Guest User

Untitled

a guest
Jul 18th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. public function calculateIntersection(line: Line) : Point
  2. {
  3. const x11: Number = this.point1.x;
  4. const y11: Number = this.point1.y;
  5. const x12: Number = this.point2.x;
  6. const y12: Number = this.point2.y;
  7.  
  8. const x21: Number = line.point1.x;
  9. const y21: Number = line.point1.y;
  10. const x22: Number = line.point2.x;
  11. const y22: Number = line.point2.y;
  12.  
  13. if (this.isSegment && line.isSegment)
  14. {
  15. if (Math.min(x11, x12) > Math.max(x21, x22) || Math.max(x11, x12) < Math.min(x21, x22)) return null;
  16. if (Math.min(y11, y12) > Math.max(y21, y22) || Math.max(y11, y12) < Math.min(y21, y22)) return null;
  17. }
  18.  
  19. const fseX: Number = x12 - x11;
  20. const fseY: Number = y12 - y11;
  21.  
  22. const sseX: Number = x22 - x21;
  23. const sseY: Number = y22 - y21;
  24.  
  25. const sfsX: Number = x11 - x21;
  26. const sfsY: Number = y11 - y21;
  27.  
  28. const denominator: Number = fseX * sseY - fseY * sseX;
  29. const a: Number = sseX * sfsY - sfsX * sseY;
  30.  
  31. if (denominator == 0) return null;
  32.  
  33. var u: Number = a / denominator;
  34.  
  35. if (this.isSegment && (u < 0.0 || u > 1.0)) return null;
  36.  
  37. const b: Number = fseX * sfsY - sfsX * fseY;
  38. var u2: Number = b / denominator;
  39.  
  40. if (line.isSegment && (u2 < 0.0 || u2 > 1.0)) return null;
  41.  
  42. const rx: Number = x11 + fseX * u;
  43. const ry: Number = y11 + fseY * u;
  44.  
  45. return new Point(MathUtils.round(rx, 10), MathUtils.round(ry, 10));
  46. }
Add Comment
Please, Sign In to add comment