Você está na página 1de 38

Computer Science III B.

Sc CS Sem : VI Year 2019 - 2020

Subject: Graphics and Multimedia

Google Classroom : oefqdki Subject code:63A

Output Primitives
Unit 1: Ellipse Generating Algorithm
Dr.M.Manimaran,
Associate Professor,
Department Computer Science,
SKACAS
oefqdki - Graphics & Multimedia Unit I Output Primitives 1
Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Snap talk / Attendance

oefqdki - Graphics & Multimedia Unit I Output Primitives 2


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Lecture Agenda
• Circle Generating Algorithms
– Properties of Circles
– Bresenham’s Algorithm
– Mid-Point Algorithm

oefqdki - Graphics & Multimedia Unit I Output Primitives 3


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

EXPECTED OUTCOME
After studying this class, you should be able to:
• To understand the concepts of Circle Generating
Algorithms
• To understand the concepts of Properties of Circles
• To understand the concepts of Bresenham’s Algorithm
• To understand the concepts of Mid-Point Algorithm

oefqdki - Graphics & Multimedia Unit I Output Primitives 4


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Lecture Agenda
• Ellipse Generating Algorithms
– Properties of Ellipse
– Mid-Point Algorithm

oefqdki - Graphics & Multimedia Unit I Output Primitives 5


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• Ellipse equations are greatly simplified if the major
and minor axes are oriented to align with the
coordinate axes.
• In Fig. 3-22, we show an ellipse in “standard
position” with major and minor axes oriented parallel
to the x and y axes.
• Parameter rx for this example labels the semi major
axis, and parameter ry labels the semiminor axis.

oefqdki - Graphics & Multimedia Unit I Output Primitives 6


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• The equation for the ellipse shown in Fig. 3-22 can be
written in terms of the ellipse center coordinates and
parameters rx and ry as

oefqdki - Graphics & Multimedia Unit I Output Primitives 7


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• Using polar coordinates r and θ, we can also describe
the ellipse in standard position with the parametric
equations

oefqdki - Graphics & Multimedia Unit I Output Primitives 8


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• The midpoint ellipse method is
applied throughout the first quadrant
in two parts.
• Figure 3-25 shows the division of the
first quadrant according to the slope
of an ellipse with rx < ry.

oefqdki - Graphics & Multimedia Unit I Output Primitives 9


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• Regions 1 and 2 (Fig. 3-25) can be processed in
various ways.
• We can start at position (0, ry) and step clockwise
along the elliptical path in the first quadrant, shifting
from unit steps in x to unit steps in y when the slope
becomes less than −1.0.
• Alternatively, we could start at (rx, 0) and select
points in a counterclockwise order, shifting from unit
steps in y to unit steps in x when the slope becomes
greater than −1.0.

oefqdki - Graphics & Multimedia Unit I Output Primitives 10


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• We define an ellipse function from Eq. 3-37 with (xc ,
yc) = (0, 0) as

• which has the following properties:

oefqdki - Graphics & Multimedia Unit I Output Primitives 11


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• Starting at (0, ry), we take unit steps in the x direction
until we reach the boundary between region 1 and
region 2 (Fig. 3-25).
• Then we switch to unit steps in the y direction over
the remainder of the curve in the first quadrant.
• At each step we need to test the value of the slope of
the curve.

oefqdki - Graphics & Multimedia Unit I Output Primitives 12


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• The ellipse slope is calculated from Eq. 3-39 as

• At the boundary between region 1 and region 2, dy/dx


= −1.0 and

• Therefore, we move out of region 1 whenever

oefqdki - Graphics & Multimedia Unit I Output Primitives 13


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• Figure 3-26 shows the midpoint between the two
candidate pixels at sampling position xk +1 in the first
region.
• Assuming position (xk , yk) has been selected in the
previous step, we determine the next position along
the ellipse path by evaluating the decision parameter
(that is, the ellipse function 3-39) at this midpoint:

oefqdki - Graphics & Multimedia Unit I Output Primitives 14


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• If p1k < 0, the midpoint is inside the ellipse and the
pixel on scan line yk is closer to the ellipse boundary.
• Otherwise, the midposition is outside or on the ellipse
boundary, and we select the pixel on scan line yk − 1.

oefqdki - Graphics & Multimedia Unit I Output Primitives 15


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• At the next sampling position (xk+1 + 1 = xk + 2), the
decision parameter for region 1 is evaluated as

