Page 85 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 85

Unit 5: Implementing Ellipse Algorithm



            then return (–1, ERROR_ELLIPSE_PARAMETERS) :DATA CHECK                                Notes
                     do if (|φ| > 2
            then φ← (φ modulo 2) :BRING φ INTO –2≤φ < 2 (?)
                     do if (|X 1 |/A > 2)
                     then X1 ← –A
                     X10 ← cos(φ)*(X 1  – H) + sin(φ)*(Y 1  – K)
                     Y 10  ← –sin(φ)*(X 1  – H) + cos(φ)*(Y 1  – K)
                     X 20  ← cos(φ)*(X 2  – H) + sin(φ)*(Y 2  – K)
                     Y 20  ← –sin(φ)*(X 2  – H) + cos(φ)*(Y 2  – K)
            do if (|X 20  – X 10 | > ε) :LINE IS NOT VERTICAL
            then m ← (Y 20  – Y 10 )/(X 20  – X 10 ) :STORE QUADRATIC COEFFICIENTS

                     a ← (B 2  + (A*m)2)/A 2
                     b ← (2.0*(Y 10 *m – m 2 *X 10 ))
                     c ← (Y 102  – 2.0*m*Y 10 *X 10  + (m*X 10 )2 – B 2 )

            else if (|Y 20  – Y 10 | > ε) :LINE IS NOT HORIZONTAL
            then m ← (X 20  – X 10 )/(Y 20  – Y 10 ) :STORE QUADRATIC COEFFS

                     a ← (A 2  + (B*m)2)/B 2
                     b ← (2.0*(X 10 *m – m 2 *Y 10 ))
                     c ← (X 102  – 2.0*m*Y 10 *X 10  + (m*Y 10 )2 – A 2 )
            else return (–1, ERROR_LINE_POINTS) :LINE POINTS TOO CLOSE
            discrim ← b2 – 4.0*a*c
            do if (discrim < 0.0):LINE DOES NOT CROSS ELLIPSE
            then return (0, NO_INTERSECT)

            else if (discrim > 0.0): TWO INTERSECTION POINTS
            then root1 ← (–b – sqrt (discrim))/(2.0*a)
            root2 ← (–b + sqrt (discrim))/ (2.0*a)
            else return (0, TANGENT) :LINE TANGENT TO ELLIPSE
            do if (|X 20  – X 10 | > ε) :ROOTS ARE X-VALUES
            then do if (X 10  < X 20 ) :ORDER PTS SAME AS LINE DIRECTION
            then     x 1  ← root 1
                     x 2  ← root 2
                     else x 1  ← root 2

                     x 2  ← root 1
            else do if (Y 10  < Y 20 ) :ROOTS ARE Y-VALUES
            then y 1  ← root 1  :ORDER PTS SAME AS LINE DIRECTION

                     y 2  ← root 2
                     else y 1  ← root 2
                     y 2  ← root 1
            (Area,Code) ← ELLIPSE_SEGMENT (A,B,x 1 ,y 1 ,x 2 ,y 2 )



                                             LOVELY PROFESSIONAL UNIVERSITY                                    79
   80   81   82   83   84   85   86   87   88   89   90