• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Checking if a point is within a triangle

Status
Not open for further replies.
Level 10
Joined
Jun 6, 2007
Messages
392
I use these 3 conditions to check if TempPoint2 is within a triangle. The center of the triangle is TempPoint and length of a median is 600.

  • ((Y of TempPoint2) - ((Y of TempPoint) + 400.00)) Less than or equal to (1.73 x ((X of TempPoint2) - (X of TempPoint)))
  • ((Y of TempPoint2) - ((Y of TempPoint) + 400.00)) Less than or equal to (-1.73 x ((X of TempPoint2) - (X of TempPoint)))
  • ((Y of TempPoint2) - 200.00) Greater than or equal to (Y of TempPoint)
Basically those conditions come from the equation of a line (y-y0 = k(x-x0)), but for some reason, none of the points withing the triangle seems to fulfill those conditions. Could someone point me my mistake?
 
Level 3
Joined
Jan 31, 2012
Messages
42
JASS:
function IsPointInTriangle takes real x1, real y1, real x2, real y2, real x3, real y3, real x, real y returns boolean
    local boolean b = (x2 - x) * (y3 - y2) - (x3 - x2) * (y2 - y) >= .0
    return ((x1 - x) * (y2 - y1) - (x2 - x1) * (y1 - y) >= .0) == b and b == ((x3 - x) * (y1 - y3) - (x1 - x3) * (y3 - y) >= .0)
endfunction
 
Level 10
Joined
Jun 6, 2007
Messages
392
Thank you both, I will surely get the spell to work with those, +rep. Ayway, I would still like to know why my conditions don't seem to work. The triangle is symmetric, so the angle factor for side lines is tan (60 deg) = 1.73 and tan (-60 deg) = -1.73, and for the bottom line it's 0.
 
Status
Not open for further replies.
Top