- Joined
- May 2, 2015
- Messages
- 109
I've read this Barycentric coordinate system - Wikipedia and I found the way to determine if a point in a triangle. Here is it
Please tell me if I did something wroing because I'm about to create a new system (I think) and it uses this snippet.
JASS:
library IsPointInTriangle
function IsPointInTriangle takes real x, real y, real x1, real y1, real x2, real y2, real x3, real y3 returns boolean
//denominator
local real d = ((y2 - y3)*(x1 - x3) + (x3 - x2)*(y1 - y3))
//express new p coordinates as a linear combination of a, b, c
local real a = ((y2 - y3)*(x - x3) + (x3 - x2)*(y - y3)) / d
local real b = ((y3 - y1)*(x - x3) + (x1 - x3)*(y - y3)) / d
local real c = 1 - a - b
return 0 <= a and a <= 1 and 0 <= b and b <= 1 and 0 <= c and c <= 1
endfunction
endlibrary
Please tell me if I did something wroing because I'm about to create a new system (I think) and it uses this snippet.