Rotated Ellipses And Their Intersections With Lines b Mark C. Hendricks, Ph.D. Copright March 8, 0 Abstract: This paper addresses the mathematical equations for ellipses rotated at an angle and how to calculate the intersections between ellipses and straight lines. The formulas for calculating the intersection points are deried, and methods are gien for plotting these ellipses on a computer. In addition, techniques are shown for determining tangents to (rotated) ellipses, calculating the ellipse s bounding bo, and finding its foci.
Table of Contents Rotating Points Rotating an Ellipse Rotating an Ellipse More Than Once Constructing (Plotting) an Ellipse Constructing (Plotting) a Rotated Ellipse Finding the Foci of an Ellipse Intersection of Lines with a Rotated Ellipse Intersection with a Horizontal Line Intersection with a Vertical Line Intersection of Rotated Ellipse with Sloping Line(s) Bounding Bo for a Rotated Ellipse Determining the Tangent to an Ellipse Determining the Tangent to a Rotated Ellipse Approimating a Segment of an Ellipse with a Bezier Cure
Rotating Points First, we will rotate a point (, ) around the origin b an angle. 55 50 45 40 (,) 35 30 5 0 r r (, ) 5 +β 0 5 β 5 0 5 0 5 30 35 40 45 50 55 If the point (, ) is at angle β from the -ais, then r β r sin β After rotating the point b angle, the new coordinates are r ( β + ) r sin( β + ) Appling the formulae for the sine and ine of the sum of two angles, or ( r β ) ( r sin β ) ( r sin β ) ( r β ) r β r sin β r sin β + r β + (a) + (b) If ou rotate that point around a center of rotation at (e, f ), ou get ( e ) ( f) sin e ( f) + ( e ) sin f + (a) + (b)
Rotating an Ellipse 40 (, ) 30 (, ) 0 (e, f ) h 0-0 0 0 30 40 50 60 70 80 So if (, ) is a point on the ellipse and (e, f ) is the center of the ellipse (see aboe figure), then equations () are true for all points on the rotated ellipse. The line from (e, f ) to each point on the ellipse gets rotated b. To rotate an ellipse about a point (p) other then its center, we must rotate eer point on the ellipse around point p, including the center of the ellipse. 0 00 (e, f) 80 60 40 (e, f ) 0 (p) -40-0 0 40 60 80 00 0 40 60 80 00 This is as if we put a pin in the graph at point p and rotated the entire sheet of paper around the pin. Here we are rotating the red ellipse centered at (e, f ) around point (p) b an angle. So, for eer point (, ) on the original ellipse, the rotated point is ( p ) ( p ) sin p ( p ) + ( p ) sin p + +
and the rotated center is ( e p ) ( f p ) sin p ( f p ) + ( e p ) sin p e + f + So the directed line from the new center (e, f) to the rotated point (, ) can be epressed as ( e) ( p e + p ) ( p f + p ) ( e ) ( f) + e ( f ) ( p f + p) + ( p e + p ) ( f) + ( e ) + f which hae the same form as equations () for the ellipse rotated around its center, ecept that the new ellipse is centered at (e, f). Note: If we are rotating about the center, then (p) (e, f ) and (e, f) (e, f ) and we are back to equations (). Therefore, we can state that: When an ellipse gets rotated b angle about a point p other than its center, the center of the ellipse gets rotated about point p and the new ellipse at the new center gets rotated about the new center b angle.
Rotating an Ellipse More Than Once If an ellipse is rotated around one center of rotation and then again around a different point, what is the result? 50 + (e, f ) 3 3 00 (e, f ) (q) 50 (e, f ) (p) -50-00 -50 50 00 50 Let us assume that the ellipse has its center at (e, f ). The ellipse is first rotated about the point p b angle of, and then rotated about the point q b angle. Using the rule deried in the preceding section, we can compute the center point (e, f ) after the first rotation ( e p ) ( f p ) p ( f p ) + ( e p ) p e sin + f sin + Then compute the final center point (e 3, f 3 ) with similar equations ( e q ) ( f q ) q ( f q ) + ( e q ) q e 3 sin + f 3 sin + Finall, the ellipse is plotted centered at point (e 3, f 3 ) with a rotation of ( + ). In other words, The center point is successiel rotated (translated) around each of the two centers of rotation, and the ellipse itself is rotated about the new center b the sum of the two rotation angles. This makes plotting the rotated ellipses easier, since ou onl hae to rotate the points on the ellipse once. This process can be applied an number of times for multiple rotations around multiple points.
Constructing (Plotting) an Ellipse For a non-rotated ellipse, it is eas to show that h β (3a) sin β (3b) satisfies the equation +. Simpl substitute h ( h β ) ( sin β ) h β sin β + + β + sin β. h h Therefore, equations (3) satisf the equation for a non-rotated ellipse, and ou can simpl plot them for all alues of β from 0 to 360 degrees. For ellipses not centered at the origin, simpl add the coordinates of the center point (e, f) to the calculated (, ). Constructing (Plotting) a Rotated Ellipse if we let h β sin β and then rotate these points around the origin b angle, substituting + h β sin β (4a) sin β + h β (4b) You can plot them for all alues of β from 0 to 360 degrees. For ellipses not centered at the origin, simpl add the coordinates of the center point (e, f) to the calculated (, ). If the ellipse is rotated multiple times around multiple points, first calculate the new center point b successiel rotating it around each center of rotation (equations ), then plot the ellipse at the new center point, rotating the ellipse b the sum of the rotation angles.
Finding the Foci of an Ellipse b 0 (, ) d 0 d -40-30 -0-0 0 0 30 40 50 -c c a -0-0 If ou need to compute its foci, the conersion is eas. The formula is c a b where a is the major ais and b is the minor ais (measured from the center to the edge of the ellipse). c is the distance from the center to each focus. The foci lie along the major ais. If the ellipse is a circle (ab), then c0. You can reerse this conersion if ou know the foci and either of the aes, howeer if all ou hae is the foci, ou cannot determine a and b. If ou know the foci and an point (, ) on the ellipse, ou can calculate the sum of the distances to the two foci: ( c) d + ( + c) d + For an point on the ellipse, d + d a. Then ou can calculate b a c.
Intersection of Lines with a Rotated Ellipse Assume we hae an ellipse with horizontal radius h and ertical radius, centered at the origin (for now), and rotated counter-clockwise b angle. 0 (, ) (, ) 0-40 -30-0 -0 0 0 30 40 50-0 -0 The equation for the non-rotated (red) ellipse is + h (5) where and are the coordinates of points on the ellipse rotated back (clockwise) b angle to produce a regular ellipse, with the aes of the ellipse parallel to the and aes of the graph ( red ellipse). Using the equations for rotating a point about the origin b angle clockwise (that is, a counter-clockwise rotation of -), we get or ( ) sin( ) and ( ) + sin( ) ( ) sin( ) and ( ) sin( ) + Plugging these into equation (5) for the non-rotated ellipse, we get the equation for a rotated ellipse: ( + ) ( ) h + (6) Epanding, or + + h sin + + sin
+ + sin + h h + h sin h 0 (7) Intersection with a Horizontal Line. 0 (, ) (, ) 0-40 -30-0 -0 0 0 30 40 50-0 -0 Assume that is a constant, and re-write equation (7) as a quadratic equation for : ( + h sin ) + sin ( h ) ( sin + h ) h 0 + (8) So we get the parameters for the quadratic equation solution b ± b 4ac, where: a a + h sin (9a) b h (9b) c ( ) ( sin + h ) h (9c) Now, returning to the general case where the ellipse is not centered at the origin, assume the center of the ellipse is at (e, f). The translation is simple. Merel subtract f from the alue of, and add e to the resulting alues of. Note: For a normal or non-rotated ellipse, ( 0), the equations simplif to: a (0a) b 0 (0b) c h (0c) ( )
Intersection with a Vertical Line. (, ) 0 0-40 -30-0 -0 0 0 30 40 50 60 (, ) -0-0 Assume that is a constant, re-write equation (7) as a quadratic equation for : ( sin + h ) + ( h ) ( + h sin ) h 0 () + So we get the parameters for the quadratic equation solution for b ± b 4ac, where: a a sin + h (a) b h (b) c ( ) ( + h sin ) h (c) Now, returning to the general case where the ellipse is not centered at the origin, assume the center of the ellipse is at (e, f). The translation is simple. Merel subtract e from the alue of, and add f to the resulting alues of. Note: For a normal or non-rotated ellipse, ( 0), the equations simplif to: a h (3a) b 0 (3b) c h (3c) ( )
Intersection of Rotated Ellipse with Sloping Line(s) 0-40 -30-0 -0 0 0 30 40 0-0 -0 This is the general case where the ellipse is rotated b angle and the line has the equation m + where m, e.g., the line is not ertical. b Note: We use b instead of b to aoid confusion with the b parameter in the quadratic equation. Substituting this epression for in equation (7), Epanding, + ( m + b ) + ( m b ) sin ( m + b ) h ( m + b ) sin + h sin h 0 + + h + m + b + m sin + mb sin + b sin + h m + h mb + h b h m Collecting terms, as before, or h b + h sin h a + m + m sin + h m h m + h sin b b + mb sin + h mb h b b sin + h b h c 0
where, again, ( + m + m sin ) + h ( m + sin ) a m (4a) b b + msin + h b m (4b) ( ) ( ) ( sin + h ) h c b (4c) b ± b 4ac a Once the alue(s) for is calculated, use the equation m + b (5) to calculate the corresponding alues for the intersection points. Note: This method will not work for ertical lines (infinite slope). That would require reersing the aboe solution to sole for instead of. It is much easier, in this case, to use the special formula described aboe for intersections with ertical lines (equations ()). Note: Substituting m 0 and b (for a horizontal line) into the aboe formulas for a, b, and c (equations 4), we get the same formulas as equations (9). Again, returning to the general case where the ellipse is not centered at the origin, assume the center of the ellipse is at (e, f). The equation for the line must also be translated to coordinates with their origin at (e, f). Letting and be those coordinates, e f and the equation for the line becomes: or ( + e) + + f m b ( me + b f ) m +. So, in the new coordinate sstem, +, where b b + me f m b Therefore, we must add ( f ) me to b in equations (4). Then calculate the intersection points, and add e to each calculated -alue to return to the original coordinate sstem. Finall, calculate for each using m + b (equation (5)), where b is the original alue.
In the special case, for non-rotated ellipses ( 0) with sloping line (m 0): a + h m (a) b h bm (b) c h ( b ) (c) And for the horizontal line (m 0, b ), the equations further reduce to the same as equations (0) for non-rotated ellipses.
Bounding Bo for a Rotated Ellipse maimum 0 minimum 0-40 -30-0 -0 0 0 30 40 50-0 maimum -0 minimum We would like to know the maimum and minimum horizontal and ertical alues for a rotated ellipse, i.e., the bounding bo for the ellipse. Assume, as before, that the ellipse is centered at the origin. The top line of the bounding bo, at ma, ma be thought of as a horizontal line which intersects the ellipse at a single point. Equations (9) gie the a, b and c alues for soling the quadratic equation for on that line: a + h sin (8a) b h (9b) c ( ) ( sin + h ) h (9c) Note that a does not contain the ariable, therefore a is a constant for this condition. Recalling that ou get a single solution when b 4ac 0 (7) we can plug in the alues for a, b and c from equations (9) and sole for. ( ( h ) 4a( ( sin + h ) h ) 0 Separate out the terms: ( ( h ) 4a( sin + h ) + 4ah 0 ( 4 sin ( h ) 4a( sin + h ) + 4ah 0 4 sin 4ah ( h ) 4a( sin + h )
ah ± (8) sin ( h ) a( sin + h ) where a + h sin (9a) The positie and negatie alues gie solutions for ma and min. There is no need to find the -alues corresponding to these -alues at this time. If the ellipse is not centered at the origin, add the ertical offset of the ellipse center. Turning now to the maimum and minimum horizontal alues, go back to the intersection of a ertical line with the ellipse. The right line of the bounding bo, at ma, ma be thought of as a ertical line which intersects the ellipse at a single point. Equations () gie the a, b and c alues for soling the quadratic equation for on that line: a sin + h (a) b h (b) c ( ) ( + h sin ) h and letting b 4ac 0, as before, sole for : (c) ( ( h ) 4a( ( + h sin ) h ) 0 Separate out the terms: ( ( h ) 4a( + h sin ) + 4ah 0 ( 4 sin ( h ) 4a( + h sin ) + 4ah 0 sin ah ( h ) a( + h sin ) ah ± (9) sin ( h ) a( + h sin ) where a sin + h (a) The positie and negatie alues gie solutions for ma and min. There is no need to find the -alues corresponding to these -alues at this time. If the ellipse is not centered at the origin, add the horizontal offset of the ellipse center.
Determining the Tangent to an Ellipse Assume we hae an ellipse with horizontal radius h and ertical radius centered at (e, f). We wish to determine the tangent to the ellipse at point (, ). 40 30 d (, ) 0 (e, f) d h 0-0 0 0 30 40 50 60 70 80 If this were a circle, the tangent would be negatie inerse of the slope (d/d) of the radial line, or d/d. Howeer, because the aes are not equal, we hae to make them equal b first multipling d/d b h/. Then take the negatie inerse (-d/d)(/h). This gies the slope if the ellipse were a circle, so we now hae to multipl again b /h to re-proportion the circle back to an ellipse. Thus, the slope m of the tangent can be calculated as d e (0) h m d h f and the equation for the tangent line is ( ) m + () Note: if f, the slope is infinite and the equation is for all.
Determining the Tangent to a Rotated Ellipse Assume the ellipse in question is rotated b angle, and we wish to find the tangent line at (, ). First rotate the (, ) point back to the corresponding point on a normal or un-rotated ellipse with the equations ( e) + ( f ) sin e ( f ) ( e) sin f + (a) +. (b) (, ) 40 (, ) a a 30 (, ) 0 0 (e, f) h (, ) a a -0 0 0 30 40 50 60 70 80 90 Now we can sole for the tangent line of the un-rotated ellipse, using the technique from the preious section. Substituting and from equations () into equation (0), ( e) + ( f ) ( f ) ( e) h m (3) which is the slope of the tangent to the un-rotated ellipse in terms of the rotated points (, ). Since the ellipse was rotated, we must rotate the tangent line back to the angle of the rotated ellipse. In order to rotate the line, we need more than one point on the line. First, we will work with the case where m is not infinite. We will pick an arbitrar point ( a, a ) on the tangent line. Let a + z where z > 0, m (from equation ) then a ( a ) + m ( + z ) + m z + Now let us rotate ( a, a ) back to the rotated ellipse. Call this rotated point ( a, a )
( a e) ( a f ) sin e ( + z e) ( mz + f ) sin + e ( a f ) + ( a e) sin f ( m z + f ) + ( + z e) sin + f a + (4a) a + (4b) Now the slope m of the rotated tangent line at (, ) can be epressed as d /d. ( e) ( ) ( f ) sin( ) e ( f ) ( ) + ( e) sin( ) f + (5a) +. (5b) Now, using the epressions for ( a, a ) in equations (4) and the epressions for (, ) in equations (5), we can calculate d d m a ( + z e ( e) ) ( m z + f ( f )) + e e z mz z( m ) ( m z + f ( f )) + ( + z e ( e) ) + f f a m z + z z m + ( ) d m +. (6) d m Note: If m 0, the rotated slope is infinite. In the case where the un-rotated slope m is infinite, we can still calculate the rotated slope. In this case, and let a (7a) a + z, where z > 0. (7b) Repeating the aboe calculations for the new ( a, a ), ( a e) ( a f ) sin e ( e) ( + z f ) sin + e ( a f ) + ( a e) sin f ( + z f ) + ( e) sin + f a + (8a) a + (8b)
Now, using the epressions for ( a, a ) in equations (8) and the epressions for (, ) in equations (5), we can calculate d d a ( e ( e) ) ( + z f ( f )) + e e z a ( + z f ( f )) + ( e ( e) ) + f f z d m, (9) d which, incidentall, is the limit of equation (6) as m. Note In equation (9), m is infinite if sin 0, that is, rotating a line of infinite slope b a multiple of 80 degrees (sin 0) results in another infinite slope. Summar: The slope m of the tangent at a point (, ) on an ellipse rotated b angle is determined b first calculating the tangent m on the un-rotated ellipse using equation (3). Then, if m is infinite, calculate m using equation (9), otherwise use equation (6). In either case, the equation for the tangent line is ( ) m + (30)
Approimating a Segment of an Ellipse with a Bezier Cure If ou are drawing an elliptical arc, chord, or pie segment, it can be useful (and often faster) to draw the segment as a cubic Bezier cure. This works for small segments, not more than 90 degrees and optimall, less than 45 degrees. The smaller the segment, the greater the accurac. The larger ou magnif a segment of an ellipse, the straighter the cure appears. It is assumed that ou know the horizontal and ertical radii of the ellipse (h and ), the center of the ellipse (e, f) and the rotation angle, if the ellipse is rotated. If the ellipse is rotated, we will first rotate it back to a normal un-rotated ellipse. If ou are starting with points ( start, start ) and ( end, end ) on the rotated ellipse, rotate each of them back using the formula ( e) ( ) + ( f ) sin( ) e ( f ) ( ) ( e) sin( ) f + and +. Net determine the start and end angles. To do that, we first define a function arctan (, ) arctan, if > 0, 0 π arctan, if < 0, 0 π + arctan, if < 0, < 0, where the angle is in radians. π arctan, if > 0, < 0 π, if 0, 0 3π, if 0, < 0 This will result in a single alue between 0 and π (0 and 360 degrees). These start and end angles, β start and β end, are the angles used in the formulae e h β f sin β defining the ellipse. The are not actual angles unless the ellipse is a circle. To find the angles, use the arctan formula, aboe, as follows: β arctan e, h f
To determine the Bezier control points, assume the will lie on lines tangent to the ellipse at the start and end points. Determine the parameters for the tangent lines at both ends of the segment, using the technique described in the preious section. Now calculate angles of approimatel /3 and /3 of the angle (β end -β start ) and spanned b the segment. Empiricall, the alues.3343333 and.67636667 work quite well. Adjust the angles if the arc crosses 360 degrees. Now imagine lines from the center of the ellipse at those angles and find their intersection with the tangent lines. (Take into account the possibilit that the tangent or radial lines ma hae infinite slope.) These intersections are our Bezier control points. 40 35 30 5 ( end, end ) Control Point Control Point ( start, start ) 0 (e, f) 30 35 40 45 50 55 60 65 70 75 80 h Now, if the ellipse is rotated, rotate the Bezier control points b the same angle, using the formulae ( e) ( f ) sin e ( f ) + ( e) sin f + +. Now draw the Bezier cure from the (rotated) start point to the (rotated) end point using the calculated (rotated) control points. The cure is shown in blue on the figure aboe.