Program to create a cylinder and Parallelepiped by extruding Circle and Quadrilateral respectively. Allow the user to specify the circle and quadrilateral.
chapter 5.pptx: drainage and irrigation engineering
10CSL67 CG LAB PROGRAM 6
1. PROGRAM 6
Program to create a cylinder and Parallelepiped
by extruding Circle and Quadrilateral respectively.
Allow the user to specify the circle and
quadrilateral.
3. Midpoint Circle Algorithm
In the mid-point circle algorithm, we use eight-way
symmetry.
Calculate the points for the top right eighth of a
circle, and then use symmetry to get the rest of the
points.
5. The equation of the circle:
The equation evaluates as follows:
If we choose a point inside a circle, x2+y2<r2
If we choose a point outside a circle, x2+y2>r2
If we choose a point on the circle, x2+y2=r2
222
),( ryxyxfcirc
,0
,0
,0
),( yxfcirc
boundarycircletheinsideis),(if yx
boundarycircleon theis),(if yx
boundarycircletheoutsideis),(if yx
Midpoint Circle Algorithm
6. (xk+1, yk)
(xk+1, yk-1)
(xk, yk)
E
SE
(xk+1, yk- ½ )
Assuming we have just plotted the
pixel at (xk, yk) so we need to choose
between (xk+1,yk) and (xk+1,yk-1)
Our decision variable can be defined
as:
If pk < 0, the pixel at yk is closer to the
circle.
Otherwise yk-1 is closer.
222
)
2
1()1(
)
2
1,1(
ryx
yxfp
kk
kkcirck
Midpoint Circle Algorithm
7. (xk+1, yk)
(xk+1, yk-1)
(xk, yk)
E
SE
(xk+1, yk- ½ )
Let pk=d
dold=F(M)
dold=F(Xk+1,Yk- ½ )
If d<0, choose E
x=x+1 which gives dnew
dnew=(Xk+1)+1, (Yk- ½ )
( d)E = dnew- dold
F(Xk+2, Yk- ½ ) – F(Xk+1, Yk- ½ )
( d)E = 2Xk+3
Midpoint Circle Algorithm
8. (xk+1, yk)
(xk+1, yk-1)
(xk, yk)
E
SE
(xk+1, yk- ½ )
Let pk=d
dold=F(M)
dold=F(Xk+1,Yk- ½ )
If d>=0, choose SE
x=x+1
y=y-1 which gives dnew
dnew=(Xk+1)+1, (Yk- ½)-1
( d)SE = dnew-dold
F(Xk+2, Yk- 3/2) – F(Xk+1, Yk- ½)
( d)SE = 2Xk-2Yk+5
Midpoint Circle Algorithm
11. void plotpixels(GLint h, GLint k, GLint x, GLint y)
{
draw_pixel(x+h,y+k);
draw_pixel(-x+h,y+k);
draw_pixel(x+h,-y+k);
draw_pixel(-x+h,-y+k);
draw_pixel(y+h,x+k);
draw_pixel(-y+h,x+k);
draw_pixel(y+h,-x+k);
draw_pixel(-y+h,-x+k);
}
x and y of the
window
x and y of the
circle