Ember

collision_triangle

Sep 6th, 2012
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // in_triangle(x1,y1,x2,y2,x3,y3,xx,yy) : Checks if (xx,yy) is inside the triangle
  2. // formed by (x1,y1), (x2,y2), and (x3,y3)
  3. var x1,x2,x3,y1,y2,y3,xx,yy,a0,a1,a2,a3;
  4. x1 = argument0;  
  5. y1 = argument1;
  6. x2 = argument2;
  7. y2 = argument3;
  8. x3 = argument4;
  9. y3 = argument5;
  10. xx = argument6;
  11. yy = argument7;
  12. // Okay, so you really don't have to declare variables like I just did
  13. // It just saves me typing later and helps me to remember what each argument is
  14. a0 = abs((x2-x1)*(y3-y1)-(x3-x1)
  15. *(y2-y1));
  16. a1 = abs((x1-xx)*(y2-yy)-(x2-xx)
  17. *(y1-yy));
  18. a2 = abs((x2-xx)*(y3-yy)-(x3-xx)
  19. *(y2-yy));
  20. a3 = abs((x3-xx)*(y1-yy)-(x1-xx)
  21. *(y3-yy));
  22. return (abs(a1+a2+a3-a0) <= 1/256);
Advertisement
Add Comment
Please, Sign In to add comment