Page 87 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 87

Unit 5: Implementing Ellipse Algorithm



                     area 2  = ellipse_line_overlap (PHI, A, B, H, K, X 1 , Y 1 , X 2 , Y 2 , &rtn);  Notes
                     sprintf (msg, “Fig  5.3 reverse: area = %15.8f, return_value = %d\n”,
                     area 2 , rtn);
                     printf (msg);
                     sprintf (msg, “sum of ellipse segments = %15.8f\n”, area 1  + area 2 );
                     printf (msg);
                     sprintf (msg, “total ellipse area by pi*a*b = %15.8f\n”, pi*A*B);
                     printf (msg);
                     return rtn;
                     }
            Determining Intersection Points

            To find intersection points, the two ellipse equations are solved simultaneously, using the implicit
            polynomial forms. The first ellipse equation, in its translated + rotated position, is written using
            the appropriate semi-axis lengths:
                          x 2  y 2
                            +    = 1                                                (11)
                         A 1 2  B 2 1
            In  a  general  form  of  this  problem,  the  translation  +  rotation  that  positions  the  first  ellipse
            centered at the origin and oriented with the coordinate axes will typically leave the second ellipse
            displaced and rotated, as in Figure 5.4. The implicit polynomial form for a more general ellipse
            that is rotated and/or translated away from the origin is written in the conventional way as:
                                        2
                      2
                AA · x  + BB · x · y + CC · y  + DD · x + EE ·  y + FF = 0          (12)
            Any points of intersection for the two ellipses will satisfy Equation (11) and Equation (12)
            simultaneously. An intermediate goal is to find the implicit polynomial coefficients in Equation
            (12) that describes the second ellipse after the translation + rotation that positions the first ellipse
            centred at the origin and oriented with the coordinate axes. The second ellipse centre (h 2 , k 2 ) is
            translated through an amount (–h 1 , –k 1 ), then centre-point is rotated through –φ 1  to give a new
                            TR
            centre point (h 2 , k 2 ):
                        TR
                             h   = cos(–φ 1 ) · (h 2  – h 1 ) – sin(–φ 1 ) · (k 2  – k 1 )    (13a)
                              2 TR
                             k 2 TR   = sin(–φ 1 ) · (h 2  – h 1 ) + cos(–φ 1 ) · (k 2  – k 1 )  (13b)
            The coordinates for any point (x TR , y TR ) from Equation (12) on the second  ellipse in its new
            translated + rotated position can be found from the following parametric equations, based on an
            ellipse with semi-axis lengths A 2  and B 2  that is centred at the origin, then rotated and translated
            to the desired position:

                  x  =  A ◊ cos( t ◊)cos(j  - j  ) - B ◊ sin( t ◊)sin(j  - j  ) +  h 2 ¸
                                                              TR Ô
                  TR   2           2  1    2          2   1     ˝  0 ≤ t ≤ 2       (14)
                                               t ◊
                  y TR  =  A ◊ coos() sin(t ◊  j 2  - j 1 ) -  B ◊ sin() cos(j 2  - j 1 ) +  k 2 TR ˛ Ô
                                          2
                       2
            To find the implicit polynomial coefficients from the parametric form, transform the locus of
            points (x TR , y TR ) so that they lie on the ellipse (A 2 , B 2 , 0, 0, 0), which is accomplished by first
            translating through (–(h 1  – h 2 ),(k 1  – k 2 )) and then rotating the point through the angle –(φ 1  – φ 2 ):
                        x =  cos(φ 2  – φ 1 )  (x TR  – (h 1  – h 2 )) – sin(φ 2  – φ 1 )  (y TR  – (k 1  – k 2 ))  (15a)
                        y =  sin(φ 2  – φ 1 )  (x TR  – (h 1  – h 2 )) – cos(φ 2  – φ 1 )  (y TR  – (k 1  – k 2 ))  (15b)
            The locus of points (x, y) should  satisfy the standard  ellipse equation with the appropriate
            semi-axis lengths, A 2  and B 2 . Finally, the implicit polynomial coefficients for the second ellipse



                                             LOVELY PROFESSIONAL UNIVERSITY                                    81
   82   83   84   85   86   87   88   89   90   91   92