Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // in_triangle(x1,y1,x2,y2,x3,y3,xx,yy) : Checks if (xx,yy) is inside the triangle
- // formed by (x1,y1), (x2,y2), and (x3,y3)
- var x1,x2,x3,y1,y2,y3,xx,yy,a0,a1,a2,a3;
- x1 = argument0;
- y1 = argument1;
- x2 = argument2;
- y2 = argument3;
- x3 = argument4;
- y3 = argument5;
- xx = argument6;
- yy = argument7;
- // Okay, so you really don't have to declare variables like I just did
- // It just saves me typing later and helps me to remember what each argument is
- a0 = abs((x2-x1)*(y3-y1)-(x3-x1)
- *(y2-y1));
- a1 = abs((x1-xx)*(y2-yy)-(x2-xx)
- *(y1-yy));
- a2 = abs((x2-xx)*(y3-yy)-(x3-xx)
- *(y2-yy));
- a3 = abs((x3-xx)*(y1-yy)-(x1-xx)
- *(y3-yy));
- return (abs(a1+a2+a3-a0) <= 1/256);
Advertisement
Add Comment
Please, Sign In to add comment