oefqdki - Graphics & Multimedia Unit I Output Primitives 16


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• Decision parameters are incremented by the
following amounts:

oefqdki - Graphics & Multimedia Unit I Output Primitives 17


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• At the initial position (0, ry), these two terms evaluate to

• As x and y are incremented, updated values are obtained by


adding 2r 2y to the current value of the increment term in Eq.
3-45 and subtracting 2r 2x from the current value of the
increment term in Eq. 3-46.
• The updated increment values are compared at each step, and
we move from region 1 to region 2 when condition 3-42 is
satisfied.

oefqdki - Graphics & Multimedia Unit I Output Primitives 18


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• In region 1, the initial value of the decision parameter
is obtained by evaluating the ellipse function at the
start position (x0, y0) = (0, ry):

oefqdki - Graphics & Multimedia Unit I Output Primitives 19


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• Over region 2, we sample at unit intervals in the
negative y direction, and the midpoint is now taken
between horizontal pixels at each step (Fig. 3-27).
• For this region, the decision parameter is evaluated as

oefqdki - Graphics & Multimedia Unit I Output Primitives 20


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• If p2k > 0, the midposition is outside the ellipse
boundary, and we select the pixel at xk.
• If p2k <= 0, the midpoint is inside or on the ellipse
boundary, and we select
• pixel position xk+1.

oefqdki - Graphics & Multimedia Unit I Output Primitives 21


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• To determine the relationship between successive
decision parameters in region 2,we evaluate the
ellipse function at the next sampling step yk+1 −1 = yk
−2:

oefqdki - Graphics & Multimedia Unit I Output Primitives 22


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Midpoint Ellipse Algorithm


• When we enter region 2, the initial position (x0, y0) is
taken as the last position selected in region 1 and the
initial decision parameter in region 2 is then

oefqdki - Graphics & Multimedia Unit I Output Primitives 23


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Algorithm

oefqdki - Graphics & Multimedia Unit I Output Primitives 24


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Algorithm

oefqdki - Graphics & Multimedia Unit I Output Primitives 25


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Algorithm

oefqdki - Graphics & Multimedia Unit I Output Primitives 26


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Example
• Given input ellipse parameters rx =8 and ry = 6, we
illustrate the steps in the midpoint ellipse algorithm
by determining raster positions along the ellipse path
in the first quadrant.
• Initial values and increments for the decision
parameter calculations are

oefqdki - Graphics & Multimedia Unit I Output Primitives 27


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Example
• For region 1, the initial point for the ellipse centered
on the origin is (x0, y0) = (0, 6), and the initial
decision parameter value is

• Successive midpoint decision parameter values and


the pixel positions along the ellipse are listed in the
following table.

oefqdki - Graphics & Multimedia Unit I Output Primitives 28


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Example

oefqdki - Graphics & Multimedia Unit I Output Primitives 29


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Example
• We now move out of region 1, since
2r 2 y x > 2r 2 x y.
• For region 2, the initial point is
(x0, y0) = (7, 3)
• and the initial decision parameter is

oefqdki - Graphics & Multimedia Unit I Output Primitives 30


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Example
• The remaining positions along the ellipse path in the
first quadrant are then calculated as

oefqdki - Graphics & Multimedia Unit I Output Primitives 31


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Example
• A plot of the calculated positions for the ellipse
within the first quadrant is shown bellow:

oefqdki - Graphics & Multimedia Unit I Output Primitives 32


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Key Points
• Mid point ellipse algorithm

oefqdki - Graphics & Multimedia Unit I Output Primitives 33


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

VIDEO URL

https://www.youtube.com/watch?v=CrfxZ7mj8Wg

oefqdki - Graphics & Multimedia Unit I Output Primitives 34


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

One mark URL

https://www.sanfoundry.com/computer-graphics-
mcqs-line-filling-algorithms/

oefqdki - Graphics & Multimedia Unit I Output Primitives 35


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

Next Lecture
Attributes of Output Primitives –
Line Attributes

oefqdki - Graphics & Multimedia Unit I Output Primitives 36


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

DISCUSSIONS

oefqdki - Graphics & Multimedia Unit I Output Primitives 37


Computer Science III B.Sc CS Sem : VI Year 2019 - 2020

oefqdki - Graphics & Multimedia Unit I Output Primitives 38

Você também pode gostar