CoderJohn

Lua Circle Intersection

Mar 16th, 2013
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.59 KB | None | 0 0
  1. P0 = {
  2. X =     5,
  3. Y = -15,
  4. R = 5
  5. }
  6.  
  7. P1 = {
  8. X =     6,
  9. Y = -13,
  10. R = 5
  11. }
  12.  
  13. Distance = math.sqrt((P1.X-P0.X)^2+(P1.Y-P0.Y)^2);
  14.  
  15. A = (P0.R^2 - P1.R^2 + Distance^2)/(2*Distance);
  16. B = Distance-A;
  17. H = math.sqrt(P0.R^2-A^2);
  18.  
  19. dirToP1X = (P1.X-P0.X)/Distance;
  20. dirToP1Y = (P1.Y-P0.Y)/Distance;
  21.  
  22. P2 = {
  23. X = P0.X+(A*dirToP1X); 
  24. Y = P0.Y+(A*dirToP1Y); 
  25. }
  26.  
  27. dirToP3X = (P1.Y-P0.Y)/Distance;
  28. dirToP3Y = -1*(P1.X-P0.X)/Distance;
  29.  
  30. P3 = {
  31.     X = P2.X+H*dirToP3X;
  32.     Y = P2.Y+H*dirToP3Y;
  33. }
  34. P4 = {
  35.     X = P2.X-H*dirToP3X;
  36.     Y = P2.Y-H*dirToP3Y;
  37. }
  38.  
  39. print(P4.X.." , "..P4.Y);
  40. print(P3.X.." , "..P3.Y);
Advertisement
Add Comment
Please, Sign In to add comment