Guest User

Untitled

a guest
Nov 23rd, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. public function lineTest( test_ellipse:Geometry_Ellipse, test_line:Geometry_Line ):Object {
  2. // get the variables that define the line and ellipse
  3. var m:Number = test_line.getSlope();
  4. var c:Number = test_line.getY_Intercept();
  5. var a:Number = this.getRadius_X();
  6. var b:Number = this.getRadius_Y();
  7.  
  8. // check for division by 0 and sqrt of negative values
  9. if( (b*b)+(m*a)*(m*a)-(c*c) >= 0 && (b*b)+(m*a)*(m*a) != 0 ) {
  10. // get intersection points
  11. var point_1:Geometry_Coordinate = new Geometry_Coordinate(
  12. ( (m*c*a)*(m*c*a) + (a*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
  13. ( (c*b)*(c*b) - ((m*a)*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
  14. 0
  15. );
  16. var point_2:Geometry_Coordinate = new Geometry_Coordinate(
  17. ( (m*c*a)*(m*c*a) - (a*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
  18. ( (c*b)*(c*b) + ((m*a)*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
  19. 0
  20. );
  21.  
  22. // check if points are on line segment
  23. // ...
  24.  
  25. return { "result":true, "points":new Array(point_1, point_2) };
  26. } else {
  27. trace("no real values");
  28. }
  29.  
  30. return { "result":false, "points":new Array() };
  31. }
Add Comment
Please, Sign In to add comment