Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function lineTest( test_ellipse:Geometry_Ellipse, test_line:Geometry_Line ):Object {
- // get the variables that define the line and ellipse
- var m:Number = test_line.getSlope();
- var c:Number = test_line.getY_Intercept();
- var a:Number = this.getRadius_X();
- var b:Number = this.getRadius_Y();
- // check for division by 0 and sqrt of negative values
- if( (b*b)+(m*a)*(m*a)-(c*c) >= 0 && (b*b)+(m*a)*(m*a) != 0 ) {
- // get intersection points
- var point_1:Geometry_Coordinate = new Geometry_Coordinate(
- ( (m*c*a)*(m*c*a) + (a*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
- ( (c*b)*(c*b) - ((m*a)*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
- 0
- );
- var point_2:Geometry_Coordinate = new Geometry_Coordinate(
- ( (m*c*a)*(m*c*a) - (a*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
- ( (c*b)*(c*b) + ((m*a)*b)*Math.sqrt((b*b)+(m*a)*(m*a)-(c*c)) ) / ( (b*b)+(m*a)*(m*a) ),
- 0
- );
- // check if points are on line segment
- // ...
- return { "result":true, "points":new Array(point_1, point_2) };
- } else {
- trace("no real values");
- }
- return { "result":false, "points":new Array() };
- }
Add Comment
Please, Sign In to add comment