# [JASS]Better way to do IsPointInTriangleInInscribledTriangle??

Status
Not open for further replies.

#### Nestharus

Level 31
Better way to do IsPointInInscribledTriangleInTriangle??

This little snippet will see if a point is in a right triangle that is inscribed into a right triangle given a distance of x.

This was used to create attack paths for motion, which adds more realism to combat. I'll probably eventually change all of these triangles into arcs >.>.

ax, ay, bx, by, cx, cy are the triangles edges. The triangle is always a right triangle (or should be lest I kill u, fuahaha)

px and py is the point to test for

percent (0<=percent<=1) is the distance of one of the legs for the inscribed triangle (might be x, might be y, who the hell knows, lol).

The triangle can be rotated any which way, which is what adds to the confusion : P.
JASS:
``````library IsPointInInscribedTriangle uses IsPointInTriangle
function IsPointInInscribedTriangle takes real ax, real ay, real bx, real by, real cx, real cy, real px, real py, real percent returns boolean
local real abx = ax-bx
local real aby = ay-by
local real ab = SquareRoot(abx*abx+aby*aby)

local real bcx = bx-cx
local real bcy = by-cy
local real bc = SquareRoot(bcx*bcx+bcy*bcy)

local real acx = ax-cx
local real acy = ay-cy
local real ac = SquareRoot(acx*acx+acy*acy)

local real hyp
local real short
local real long

local real angle
local real y

local real rootX
local real rootY

if (ab > bc and ab > ac) then
set hyp = ab
if (bc > ac) then
set long = bc
set short = ac
else
set long = ac
set short = bc
endif

set rootX = cx
set rootY = cy
elseif (bc > ac) then
set hyp = bc
if (ab > ac) then
set long = ab
set short = ac
else
set long = ac
set short = ab
endif

set rootX = ax
set rootY = ay
else
set hyp = ac
if (ab > bc) then
set long = ab
set short = bc
else
set long = bc
set short = ac
endif

set rootX = bx
set rootY = by
endif

set percent = percent*short

set angle = bj_PI/2-Atan2(short, long)
set y = Sin(bj_PI/2-angle)/(Sin(angle)/percent)

return IsPointInTriangle(rootX, rootY, rootX+percent, rootY, rootX, rootY+y, px, py)
endfunction
endlibrary``````

So I'm wondering if there is a more efficient way to do the above? I know I don't need the hypotenuse and crap (will remove those extra things), but I'm wondering about different techniques all together.

The motion is created by slowly increasing percent until it's 1.

Status
Not open for further replies.

Replies
15
Views
2K
Replies
1
Views
406
Replies
0
Views
1K
Replies
7
Views
799
Replies
10
Views
632