Page 80 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 80
Lab on Computer Graphics
Notes Pseudo-code and an implementation in c-code for ELLIPSE_SEGMENT are given in the along
with examples.
Algorithm 1: ELLIPSE_SEGMENT: Calculate the segment area of a centred and coordinate-
aligned ellipse given two points on the ellipse.
Inputs: Ellipse parameters semi-axis lengths A, B; coordinates of two points (x 1 , y 1 ) and (x 2 , y 2 )
where the secant intersects the ellipse.
Output: The area between the secant and the ellipse travelling counter-clockwise from (x 1 , y 1 )
to (x 2 , y 2 ), and a diagnostic message indicating either normal termination or an error condition
do if (A ≤ 0 or B ≤ 0)
then return (–1, ERROR_ELLIPSE_PARAMETERS): DATA CHECK
do if (|X12/A2 + Y12/B2 – 1| > ε or |X12/A2 + Y12/B2 – 1| > ε)
then return (–1, ERROR_POINTS_NOT_ON_ELLIPSE) :DATA CHECK
do if (|X1|/A > ε)
do if |X1| – A > ε
then return (–1, ERROR_INVERSE_TRIG)
else do if X1 < 0
then X1 ← – A
else X1 ← A
do if (|X2|/A > ε)
do if |X2| – A > ε
then return (–1, ERROR_INVERSE_TRIG)
else do if X2 < 0
then X2 ← –A
else X2 ← A
do if (Y1 < 0)
then θ1 ← 2π – acos (X1/A)
else θ1 ← acos (X1/A)
do if (Y2 < 0)
then θ2 ← 2 – acos (X2/A)
else θ2 ← acos (X2/A)
do if (θ1 > θ2)
then θ1 ←θ1 – 2
do if ((θ2 – θ1) > )
then trsgn ← +1.0
else trsgn ← +1.0
call_es.c
#include <stdio.h>
#include <math.h>
#include “program_constants.h”
double ellipse_segment (double A, double B, double X 1 , double Y 1 ,
double X 2 , double Y 2 , int *MessageCode);
74 LOVELY PROFESSIONAL UNIVERSITY