KEMBAR78
Computer Graphics - Output Primitive | PDF
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
OutputPrimitive
1
St. Francis Institute of Technology
Department of Computer Engineering
1
Subject Incharge
Rupesh Mishra
Asst. Professor 
Room No. 401
rupeshmishra@sfit.ac.in
31 July 2020
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
2
Module II
Lecture 4
Computer Graphics: Output Primitive
St. Francis Institute of Technology
Department of Computer Engineering
1
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
OutputPrimitive
• Graphics programming packages
• Describe a scene in terms of basic geometric structures (Output Primitives)
• Group output primitives into more complex structures.
• Each output primitive is specified with
• Input coordinate data
• Information about object to be displayed.
• Point, Line, Circle, Conic Section, Spline curves, polygon and Character String.
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Point
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Point
• Point plotting is accomplished by converting a single coordinate position into
appropriate operations for the output device in use.
• Setting value in frame buffer
• Moving beam of electron at the selected location (CRT)
• Point plotting instruction in display list (Random Scan)
• Converted to deflection voltages to position the electron beam.
• Frame buffer is loaded with the color codes (RGB System)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Line
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Line
• Collection of points over a path
• Plotting discrete points between the two endpoints.
• Calculated from the equation of the line
• Frame buffer loaded with intensity value at the corresponding pixel coordinates.
• Video Controller plots the screen pixels
• Approximation of actual points
• (10.4, 20.5) converted to (10, 21)
• Stair-step appearance in low resolution
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
LineDrawing
• The Cartesian slope-intercept equation
for a straight line
•
•
• intercept
• Given end point of line
•
•
y = m ⋅ x + c
m : Slope
c : y
(x1, y1), (x2, y2)
m =
(y2 − y1)
(x2 − x1)
c = y1 − m ⋅ x1
Line Segment
Y intercept
x intercept
(x1, y1)
(x2, y2)
x axis
Y axis
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• For any given interval along a line, we
can compute the corresponding y interval
•
• Similarly
•
x Δx
Δy
Δy = m . Δx
Δx =
Δy
m
Δy
Δx
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Δy
Δx Δx
Δy
Δx
Δy
For angle more than 45∘
Δy
Δx
> 1
For angle less than 45∘
Δy
Δx
< 1
For angle equal 45∘
Δy
Δx
= 1
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
DigitalDifferentialAnalyser
• Scan-conversion line algorithm
• Calculating either or
• Sample the line at unit intervals in one coordinate
• Determine corresponding integer values nearest the line path for the other
coordinate.
• DDA algorithm works even if points are reversed
Δx Δy
DDA
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
(1) Compute
(2)If then
else
Δx = x2 − x1
Δy = y2 − y1
abs(Δx) > abs(Δy)
steps = abs(Δx)
steps = abs(Δy)
(3)
(4)
(5)repeat for all steps
xinc =
Δx
steps
yinc =
Δy
steps
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
LimitationofDDA
• Time Consuming
• Floating Point Numbers
• Roundoff Error
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Bresenham's Line Algorithm
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Accurate and efficient raster line-generating
algorithm
• Using only incremental integer calculations
• Sampling at unit intervals
• Decide possible pixel positions closer to
the line path at each sample step.
• Weather to plot pixel at position
in the next step
• Testing the sign of an integer parameter,
whose value is proportional to the
difference between the separations of the
two pixel positions from the actual line
path.
x
(11,11)or(11,12)
10
11
12
13
14
10 11 12 13
.
. .
.
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
du
dl
Decisión parameter
y = mx + c
y = m(xk + 1) + c
dl = y − yk = [m(xk + 1) + c] − yk
du = yk+1 − y = yk+1 − [m(xk + 1) + c]
if(dl − du < 0) − > yk
if(dl − du > 0) − > yk+1
xk
yk+1
yk
xk+1
y
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
dl − du = [[m(xk + 1) + c] − yk] − [yk+1 − [m(xk + 1) + c]]
dl − du = m(xk + 1) + c − yk − yk+1 + m(xk + 1) − c
dl − du = 2m(xk + 1) − 2yk + 2c − 1
m =
Δy
Δx
dl − du =
2Δy
Δx
(xk + 1) − 2yk + 2c − 1
dl − du = Δx[
2Δy
Δx
(xk + 1) − 2yk + 2c − 1]
Δx(dl − du) = 2Δy(xk + 1) − 2Δxyk + 2Δxc − Δx
pk = Δx(dl − du) = 2Δyxk + 2Δy − 2Δxyk + 2Δxc − Δx
pk = Δx(dl − du) = 2Δyxk − 2Δxyk
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
pk = 2Δyxk − 2Δxyk
pknext = 2Δyxknext − 2Δxyknext
pknext − pk = 2Δyxknext − 2Δxyknext − 2Δyxk + 2Δxyk
pknext − pk = 2Δy(xknext − xk) − 2Δx(yknext − yk)
pknext − pk = 2Δy(xknext − xk) − 2Δx(yknext − yk)
if(pknext − pk) < 0
pknext = pk + 2Δy(xknext − xk) − 2Δx(yknext − yk)
pknext = pk + 2Δy
if(pknext − pk) > = 0
pknext = pk + 2Δy(xknext − xk) − 2Δx(yknext − yk)
pknext = pk + 2Δy − 2Δx
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
InitialDecisionParameter
p0 = 2Δyx1 + 2Δy − 2Δxy1 + 2Δxc − Δx
c = y −
Δy
Δx
x1
p0 = 2Δyx1 + 2Δy − 2Δxy1 + 2Δx[y −
Δy
Δx
x1] − Δx
p0 = 2Δyx1 + 2Δy − 2Δxy1 + 2Δxy1 − 2Δyx1 − Δx
p0 = 2Δy − Δx
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Algorithm breshanmsLine( )
______________________________________
x1, y1, x2, y2
x = x1
y = y1
dx = x2 − x1
dy = y2 − y1
p = 2dy − dx
while(x < = x2)
putpixel(x, y)
x + +
if(p < 0)
p = p + 2dy
else
p = 2dy − 2dx + p
y + +
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
x Y P
9 18 3
10 19 1
11 20 -1
12 20 7
13 21 5
14 22 3
x = x1
y = y1
dx = x2 − x1
dy = y2 − y1
p = 2dx − dy
while(x < = x2)
putpixel(x, y)
x + +
if(p < 0)
p = p + 2dy
else
p = 2dy − dx + p
y + +
(9,18) (14,22)
dx = 14 − 9 = 5
dy = 22 − 18 = 4
p = (2 * 4) − 5 = 3
pnext = 3 + (2 * 4) − (2 * 5) = 1
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Yaxis
15
16
17
18
19
20
21
22
23
24
25
X axis
6 7 8 9 10 11 12 13 14 15 16
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
x Y P
20 10
21 11 6
22 12 2
23 12 -2
24 13 14
25 14 10
26 15 6
27 16 2
28 16 -2
29 17 14
30 18 10
dx= 10
dy= 8
p=6
2dy = 16
2dy-2dx=-4
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
x Y P
2 3
3 4 7
4 5 11
5 6 15
6 7 19
dx= 3
dy= 5
p=7
2dy = 10
2dy-2dx=4
(2,3) and (5,8)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Circle
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Frequently used component in
image and graph
• Properties of Circles
• A Circle is defined as the set of
points that are all at a given
distance r from a centre position
•
• Distance Relationship
Center(xc, yc)
(x − xc)2
+ (y − yc)2
= r2
• Scan conversion
• Calculate the position of points
on a circle circumference by
stepping along the x axis in unit
step
•
• Calculate
• Not a best method
• Lot of computation
• Unequal spacing
(xc − r)to(xc + r)
y = yc ± (r2
− (xc − x)2
r
x
y
(xc, yc)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Calculate points along the circular boundary using polar
coordinates r and
• Circle equation in parametric polar form
•
•
• Generated with these equations using a fixed angular step size
• The step size chosen for 8 depends on the application and the
display device
• Step size at
• Plots pixel positions that are approximately one unit apart.
θ
x = xc + r ⋅ cosθ
y = yc + r ⋅ sinθ
1
r
UniformSpacing
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Symmetry of Circle
• Shape of the circle is similar in each quadrant
• Generate the circle section in the second quadrant
• The section of circle is symmetric across y axis
• Above section of circle to generate III and IV quadrant
• One step further
• Symmetry between octant
• A one-eighth circle sector is mapped to seven circle points
in the other octants of the plane
• Cartesian equation - multiplications and square root
• Parametric equations - Multiplications & Trigonometric
• Incremental calculation of decision parameters
xy
Computations
.
(x, y)
.
(x, − y)
.
(y, x)
.(y, − x)
.(−y, − x)
.
(−x, − y)
.(−y, x)
.
(−x, y)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Midpoint Circle Algorithm
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Center
•
•
• For any pixel
•
•
(0,0)
x2
+ y2
= r2
x2
+ y2
− r2
= 0
(x1, y1)
x2
1 + y2
1 − r2
= ?
res = ?
• If
• Point Lies on the Circle
• If
• Point Lies inside the Circle
• If
• Point Lies outside the Circle
(res = 0)
(res < 0)
(res > 0)
CircleEquation
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
.
. (x1, y1)
r
.
< r
. > r
(x2, y2)
(x3, y3)
•
•
• Point Lies on the Circle
•
• Point Lies inside the Circle
•
• Point Lies outside the Circle
x2
+ y2
− r2
= 0
x2
1 + y2
1 = r2
x2
1 + y2
1 < r2
x2
1 + y2
1 > r2
(0,0)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
.
.
.
.
.
.
.
.
.
.
. South Pixel
South East Pixel
. Starting Pixel (0, r)
Point − > (xk, yk)
(xk + 1,yk)
(xk + 1,yk − 1)
(xk, yk) (xk + 1,yk)
(xk + 1,yk − 1)
X always increases
Midpoint ( Decision Parameter )
.
If Mid Point is inside the circle P < 0
Select South Pixel
If Mid Point is Outside the circle P > 0
Select South East Pixel
(xk + 1,yk)
(xk + 1,yk − 1)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Midpoint
midpoint = [
xk+1 + xk+1
2
,
yk + yk−1
2
]
midpoint = [
xk + 1 + xk + 1
2
,
yk + yk − 1
2
]
midpoint = [xk + 1,yk −
1
2
]
midpoint = [xk+1, yk− 1
2
]
midpoint = [xm, ym]
(xk + 1,yk)
(xk + 1,yk − 1)
.
.
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Decision Parameter
midpoint = [xm, ym]
(pk)
pk = x2
m + y2
m − r2
pk = x2
k+1 + y2
k− 1
2
− r2
pk+1 = (xk+1 + 1)2
+ (yk+1 −
1
2
)2
− r2
pk+1 − pk = (xk+1 + 1)2
+ (yk+1 −
1
2
)2
− r2
− x2
k+1 − y2
k−1
2
+ r2
pk+1 − pk = (xk + 1 + 1)2
+ (yk+1 −
1
2
)2
− (xk + 1)2
− y2
k−1
2
pk+1 − pk = (xk + 2)2
+ (yk+1 −
1
2
)2
− (xk + 1)2
− y2
k−1
2
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
•
•
•
•
•
•
•
•
pk+1 − pk = (xk + 2)2
+ (yk+1 −
1
2
)2
− (xk + 1)2
− y2
k−1
2
pk+1 − pk = (x2
k + 4 + 4xk) + (y2
k+1 +
1
4
− yk+1) − (x2
k + 1 + 2xk) − (y2
k +
1
4
− yk)
pk+1 − pk = x2
k + 4 + 4xk + y2
k+1 +
1
4
− yk+1 − x2
k − 1 − 2xk − y2
k −
1
4
+ yk
pk+1 − pk = 2xk + 3 + y2
k+1 − yk+1 − y2
k + yk
pk+1 = pk + 2xk + 3 + y2
k+1 − y2
k − yk+1 + yk
if(pk > 0)
yk+1 = ?
yk+1 = yk − 1
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
pk+1 = pk + 2xk + 3 + y2
k+1 − y2
k − yk+1 + yk
if(pk < 0)
yk+1 = yk
pk+1 = pk + 2xk + 3 + y2
k − y2
k − yk + yk
pk+1 = pk + 2xk + 3
if(pk > 0)
yk+1 = yk − 1
pk+1 = pk + 2xk + 3 + (yk − 1)2
− y2
k − (yk − 1) + yk
pk+1 = pk + 2xk + 3 + y2
k − 2yk + 1 − y2
k − yk + 1 + yk
pk+1 = pk + 2xk − 2yk + 5
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Initial Point
p0 = ?
(0,r)
p0 = x2
m + y2
m − r2
p0 = (xk + 1)2
+ (yk −
1
2
)2
− r2
p0 = (0 + 1)2
+ (r −
1
2
)2
− r2
p0 = (0 + 1)2
+ (r2
− r +
1
4
) − r2
p0 =
5
4
− r
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
midpointCircle(r)
1. or
2. and project on
remaining Octant
3. Loop
p0 =
5
4
− r p0 = 1 − r
plot(xi, yi)
if(pi < 0)then
pi+1 = pi + 2xi + 3
yi+1 = yi
xi+1 = xi + 1
project on remaining
Octant
Repeat until
if(pi > 0)then
pi+1 = pi + 2(xi − yi) + 5
yi+1 = yi − 1
xi+1 = xi + 1
plot(xi+1, yi+1)
(x > = y)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
(1) or
(2)
(3)
(4) while
p =
5
4
− r p = 1 − r
x = 0,y = r
plot(x, y)
(x > = y)
if(p < 0)then
p = p + 2x + 3
if(p > 0)then
p = p + 2 × (x − y) + 5
y = y − 1
x = x + 1
plot(x, y)
midPointCircle(xc, yc, r)
p x Y
0 10
-9 1 10
-6 2 10
-1 3 10
6 4 9
-3 5 9
8 6 8
5 7 7
midPointCircle(0,0,10)
p = 1 − 10 = − 9
p < 0
p = (−9) + 2 × 0 + 3 = − 6
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
(1) or
(2)
(3)
(4) while
p =
5
4
− r p = 1 − r
x = 0,y = r
plot(x, y)
(x > = y)
if(p < 0)then
p = p + 2x + 3
if(p > 0)then
p = p + 2(x − y) + 5
y = y − 1
x = x + 1
plot(x, y)
midPointCircle(xc, yc, r)
p x Y
0 5
-4 1 5
-1 2 5
4 3 4
-3 4 4
midPointCircle(0,0,5)
p = 1 − 5 = − 4
p < 0
p = (−9) + 2 * 0 + 3 = − 6
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
p x Y
0 10
-9 1 10
-6 2 10
-1 3 10
6 4 9
-3 5 9
8 6 8
5 7 7
midPointCircle(3,4,10)
p = 1 − 10 = − 9
p < 0
p = (−9) + 2 * 0 + 3 = − 6
x Y
3 14
4 14
5 14
6 14
7 13
8 13
9 12
10 11
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
p x Y
0 8
-7 1 8
-4 2 8
1 3 7
-6 4 7
3 5 6
midPointCircle(5,5,8)
x Y
5 13
6 13
7 13
8 12
9 12
10 11
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Ellipse
x2
r2
x
+
y2
r2
y
= 1
(0,0) rx
ry
⋅
R1
R2
Sample x point
Sample y point
Slope = -1
Slope < -1
Slope > -1
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• An ellipse is an elongated circle
• An ellipse is defined as the set of
points such that the sum of the
distances from two fixed positions
(foci) is the same for all points
•
•
•
•
P = (x, y)
d1 : Distance from the First foci
d2 : Distance from the Second foci
d1 + d2 = constant
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Focal Coordinates
•
•
•
• squaring this equation, isolating the remaining radical
•
• Evaluation of the coefficients
• Focal Coordinates
• Dimensions of the major and minor axes
• Ellipse equations are greatly simplified if the major and minor axes are oriented to
align with the coordinate axes.
F1 = (x1, y1)
F2 = (x2, y2)
(x − x1) + (y − y1) + (x − x2) + (y − y2) = constant
Ax2
+ By2
+ Cxy + Dx + Ey + F = 0
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Ellipse in standard position
• Major and Minor axes oriented
parallel to the x and y axes
•
•
• The equation of the ellipse in terms
of the centre coordinates
and parameters and
•
• Center
•
• Using polar coordinates
•
•
• Symmetry considerations can be
used to further reduce computation
• Symmetric between quadrants
rx semi major axis
ry semi minor axis
(xc, yc)
rx ry
(
x − xc
rx
)2
+ (
y − yc
ry
)2
= 1
(0,0)
(
x
rx
)2
+ (
y
ry
)2
= 1
x = xc + rx cosθ
y = yc + ry sinθ
calculate pixel positions along the elliptical arc throughout one quadrant,
then we obtain positions in the remaining three quadrants by symmetry
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Mid Point Ellipse
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Similar to display raster circle
• Input
• Ellipse in standard position centred
on the origin
• Translate and Rotate to orient the
Major and Minor axes
• The midpoint ellipse method is
applied throughout the first
quadrant in two parts.
• Region I
• Region II
•rx, ry, (xc, yc)
(Slope of curve < − 1)
(Slope of curve > − 1)
ry
rx
Slope < − 1
Slope > − 1
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Region I
• Unit steps in the direction
• Slope of the curve less than -1
•
• Start position
• Step clockwise along the elliptical
path in the first quadrant
• Shifting from unit steps in to unit
steps in when the slope becomes
less than
• Region II
• Unit steps in the y direction
• Slop greater than -1

•
• Start position
• Step counter clockwise along the
elliptical path in the first quadrant
• Shifting from unit steps in to unit
steps in when the slope becomes
greater than
• Parallel processing
x
|slope| < 1
(0,ry)
x
y
−1
|slope| > 1
(rx,0)
y
x
−1
Calculate pixel positions in the two regions simultaneously
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Sequential Implementation
• Start Point
• Step along the ellipse path in
clockwise order throughout the
first quadrant.
•
• For any point
•
•
• Decision Parameter
•
• Point lies inside the ellipse
•
• Point lies on the ellipse
•
• Point lies outside the ellipse
• At each position, the next pixel
along the ellipse path is selected
• Sign of the ellipse function
evaluated at the midpoint between
the two candidate pixels.
(0,ry)
r2
y x2
+ r2
x y2
− r2
x r2
y = 0
(xk, yk)
r2
y x2
k + r2
x y2
k − r2
x r2
y = ?
res = ?
if(res < 0)
if(res = 0)
if(res > 0)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Starting Point
• Take unit steps in the direction
• Continue till the boundary between
region 1 and region 2
• Then take unit steps in the
direction over the remainder of the
curve in the first quadrant.
• At each step, test the value of the
slope of the curve.
•
•
• On the boundary
•
•
• Out of region I

•
(0,ry)
x
y
d
dx
(r2
y x2
+ r2
x y2
− r2
x r2
y ) = 0
dy
dx
= −
2r2
y x
2r2
x y
dy/dx = − 1
2r2
y x = 2r2
x y
2r2
y x > = 2r2
x y
Slope
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
[Region I]
• Previous position
• Sampling position
• Midpoint between the two
candidate pixels
•
• Evaluating the decision parameterat
midpoint
•
•
•
• Mid point is inside the ellipse
•
•
• Mid point is on the ellipse
•
•
• Mid point is outside the ellipse
•
(xk, yk)
xk+1
(xk + 1,yk) (xk + 1,yk − 1)
Mid Point (xk + 1,yk −
1
2
)
p1k = r2
y (xk + 1)2
+ r2
x (yk −
1
2
)2
− r2
x r2
y
if (p1k < 0)
(xk + 1,yk)
if (p1k = 0)
(xk + 1,yk − 1)
if (p1k > 0)
(xk + 1,yk − 1)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
p1k = r2
y (xk + 1)2
+ r2
x (yk −
1
2
)2
− r2
x r2
y
p1k+1 = r2
y (xk+1 + 1)2
+ r2
x (yk+1 −
1
2
)2
− r2
x r2
y
p1k+1 = r2
y (xk + 1 + 1)2
+ r2
x (yk+1 −
1
2
)2
− r2
x r2
y
p1k+1 − p1k = r2
y (xk + 1 + 1)2
+ r2
x (yk+1 −
1
2
)2
− r2
x r2
y − r2
y (xk + 1)2
− r2
x (yk −
1
2
)2
+ r2
x r2
y
p1k+1 − p1k = r2
y ((xk + 1)2
+ 1 + 2(xk + 1) − r2
y (x2
k + 1 + 2xk) + r2
x (y2
k+1 +
1
4
− yk+1) − r2
x (y2
k +
1
4
− yk)
p1k+1 − p1k = r2
y (x2
k + 1 + 2xk + 1 + 2xk + 2 − x2
k − 1 − 2xk) + r2
x (y2
k+1 +
1
4
− yk+1 − y2
k −
1
4
+ yk)
p1k+1 − p1k = r2
y {2(xk + 1) + 1} + r2
x (y2
k+1 − y2
k − yk+1 + yk)
p1k+1 = p1k + r2
y {2(xk + 1) + 1} + r2
x (y2
k+1 − y2
k − yk+1 + yk)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
•
•
•
•
•
•
•
p1k+1 = p1k + r2
y {2(xk + 1) + 1} + r2
x (y2
k+1 − y2
k − yk+1 + yk)
if (p1k < 0)
yk+1 = yk
p1k+1 = p1k + 2r2
y xk+1 + 1 + r2
y
if (p1k > = 0)
yk+1 = yk − 1
p1k+1 = p1k + 2r2
y xk+1 + 1 + r2
y − 2r2
x yk+1
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
• Initial Point
•
•
•
•
•
•
(0,ry)
p1k = r2
y (xk + 1)2
+ r2
x (yk −
1
2
)2
− r2
x r2
y
p10 = r2
y (0 + 1)2
+ r2
x (ry −
1
2
)2
− r2
x r2
y
p10 = r2
y + r2
x (r2
y +
1
4
− ry) − r2
x r2
y
p10 = r2
y + r2
x r2
y +
r2
x
4
− r2
x ry − r2
x r2
y
p10 = r2
y +
r2
x
4
− r2
x ry
⋅
⋅(0,ry)
(0,0)
Ist Quadrant
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
(0,0) rx
ry
⋅
Sample x point
Sample y point
Slope = -1
Slope < -1
Slope > -1
⋅⋅⋅
⋅⋅⋅(xk + 1,yk − 1)(xk, yk − 1)
(xk + 1,yk)
(xk + 1,yk − 1)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
[Region II]
• Previous position
• Sampling position
• Midpoint between the two
candidate pixels
•
• Evaluating the decision parameter
at midpoint
•
•
•
• Mid point is inside the ellipse
•
•
• Mid point is on the ellipse
•
•
• Mid point is outside the ellipse
•
(xk, yk)
yk+1
(xk, yk − 1) (xk + 1,yk − 1)
Mid Point (xk +
1
2
, yk − 1)
p2k = r2
y (xk +
1
2
)2
+ r2
x (yk − 1)2
− r2
x r2
y
if (p2k < 0)
(xk + 1,yk − 1)
if (p2k = 0)
(xk, yk − 1)
if (p2k > 0)
(xk, yk − 1)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
p2k = r2
y (xk +
1
2
)2
+ r2
x (yk − 1)2
− r2
x r2
y
p2k+1 = r2
y (xk+1 +
1
2
)2
+ r2
x (yk+1 − 1)2
− r2
x r2
y
p2k+1 = r2
y (xk+1 +
1
2
)2
+ r2
x (yk − 1 − 1)2
− r2
x r2
y
p2k+1 − p2k = r2
y (xk+1 +
1
2
)2
+ r2
x (yk − 1 − 1)2
− r2
x r2
y − r2
y (xk +
1
2
)2
− r2
x (yk − 1)2
− r2
x r2
y
p2k+1 − p2k = r2
y (x2
k+1 +
1
4
+ xk+1) − r2
y (x2
k +
1
4
+ xk) + r2
x ((yk − 1)2
+ 1 − 2(yk − 1)) − r2
x (y2
k + 1 + 2yk)
p2k+1 − p2k = r2
y (x2
k+1 +
1
4
+ xk+1 − x2
k −
1
4
− xk) + r2
x (y2
k + 1 − 2yk + 1 − 2yk + 2 − y2
k − 1 + 2yk)
p2k+1 − p2k = r2
y (x2
k+1 + xk+1 − x2
k − xk) + r2
x (1 − 2(yk − 1))
p2k+1 = p2k + r2
y (x2
k+1 + xk+1 − x2
k − xk) + r2
x (1 − 2yk+1)
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
•
•
•
•
•
•
•
p2k+1 = p2k + r2
y (x2
k+1 + xk+1 − x2
k − xk) + r2
x (1 − 2yk+1)
if (p2k > 0)
xk+1 = xk
p2k+1 = p2k − 2r2
x yk+1 + r2
x
if (p2k < = 0)
xk+1 = xk + 1
p2k+1 = p2k + 2r2
y xk+1 − 2r2
x yk+1 + r2
x
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
InitialPoint
• Last Point of [Region I]
• Let
•
•
(x, y)
p2k = r2
y (xk +
1
2
)2
+ r2
x (yk − 1)2
− r2
x r2
y
p20 = r2
y (x +
1
2
)2
+ r2
x (y − 1)2
− r2
x r2
y
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
Algorithm
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
midPointEllipse
(1)
(2)
(3) ,
(4) while 























(5) 

(6) 





















(rx, ry, xc, yc)
(x0, y0) = (0,ry)
p10 = r2
y +
r2
x
4
− r2
x ry
dx = 2r2
y x dy = 2r2
x y
(dx < = dy)
plot (x, y)
if (p1 < 0)
x = x + 1
dx = 2r2
y x
p1 = p1 + 2r2
y x + r2
y
else
x = x + 1
y = y − 1
dx = 2r2
y x
dy = 2r2
x y
p1 = p1 + 2r2
y x − 2r2
x y + r2
y
p20 = r2
y (x +
1
2
)2
+ r2
x (y − 1)2
− r2
x r2
y
while (y > 0)
plot (x, y)
if (p2 > 0)
y = y − 1
dy = 2r2
x y
p2 = p2 − 2r2
x y + r2
x
else
x = x + 1
y = y − 1
dx = 2r2
y x
dy = 2r2
x y
p2 = p2 + 2r2
y x − 2r2
x y + r2
x
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
(x_k,y_k) P (x_k+1, y_k+1) dx dy
(0,6) -332 (1,6) 72 764
(1,6) -224 (2,6) 114 768
(2,6) -44 (3,6) 216 768
(3,6) 208 (4,5) 288 640
(4,5) -108 (5,5) 360 640
(5,5) 288 (6,4) 432 512
(6,4) 244 (7,3) 504 384
End of Region 1
midPointEllipse(rx : 8, ry : 6)
p10 = r2
y − r2
x ry +
1
4
r2
x
(6)2
− (8)2
⋅ 6 +
1
4
⋅ (8)2
= − 332
p1 < 0
dx = 2r2
y ⋅ xk+1
dx = 2(6)2
(1)
dy = 2r2
x ⋅ yk+1
dy = 2(8)2
(6)
p1 = p1 + 2r2
y x + r2
y
p1 = − 332 + 72 + (6)2
p14 = p13 + 2r2
y x − 2r2
x y + r2
y
p14 = 208 + (2 ⋅ (6)2
⋅ 4) − (2 ⋅ (8)2
⋅ 5) + (6)2
p1 > 0
Mr. Rupesh Mishra | rupeshmishra@sfit.ac.in
(x_k,y_k) P (x_k+1, y_k+1) dx dy
(6,4) 244 (7,3) 504 384
Start of Region II
(7,3) -23 (8,2) 576 256
(8,2) 361 (8,1) 576 128
(8,1) 297 (8,0) - -
midPointEllipse(rx : 8, ry : 6)
p20 = r2
y (x +
1
2
)2
+ r2
x (y − 1)2
− r2
x r2
y
(36)2
(7 +
1
2
)2
+ (6)2
(3 − 1)2
− (8)2
(6)2
p2 < 0
dx = 2r2
y ⋅ xk+1
dx = 2(6)2
(8)
dy = 2r2
x ⋅ yk+1
dy = 2(8)2
(2)
p2 = p2 + 2r2
y x − 2r2
x y + r2
x
Region II − Start Point (7,3)
p2 = − 23 + 576 − 256 + 64
p2 > 0
p2 = p2 − 2r2
x y + r2
x
p2 = 361 − 128 + 64

Computer Graphics - Output Primitive

  • 1.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in OutputPrimitive 1 St. Francis Institute of Technology Department of Computer Engineering 1 Subject Incharge Rupesh Mishra Asst. Professor  Room No. 401 rupeshmishra@sfit.ac.in 31 July 2020
  • 2.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in 2 Module II Lecture 4 Computer Graphics: Output Primitive St. Francis Institute of Technology Department of Computer Engineering 1
  • 3.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in
  • 4.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in OutputPrimitive • Graphics programming packages • Describe a scene in terms of basic geometric structures (Output Primitives) • Group output primitives into more complex structures. • Each output primitive is specified with • Input coordinate data • Information about object to be displayed. • Point, Line, Circle, Conic Section, Spline curves, polygon and Character String.
  • 5.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Point
  • 6.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Point • Point plotting is accomplished by converting a single coordinate position into appropriate operations for the output device in use. • Setting value in frame buffer • Moving beam of electron at the selected location (CRT) • Point plotting instruction in display list (Random Scan) • Converted to deflection voltages to position the electron beam. • Frame buffer is loaded with the color codes (RGB System)
  • 7.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Line
  • 8.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Line • Collection of points over a path • Plotting discrete points between the two endpoints. • Calculated from the equation of the line • Frame buffer loaded with intensity value at the corresponding pixel coordinates. • Video Controller plots the screen pixels • Approximation of actual points • (10.4, 20.5) converted to (10, 21) • Stair-step appearance in low resolution
  • 9.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in LineDrawing • The Cartesian slope-intercept equation for a straight line • • • intercept • Given end point of line • • y = m ⋅ x + c m : Slope c : y (x1, y1), (x2, y2) m = (y2 − y1) (x2 − x1) c = y1 − m ⋅ x1 Line Segment Y intercept x intercept (x1, y1) (x2, y2) x axis Y axis
  • 10.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • For any given interval along a line, we can compute the corresponding y interval • • Similarly • x Δx Δy Δy = m . Δx Δx = Δy m Δy Δx
  • 11.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Δy Δx Δx Δy Δx Δy For angle more than 45∘ Δy Δx > 1 For angle less than 45∘ Δy Δx < 1 For angle equal 45∘ Δy Δx = 1
  • 12.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in DigitalDifferentialAnalyser • Scan-conversion line algorithm • Calculating either or • Sample the line at unit intervals in one coordinate • Determine corresponding integer values nearest the line path for the other coordinate. • DDA algorithm works even if points are reversed Δx Δy DDA
  • 13.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in (1) Compute (2)If then else Δx = x2 − x1 Δy = y2 − y1 abs(Δx) > abs(Δy) steps = abs(Δx) steps = abs(Δy) (3) (4) (5)repeat for all steps xinc = Δx steps yinc = Δy steps
  • 14.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in LimitationofDDA • Time Consuming • Floating Point Numbers • Roundoff Error
  • 15.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in
  • 16.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Bresenham's Line Algorithm
  • 17.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Accurate and efficient raster line-generating algorithm • Using only incremental integer calculations • Sampling at unit intervals • Decide possible pixel positions closer to the line path at each sample step. • Weather to plot pixel at position in the next step • Testing the sign of an integer parameter, whose value is proportional to the difference between the separations of the two pixel positions from the actual line path. x (11,11)or(11,12) 10 11 12 13 14 10 11 12 13 . . . .
  • 18.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in du dl Decisión parameter y = mx + c y = m(xk + 1) + c dl = y − yk = [m(xk + 1) + c] − yk du = yk+1 − y = yk+1 − [m(xk + 1) + c] if(dl − du < 0) − > yk if(dl − du > 0) − > yk+1 xk yk+1 yk xk+1 y
  • 19.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in dl − du = [[m(xk + 1) + c] − yk] − [yk+1 − [m(xk + 1) + c]] dl − du = m(xk + 1) + c − yk − yk+1 + m(xk + 1) − c dl − du = 2m(xk + 1) − 2yk + 2c − 1 m = Δy Δx dl − du = 2Δy Δx (xk + 1) − 2yk + 2c − 1 dl − du = Δx[ 2Δy Δx (xk + 1) − 2yk + 2c − 1] Δx(dl − du) = 2Δy(xk + 1) − 2Δxyk + 2Δxc − Δx pk = Δx(dl − du) = 2Δyxk + 2Δy − 2Δxyk + 2Δxc − Δx pk = Δx(dl − du) = 2Δyxk − 2Δxyk
  • 20.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in pk = 2Δyxk − 2Δxyk pknext = 2Δyxknext − 2Δxyknext pknext − pk = 2Δyxknext − 2Δxyknext − 2Δyxk + 2Δxyk pknext − pk = 2Δy(xknext − xk) − 2Δx(yknext − yk) pknext − pk = 2Δy(xknext − xk) − 2Δx(yknext − yk) if(pknext − pk) < 0 pknext = pk + 2Δy(xknext − xk) − 2Δx(yknext − yk) pknext = pk + 2Δy if(pknext − pk) > = 0 pknext = pk + 2Δy(xknext − xk) − 2Δx(yknext − yk) pknext = pk + 2Δy − 2Δx
  • 21.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in InitialDecisionParameter p0 = 2Δyx1 + 2Δy − 2Δxy1 + 2Δxc − Δx c = y − Δy Δx x1 p0 = 2Δyx1 + 2Δy − 2Δxy1 + 2Δx[y − Δy Δx x1] − Δx p0 = 2Δyx1 + 2Δy − 2Δxy1 + 2Δxy1 − 2Δyx1 − Δx p0 = 2Δy − Δx
  • 22.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Algorithm breshanmsLine( ) ______________________________________ x1, y1, x2, y2 x = x1 y = y1 dx = x2 − x1 dy = y2 − y1 p = 2dy − dx while(x < = x2) putpixel(x, y) x + + if(p < 0) p = p + 2dy else p = 2dy − 2dx + p y + +
  • 23.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in x Y P 9 18 3 10 19 1 11 20 -1 12 20 7 13 21 5 14 22 3 x = x1 y = y1 dx = x2 − x1 dy = y2 − y1 p = 2dx − dy while(x < = x2) putpixel(x, y) x + + if(p < 0) p = p + 2dy else p = 2dy − dx + p y + + (9,18) (14,22) dx = 14 − 9 = 5 dy = 22 − 18 = 4 p = (2 * 4) − 5 = 3 pnext = 3 + (2 * 4) − (2 * 5) = 1
  • 24.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Yaxis 15 16 17 18 19 20 21 22 23 24 25 X axis 6 7 8 9 10 11 12 13 14 15 16
  • 25.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in x Y P 20 10 21 11 6 22 12 2 23 12 -2 24 13 14 25 14 10 26 15 6 27 16 2 28 16 -2 29 17 14 30 18 10 dx= 10 dy= 8 p=6 2dy = 16 2dy-2dx=-4
  • 26.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in x Y P 2 3 3 4 7 4 5 11 5 6 15 6 7 19 dx= 3 dy= 5 p=7 2dy = 10 2dy-2dx=4 (2,3) and (5,8)
  • 27.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Circle
  • 28.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Frequently used component in image and graph • Properties of Circles • A Circle is defined as the set of points that are all at a given distance r from a centre position • • Distance Relationship Center(xc, yc) (x − xc)2 + (y − yc)2 = r2 • Scan conversion • Calculate the position of points on a circle circumference by stepping along the x axis in unit step • • Calculate • Not a best method • Lot of computation • Unequal spacing (xc − r)to(xc + r) y = yc ± (r2 − (xc − x)2 r x y (xc, yc)
  • 29.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Calculate points along the circular boundary using polar coordinates r and • Circle equation in parametric polar form • • • Generated with these equations using a fixed angular step size • The step size chosen for 8 depends on the application and the display device • Step size at • Plots pixel positions that are approximately one unit apart. θ x = xc + r ⋅ cosθ y = yc + r ⋅ sinθ 1 r UniformSpacing
  • 30.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Symmetry of Circle • Shape of the circle is similar in each quadrant • Generate the circle section in the second quadrant • The section of circle is symmetric across y axis • Above section of circle to generate III and IV quadrant • One step further • Symmetry between octant • A one-eighth circle sector is mapped to seven circle points in the other octants of the plane • Cartesian equation - multiplications and square root • Parametric equations - Multiplications & Trigonometric • Incremental calculation of decision parameters xy Computations . (x, y) . (x, − y) . (y, x) .(y, − x) .(−y, − x) . (−x, − y) .(−y, x) . (−x, y)
  • 31.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Midpoint Circle Algorithm
  • 32.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Center • • • For any pixel • • (0,0) x2 + y2 = r2 x2 + y2 − r2 = 0 (x1, y1) x2 1 + y2 1 − r2 = ? res = ? • If • Point Lies on the Circle • If • Point Lies inside the Circle • If • Point Lies outside the Circle (res = 0) (res < 0) (res > 0) CircleEquation
  • 33.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in . . (x1, y1) r . < r . > r (x2, y2) (x3, y3) • • • Point Lies on the Circle • • Point Lies inside the Circle • • Point Lies outside the Circle x2 + y2 − r2 = 0 x2 1 + y2 1 = r2 x2 1 + y2 1 < r2 x2 1 + y2 1 > r2 (0,0)
  • 34.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in . . . . . . . . . . . South Pixel South East Pixel . Starting Pixel (0, r) Point − > (xk, yk) (xk + 1,yk) (xk + 1,yk − 1) (xk, yk) (xk + 1,yk) (xk + 1,yk − 1) X always increases Midpoint ( Decision Parameter ) . If Mid Point is inside the circle P < 0 Select South Pixel If Mid Point is Outside the circle P > 0 Select South East Pixel (xk + 1,yk) (xk + 1,yk − 1)
  • 35.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Midpoint midpoint = [ xk+1 + xk+1 2 , yk + yk−1 2 ] midpoint = [ xk + 1 + xk + 1 2 , yk + yk − 1 2 ] midpoint = [xk + 1,yk − 1 2 ] midpoint = [xk+1, yk− 1 2 ] midpoint = [xm, ym] (xk + 1,yk) (xk + 1,yk − 1) . .
  • 36.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Decision Parameter midpoint = [xm, ym] (pk) pk = x2 m + y2 m − r2 pk = x2 k+1 + y2 k− 1 2 − r2 pk+1 = (xk+1 + 1)2 + (yk+1 − 1 2 )2 − r2 pk+1 − pk = (xk+1 + 1)2 + (yk+1 − 1 2 )2 − r2 − x2 k+1 − y2 k−1 2 + r2 pk+1 − pk = (xk + 1 + 1)2 + (yk+1 − 1 2 )2 − (xk + 1)2 − y2 k−1 2 pk+1 − pk = (xk + 2)2 + (yk+1 − 1 2 )2 − (xk + 1)2 − y2 k−1 2
  • 37.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • • • • • • • • pk+1 − pk = (xk + 2)2 + (yk+1 − 1 2 )2 − (xk + 1)2 − y2 k−1 2 pk+1 − pk = (x2 k + 4 + 4xk) + (y2 k+1 + 1 4 − yk+1) − (x2 k + 1 + 2xk) − (y2 k + 1 4 − yk) pk+1 − pk = x2 k + 4 + 4xk + y2 k+1 + 1 4 − yk+1 − x2 k − 1 − 2xk − y2 k − 1 4 + yk pk+1 − pk = 2xk + 3 + y2 k+1 − yk+1 − y2 k + yk pk+1 = pk + 2xk + 3 + y2 k+1 − y2 k − yk+1 + yk if(pk > 0) yk+1 = ? yk+1 = yk − 1
  • 38.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in pk+1 = pk + 2xk + 3 + y2 k+1 − y2 k − yk+1 + yk if(pk < 0) yk+1 = yk pk+1 = pk + 2xk + 3 + y2 k − y2 k − yk + yk pk+1 = pk + 2xk + 3 if(pk > 0) yk+1 = yk − 1 pk+1 = pk + 2xk + 3 + (yk − 1)2 − y2 k − (yk − 1) + yk pk+1 = pk + 2xk + 3 + y2 k − 2yk + 1 − y2 k − yk + 1 + yk pk+1 = pk + 2xk − 2yk + 5
  • 39.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Initial Point p0 = ? (0,r) p0 = x2 m + y2 m − r2 p0 = (xk + 1)2 + (yk − 1 2 )2 − r2 p0 = (0 + 1)2 + (r − 1 2 )2 − r2 p0 = (0 + 1)2 + (r2 − r + 1 4 ) − r2 p0 = 5 4 − r
  • 40.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in midpointCircle(r) 1. or 2. and project on remaining Octant 3. Loop p0 = 5 4 − r p0 = 1 − r plot(xi, yi) if(pi < 0)then pi+1 = pi + 2xi + 3 yi+1 = yi xi+1 = xi + 1 project on remaining Octant Repeat until if(pi > 0)then pi+1 = pi + 2(xi − yi) + 5 yi+1 = yi − 1 xi+1 = xi + 1 plot(xi+1, yi+1) (x > = y)
  • 41.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in (1) or (2) (3) (4) while p = 5 4 − r p = 1 − r x = 0,y = r plot(x, y) (x > = y) if(p < 0)then p = p + 2x + 3 if(p > 0)then p = p + 2 × (x − y) + 5 y = y − 1 x = x + 1 plot(x, y) midPointCircle(xc, yc, r) p x Y 0 10 -9 1 10 -6 2 10 -1 3 10 6 4 9 -3 5 9 8 6 8 5 7 7 midPointCircle(0,0,10) p = 1 − 10 = − 9 p < 0 p = (−9) + 2 × 0 + 3 = − 6
  • 42.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in (1) or (2) (3) (4) while p = 5 4 − r p = 1 − r x = 0,y = r plot(x, y) (x > = y) if(p < 0)then p = p + 2x + 3 if(p > 0)then p = p + 2(x − y) + 5 y = y − 1 x = x + 1 plot(x, y) midPointCircle(xc, yc, r) p x Y 0 5 -4 1 5 -1 2 5 4 3 4 -3 4 4 midPointCircle(0,0,5) p = 1 − 5 = − 4 p < 0 p = (−9) + 2 * 0 + 3 = − 6
  • 43.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in p x Y 0 10 -9 1 10 -6 2 10 -1 3 10 6 4 9 -3 5 9 8 6 8 5 7 7 midPointCircle(3,4,10) p = 1 − 10 = − 9 p < 0 p = (−9) + 2 * 0 + 3 = − 6 x Y 3 14 4 14 5 14 6 14 7 13 8 13 9 12 10 11
  • 44.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in p x Y 0 8 -7 1 8 -4 2 8 1 3 7 -6 4 7 3 5 6 midPointCircle(5,5,8) x Y 5 13 6 13 7 13 8 12 9 12 10 11
  • 45.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Ellipse x2 r2 x + y2 r2 y = 1 (0,0) rx ry ⋅ R1 R2 Sample x point Sample y point Slope = -1 Slope < -1 Slope > -1
  • 46.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • An ellipse is an elongated circle • An ellipse is defined as the set of points such that the sum of the distances from two fixed positions (foci) is the same for all points • • • • P = (x, y) d1 : Distance from the First foci d2 : Distance from the Second foci d1 + d2 = constant
  • 47.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Focal Coordinates • • • • squaring this equation, isolating the remaining radical • • Evaluation of the coefficients • Focal Coordinates • Dimensions of the major and minor axes • Ellipse equations are greatly simplified if the major and minor axes are oriented to align with the coordinate axes. F1 = (x1, y1) F2 = (x2, y2) (x − x1) + (y − y1) + (x − x2) + (y − y2) = constant Ax2 + By2 + Cxy + Dx + Ey + F = 0
  • 48.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Ellipse in standard position • Major and Minor axes oriented parallel to the x and y axes • • • The equation of the ellipse in terms of the centre coordinates and parameters and • • Center • • Using polar coordinates • • • Symmetry considerations can be used to further reduce computation • Symmetric between quadrants rx semi major axis ry semi minor axis (xc, yc) rx ry ( x − xc rx )2 + ( y − yc ry )2 = 1 (0,0) ( x rx )2 + ( y ry )2 = 1 x = xc + rx cosθ y = yc + ry sinθ calculate pixel positions along the elliptical arc throughout one quadrant, then we obtain positions in the remaining three quadrants by symmetry
  • 49.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Mid Point Ellipse
  • 50.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Similar to display raster circle • Input • Ellipse in standard position centred on the origin • Translate and Rotate to orient the Major and Minor axes • The midpoint ellipse method is applied throughout the first quadrant in two parts. • Region I • Region II •rx, ry, (xc, yc) (Slope of curve < − 1) (Slope of curve > − 1) ry rx Slope < − 1 Slope > − 1
  • 51.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Region I • Unit steps in the direction • Slope of the curve less than -1 • • Start position • Step clockwise along the elliptical path in the first quadrant • Shifting from unit steps in to unit steps in when the slope becomes less than • Region II • Unit steps in the y direction • Slop greater than -1 • • Start position • Step counter clockwise along the elliptical path in the first quadrant • Shifting from unit steps in to unit steps in when the slope becomes greater than • Parallel processing x |slope| < 1 (0,ry) x y −1 |slope| > 1 (rx,0) y x −1 Calculate pixel positions in the two regions simultaneously
  • 52.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Sequential Implementation • Start Point • Step along the ellipse path in clockwise order throughout the first quadrant. • • For any point • • • Decision Parameter • • Point lies inside the ellipse • • Point lies on the ellipse • • Point lies outside the ellipse • At each position, the next pixel along the ellipse path is selected • Sign of the ellipse function evaluated at the midpoint between the two candidate pixels. (0,ry) r2 y x2 + r2 x y2 − r2 x r2 y = 0 (xk, yk) r2 y x2 k + r2 x y2 k − r2 x r2 y = ? res = ? if(res < 0) if(res = 0) if(res > 0)
  • 53.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Starting Point • Take unit steps in the direction • Continue till the boundary between region 1 and region 2 • Then take unit steps in the direction over the remainder of the curve in the first quadrant. • At each step, test the value of the slope of the curve. • • • On the boundary • • • Out of region I • (0,ry) x y d dx (r2 y x2 + r2 x y2 − r2 x r2 y ) = 0 dy dx = − 2r2 y x 2r2 x y dy/dx = − 1 2r2 y x = 2r2 x y 2r2 y x > = 2r2 x y Slope
  • 54.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in [Region I] • Previous position • Sampling position • Midpoint between the two candidate pixels • • Evaluating the decision parameterat midpoint • • • • Mid point is inside the ellipse • • • Mid point is on the ellipse • • • Mid point is outside the ellipse • (xk, yk) xk+1 (xk + 1,yk) (xk + 1,yk − 1) Mid Point (xk + 1,yk − 1 2 ) p1k = r2 y (xk + 1)2 + r2 x (yk − 1 2 )2 − r2 x r2 y if (p1k < 0) (xk + 1,yk) if (p1k = 0) (xk + 1,yk − 1) if (p1k > 0) (xk + 1,yk − 1)
  • 55.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in p1k = r2 y (xk + 1)2 + r2 x (yk − 1 2 )2 − r2 x r2 y p1k+1 = r2 y (xk+1 + 1)2 + r2 x (yk+1 − 1 2 )2 − r2 x r2 y p1k+1 = r2 y (xk + 1 + 1)2 + r2 x (yk+1 − 1 2 )2 − r2 x r2 y p1k+1 − p1k = r2 y (xk + 1 + 1)2 + r2 x (yk+1 − 1 2 )2 − r2 x r2 y − r2 y (xk + 1)2 − r2 x (yk − 1 2 )2 + r2 x r2 y p1k+1 − p1k = r2 y ((xk + 1)2 + 1 + 2(xk + 1) − r2 y (x2 k + 1 + 2xk) + r2 x (y2 k+1 + 1 4 − yk+1) − r2 x (y2 k + 1 4 − yk) p1k+1 − p1k = r2 y (x2 k + 1 + 2xk + 1 + 2xk + 2 − x2 k − 1 − 2xk) + r2 x (y2 k+1 + 1 4 − yk+1 − y2 k − 1 4 + yk) p1k+1 − p1k = r2 y {2(xk + 1) + 1} + r2 x (y2 k+1 − y2 k − yk+1 + yk) p1k+1 = p1k + r2 y {2(xk + 1) + 1} + r2 x (y2 k+1 − y2 k − yk+1 + yk)
  • 56.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • • • • • • • p1k+1 = p1k + r2 y {2(xk + 1) + 1} + r2 x (y2 k+1 − y2 k − yk+1 + yk) if (p1k < 0) yk+1 = yk p1k+1 = p1k + 2r2 y xk+1 + 1 + r2 y if (p1k > = 0) yk+1 = yk − 1 p1k+1 = p1k + 2r2 y xk+1 + 1 + r2 y − 2r2 x yk+1
  • 57.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • Initial Point • • • • • • (0,ry) p1k = r2 y (xk + 1)2 + r2 x (yk − 1 2 )2 − r2 x r2 y p10 = r2 y (0 + 1)2 + r2 x (ry − 1 2 )2 − r2 x r2 y p10 = r2 y + r2 x (r2 y + 1 4 − ry) − r2 x r2 y p10 = r2 y + r2 x r2 y + r2 x 4 − r2 x ry − r2 x r2 y p10 = r2 y + r2 x 4 − r2 x ry ⋅ ⋅(0,ry) (0,0) Ist Quadrant
  • 58.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in (0,0) rx ry ⋅ Sample x point Sample y point Slope = -1 Slope < -1 Slope > -1 ⋅⋅⋅ ⋅⋅⋅(xk + 1,yk − 1)(xk, yk − 1) (xk + 1,yk) (xk + 1,yk − 1)
  • 59.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in [Region II] • Previous position • Sampling position • Midpoint between the two candidate pixels • • Evaluating the decision parameter at midpoint • • • • Mid point is inside the ellipse • • • Mid point is on the ellipse • • • Mid point is outside the ellipse • (xk, yk) yk+1 (xk, yk − 1) (xk + 1,yk − 1) Mid Point (xk + 1 2 , yk − 1) p2k = r2 y (xk + 1 2 )2 + r2 x (yk − 1)2 − r2 x r2 y if (p2k < 0) (xk + 1,yk − 1) if (p2k = 0) (xk, yk − 1) if (p2k > 0) (xk, yk − 1)
  • 60.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in p2k = r2 y (xk + 1 2 )2 + r2 x (yk − 1)2 − r2 x r2 y p2k+1 = r2 y (xk+1 + 1 2 )2 + r2 x (yk+1 − 1)2 − r2 x r2 y p2k+1 = r2 y (xk+1 + 1 2 )2 + r2 x (yk − 1 − 1)2 − r2 x r2 y p2k+1 − p2k = r2 y (xk+1 + 1 2 )2 + r2 x (yk − 1 − 1)2 − r2 x r2 y − r2 y (xk + 1 2 )2 − r2 x (yk − 1)2 − r2 x r2 y p2k+1 − p2k = r2 y (x2 k+1 + 1 4 + xk+1) − r2 y (x2 k + 1 4 + xk) + r2 x ((yk − 1)2 + 1 − 2(yk − 1)) − r2 x (y2 k + 1 + 2yk) p2k+1 − p2k = r2 y (x2 k+1 + 1 4 + xk+1 − x2 k − 1 4 − xk) + r2 x (y2 k + 1 − 2yk + 1 − 2yk + 2 − y2 k − 1 + 2yk) p2k+1 − p2k = r2 y (x2 k+1 + xk+1 − x2 k − xk) + r2 x (1 − 2(yk − 1)) p2k+1 = p2k + r2 y (x2 k+1 + xk+1 − x2 k − xk) + r2 x (1 − 2yk+1)
  • 61.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in • • • • • • • p2k+1 = p2k + r2 y (x2 k+1 + xk+1 − x2 k − xk) + r2 x (1 − 2yk+1) if (p2k > 0) xk+1 = xk p2k+1 = p2k − 2r2 x yk+1 + r2 x if (p2k < = 0) xk+1 = xk + 1 p2k+1 = p2k + 2r2 y xk+1 − 2r2 x yk+1 + r2 x
  • 62.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in InitialPoint • Last Point of [Region I] • Let • • (x, y) p2k = r2 y (xk + 1 2 )2 + r2 x (yk − 1)2 − r2 x r2 y p20 = r2 y (x + 1 2 )2 + r2 x (y − 1)2 − r2 x r2 y
  • 63.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in Algorithm
  • 64.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in midPointEllipse (1) (2) (3) , (4) while (5) (6) (rx, ry, xc, yc) (x0, y0) = (0,ry) p10 = r2 y + r2 x 4 − r2 x ry dx = 2r2 y x dy = 2r2 x y (dx < = dy) plot (x, y) if (p1 < 0) x = x + 1 dx = 2r2 y x p1 = p1 + 2r2 y x + r2 y else x = x + 1 y = y − 1 dx = 2r2 y x dy = 2r2 x y p1 = p1 + 2r2 y x − 2r2 x y + r2 y p20 = r2 y (x + 1 2 )2 + r2 x (y − 1)2 − r2 x r2 y while (y > 0) plot (x, y) if (p2 > 0) y = y − 1 dy = 2r2 x y p2 = p2 − 2r2 x y + r2 x else x = x + 1 y = y − 1 dx = 2r2 y x dy = 2r2 x y p2 = p2 + 2r2 y x − 2r2 x y + r2 x
  • 65.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in (x_k,y_k) P (x_k+1, y_k+1) dx dy (0,6) -332 (1,6) 72 764 (1,6) -224 (2,6) 114 768 (2,6) -44 (3,6) 216 768 (3,6) 208 (4,5) 288 640 (4,5) -108 (5,5) 360 640 (5,5) 288 (6,4) 432 512 (6,4) 244 (7,3) 504 384 End of Region 1 midPointEllipse(rx : 8, ry : 6) p10 = r2 y − r2 x ry + 1 4 r2 x (6)2 − (8)2 ⋅ 6 + 1 4 ⋅ (8)2 = − 332 p1 < 0 dx = 2r2 y ⋅ xk+1 dx = 2(6)2 (1) dy = 2r2 x ⋅ yk+1 dy = 2(8)2 (6) p1 = p1 + 2r2 y x + r2 y p1 = − 332 + 72 + (6)2 p14 = p13 + 2r2 y x − 2r2 x y + r2 y p14 = 208 + (2 ⋅ (6)2 ⋅ 4) − (2 ⋅ (8)2 ⋅ 5) + (6)2 p1 > 0
  • 66.
    Mr. Rupesh Mishra| rupeshmishra@sfit.ac.in (x_k,y_k) P (x_k+1, y_k+1) dx dy (6,4) 244 (7,3) 504 384 Start of Region II (7,3) -23 (8,2) 576 256 (8,2) 361 (8,1) 576 128 (8,1) 297 (8,0) - - midPointEllipse(rx : 8, ry : 6) p20 = r2 y (x + 1 2 )2 + r2 x (y − 1)2 − r2 x r2 y (36)2 (7 + 1 2 )2 + (6)2 (3 − 1)2 − (8)2 (6)2 p2 < 0 dx = 2r2 y ⋅ xk+1 dx = 2(6)2 (8) dy = 2r2 x ⋅ yk+1 dy = 2(8)2 (2) p2 = p2 + 2r2 y x − 2r2 x y + r2 x Region II − Start Point (7,3) p2 = − 23 + 576 − 256 + 64 p2 > 0 p2 = p2 − 2r2 x y + r2 x p2 = 361 − 128 + 64