Page 81 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 81

Unit 5: Implementing Ellipse Algorithm



                     int main (int argc, char ** argv)                                            Notes
                     {
                     double A, B;double X 1 , Y 1 ;double X 2 , Y 2 ;
                     double area1, area2;int rtn;char msg[1024];
                     printf (“Calling ellipse_segment.c\n”); //-- case shown in Fig. 1A = 4.;
                     B = 2;
                     X 1  = 4./sqrt (5.);
                     Y 1  = 4./sqrt (5.);
                     X 2  = –3;
                     Y 2  = –sqrt (7.)/2;
                     area1 = ellipse_segment (A, B, X 1 , Y 1 , X 2 , Y 2 , &rtn);
                     sprintf (msg, “Figure 5.1: segment area = %15.8f, return_value = %d\n”,
                     area1, rtn);
                     printf (msg);
                     //-- case shown in Figure 5.2
                     A = 4;
                     B = 2;
                     X 1  = –3;
                     Y 1  = –sqrt (7.)/2;
                     X 2  = 4./sqrt (5.);
                     Y 2  = 4./sqrt (5.);
                     area2 = ellipse_segment (A, B, X 1 , Y 1 , X 2 , Y 2 , &rtn);
                     sprintf (msg, “Fig 5.2: segment area = %15.8f, return_value = %d\n”,
                     area2, rtn);
                     printf (msg);
                     sprintf (msg, “sum of ellipse segments = %15.8f\n”, area1 + area2);
                     printf (msg);
                     sprintf (msg, “total ellipse area by pi*a*b = %15.8f\n”, pi*A*B);
                     printf (msg);
                     return rtn;
                     }

            5.4 Extending the Core Segment Algorithm to More General Cases

            Core segment algorithm is given below:

            5.4.1 Segment Area for a (Directional) Line through a General Ellipse
            The ELLIPSE_SEGMENT algorithm is based on an ellipse that is centred at the origin with its axes
            aligned to the coordinate axes. The core algorithm can be extended to rotated and/or translated
            ellipse forms. Consider an ellipse described by Equation (1), with semi-major axis lengths of A
            and B that is centred at the origin with its axes aligned with the coordinate axes. Suppose that
            the ellipse is rotated counter-clockwise through an angle φ, and that the ellipse is then translated
            so that its centre is at the point (h, k). The rotated + translated ellipse could be defined by the set
            of parameters (A, B, h, k, φ), with the understanding that the rotation through φ is performed
            before the translation through (h, k). Figure 3 illustrates this idea, showing the ellipse of Figure
            1 rotated counter-clockwise through an angle φ = +3/8, then translated by (h, k) = (–6, +3).

                                             LOVELY PROFESSIONAL UNIVERSITY                                    75
   76   77   78   79   80   81   82   83   84   85   86