Page 96 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 96
Lab on Computer Graphics
Notes should integrate in the default order, counter clockwise from (x 1 , y 1 ) to (x 2 , y 2 ). Otherwise, the
order of the points should be reversed before calling the segment algorithm. The area returned
by the segment algorithm is the area contributed by the first ellipse to the partial overlap.
The desired segment area from the second ellipse is found in a way similar to the first ellipse
segment. In the general case the second ellipse is in a displaced and rotated location. The approach
presented here translates and rotates the second ellipse to the origin so that the segment algorithm
can be used. It suffices to translate then rotate the two intersection points (x 1 , y 1 ) and (x 2 , y 2 ) by
amounts that put the second ellipse centred at the origin and oriented with the coordinate axes:
◊
+
◊
x 1 TR = (x - h 2 TR ) cos(j 1 - j 2 )(y - k 2 TR )sin(j 2 - j 1 )
1
1
+
◊
◊
y 1 = (x - h 2 TR ) sin(j 1 - j 2 )(y - k 2 TR )cos(j 1 - j 2 )
1
1
TR
+
◊
◊
x 2 TR = (x - h 2 TR ) cos(j 1 - j 2 )(y - k 2 TR )sin(j 2 - j 1 )
2
2
◊
◊
+
y 2 = (x - h 2 TR ) sin(j 1 - j 2 )(y - k 2 TR )cos(j 1 - j 2 )
2
2
TR
The new points (x 1 , y 1 ) and (x 2 , y 2 ) lie on the second ellipse after it has been translated
TR
TR
TR
TR
and rotated a second time to put its centre at the origin and its axes oriented with the coordinate
axes. The new points can be used as inputs to the segment algorithm to determine the overlap
area contributed by the second ellipse. The order of the points must be determined so that the
segment algorithm returns the appropriate area. A check is made to determine whether this
order will return the desired segment area. First, the parametric angles θ 1 and θ 2 corresponding to
points (x 1 , y 1 ) and (x 2 , y 2 ) on the second ellipse are determined, by the rules. Then, a point
TR
TR
TR
TR
TR
TR
(x mid , y mid ) on the second ellipse between (x 1 , y 1 ) and (x 2 , y 2 ) is found, as in Equation (23).
TR
TR
The point (x mid , y mid ) is on the (twice translated + rotated) second ellipse between (x 1 , y 1 ) and
TR
TR
TR
TR
TR
TR
(x 2TR , y 2TR ) when travelling counter- clockwise from (x 1 , y 1 ) and (x2 , y 2 ). To determine the
desired segment of the second ellipse, the new point (x mid , y mid ) must be rotated then translated
back to a corresponding position on the once-translated + rotated second ellipse;
x mid RT = x mid ◊ cos(j 2 - j 1 ) + y mid ◊ sin(j 1 - j 2 ) + h 2 TR
y mid RT = x mid ◊ sin(j 2 - j 1 ) + y mid ◊ cos(j 1 - j 2 ) + k 2 TR
If (x mid , y mid ) is inside the first ellipse, then the desired segment of the second ellipse contains
RT
RT
the point (x mid , y mid ), and the segment algorithm should integrate in the default order. Otherwise,
the order of the points should be reversed before calling the segment algorithm, causing it to
TR
integrate counter clockwise from (x 2 , y 2 ) to (x 1 , y 1 ). The area returned by the segment
TR
TR
TR
algorithm is the area contributed by the second ellipse to the partial overlap. The sum of the
segment areas from the two ellipses is then equal to the ellipse overlap area. The function
TWOINTPTS calculates the overlap area for partial overlap with two intersection points (Case
2-3); pseudo-code is provided.
There are two possible sub-cases for three intersection points, shown in Figure 5.8. One of the
three points must be a tangent point, and the ellipses must cross at the other two points. The
cases are distinct only in the sense that the tangent point occurs with ellipse 2 on the interior side
of ellipse 1 (Case 3-1), or with ellipse 2 on the exterior side of ellipse 1 (Case 3-2). The overlap
area calculation is performed in the same manner for both cases, by calling TWOINTPTS with
the two cross-point intersections. ISTANPT can be used to determine which point is a tangent;
the remaining two intersection points are then passed to TWOINTPTS. This logic is implemented
in the function THREEINTPTS, with pseudo-code given.
There is only one possible case for four intersection points, shown in Figure 5.8. The two ellipse
curves must cross at all four of the intersection points, resulting in a partial overlap. The overlap
90 LOVELY PROFESSIONAL UNIVERSITY