SlideShare a Scribd company logo
PROGRAM 6
Program to create a cylinder and Parallelepiped
by extruding Circle and Quadrilateral respectively.
Allow the user to specify the circle and
quadrilateral.
Output :
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.
Eight-Way Symmetry
(1, 3)
(3, 1)
(3, -1)
(1, -3)(-1, -3)
(-3, -1)
(-3, 1)
(-1, 3)
2
R
Assume x=1, y=3
(x, y)(-x, y)
(-y, x)
(-y,-x)
(y, x)
(y, -x)
(x, -y)(-x, -y)
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
(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
(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
(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
222
)
2
1()1(
)
2
1,1(
ryx
yxfp
kk
kkcirck
For the boundary condition, x=0, y=r
Substitute in the equation
p0=d
d=(0+1)2 + (r- ½ )2 – r2
d = 5/4 – r 1-r
For integer values of pixel coordinates, we
can approximate p0= d =1-r
#include<GL/glut.h>
void draw_pixel(GLint cx, GLint cy)
{
glColor3f(1.0,0.0,0.0);
glBegin(GL_POINTS);
glVertex2i(cx,cy);
glEnd();
}
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
// Midpoint Circle Drawing Algorithm
void Circle_draw(GLint h, GLint k, GLint r)
{
GLint d =1-r, x=0, y=r;
while(y > x)
{
plotpixels(h,k,x,y);
if(d < 0) // choose E, ( d)E = 2Xk+3
d+=2*x+3;
else // choose SE, ( d)SE = 2Xk-2Yk+5
{
d+=2*(x-y)+5;
--y;
}
++x;
}
plotpixels(h,k,x,y);
}
void Cylinder_draw()
{
GLint xc=100, yc=100, r=50, i,n=50;
for(i=0;i<n;i+=3)
Circle_draw(xc,yc+i,r);
}
void parallelepiped(int x1,int x2,int y1,int y2)
{
glColor3f(0.0, 0.0, 1.0);
glBegin(GL_LINE_LOOP);
glVertex2i(x1,y1);
glVertex2i(x2,y1);
glVertex2i(x2,y2);
glVertex2i(x1,y2);
glEnd();
}
void parallelepiped_draw()
{
int x1=200,x2=300,y1=100,y2=175, i, n=40;
for(i=0;i<n;i+=2)
parallelepiped(x1+i,x2+i,y1+i,y2+i);
}
void init(void)
{
glClearColor(1.0,1.0,1.0,0.0);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0.0,400.0,0.0,300.0);
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(1.0,0.0,0.0);
Cylinder_draw();
parallelepiped_draw();
glFlush();
}
void main(int argc, char **argv)
{
glutInit(&argc,argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutInitWindowPosition(50,50);
glutInitWindowSize(400,300);
glutCreateWindow("Cylinder,parallelePiped Disp by Extruding
Circle &Quadrilaterl ");
init();
glutDisplayFunc(display);
glutMainLoop();
}

More Related Content

What's hot

Solution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and ContinuitySolution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and Continuity
Hareem Aslam
 
2.circle
2.circle2.circle
2.circle
SakshiNailwal
 
Solution Manual : Chapter - 01 Functions
Solution Manual : Chapter - 01 FunctionsSolution Manual : Chapter - 01 Functions
Solution Manual : Chapter - 01 Functions
Hareem Aslam
 
Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...
Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...
Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...
Hareem Aslam
 
Hand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th editionHand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th edition
PriSim
 
Sbma 4603 numerical methods Assignment
Sbma 4603 numerical methods AssignmentSbma 4603 numerical methods Assignment
Sbma 4603 numerical methods Assignment
Saidatina Khadijah
 
Tabela completa de derivadas e integrais
Tabela completa de derivadas e integraisTabela completa de derivadas e integrais
Tabela completa de derivadas e integrais
Diego Rodrigues Vaz
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmNeha Kaurav
 
Funciones1
Funciones1Funciones1
Funciones1Ray Mera
 
Leidy rivadeneira deber_1
Leidy rivadeneira deber_1Leidy rivadeneira deber_1
Leidy rivadeneira deber_1
L.R. Rivadeneira
 
Integral table
Integral tableIntegral table
Integral table
Ankitcos0
 
01 derivadas
01   derivadas01   derivadas
01 derivadasklorofila
 
Consolidated.m2-satyabama university
Consolidated.m2-satyabama universityConsolidated.m2-satyabama university
Consolidated.m2-satyabama university
Selvaraj John
 
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2Breno Costa
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
Mani Kanth
 
Tablas integrales
Tablas integralesTablas integrales
Tablas integrales
Paulo0415
 

What's hot (20)

Solution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and ContinuitySolution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and Continuity
 
2.circle
2.circle2.circle
2.circle
 
Solution Manual : Chapter - 01 Functions
Solution Manual : Chapter - 01 FunctionsSolution Manual : Chapter - 01 Functions
Solution Manual : Chapter - 01 Functions
 
Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...
Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...
Solution Manual : Chapter - 07 Exponential, Logarithmic and Inverse Trigonome...
 
Hand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th editionHand book of Howard Anton calculus exercises 8th edition
Hand book of Howard Anton calculus exercises 8th edition
 
Sbma 4603 numerical methods Assignment
Sbma 4603 numerical methods AssignmentSbma 4603 numerical methods Assignment
Sbma 4603 numerical methods Assignment
 
Tabela completa de derivadas e integrais
Tabela completa de derivadas e integraisTabela completa de derivadas e integrais
Tabela completa de derivadas e integrais
 
Mid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing AlgorithmMid-Point Cirle Drawing Algorithm
Mid-Point Cirle Drawing Algorithm
 
Tabla integrales
Tabla integralesTabla integrales
Tabla integrales
 
Funciones1
Funciones1Funciones1
Funciones1
 
Leidy rivadeneira deber_1
Leidy rivadeneira deber_1Leidy rivadeneira deber_1
Leidy rivadeneira deber_1
 
Integral
IntegralIntegral
Integral
 
Basic m4-2-chapter1
Basic m4-2-chapter1Basic m4-2-chapter1
Basic m4-2-chapter1
 
Integral table
Integral tableIntegral table
Integral table
 
Bresenhams
BresenhamsBresenhams
Bresenhams
 
01 derivadas
01   derivadas01   derivadas
01 derivadas
 
Consolidated.m2-satyabama university
Consolidated.m2-satyabama universityConsolidated.m2-satyabama university
Consolidated.m2-satyabama university
 
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2Howard, anton   cálculo ii- um novo horizonte - exercicio resolvidos v2
Howard, anton cálculo ii- um novo horizonte - exercicio resolvidos v2
 
Bresenham's line drawing algorithm
Bresenham's line drawing algorithmBresenham's line drawing algorithm
Bresenham's line drawing algorithm
 
Tablas integrales
Tablas integralesTablas integrales
Tablas integrales
 

Similar to 10CSL67 CG LAB PROGRAM 6

Equation of a Circle in standard and general form
Equation of  a Circle in standard and general formEquation of  a Circle in standard and general form
Equation of a Circle in standard and general form
AraceliLynPalomillo
 
CIRCLES.pptx
CIRCLES.pptxCIRCLES.pptx
CIRCLES.pptx
vannessafaithgobot
 
Circle
CircleCircle
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.ppt
AliZaib71
 
Week_3-Circle.pptx
Week_3-Circle.pptxWeek_3-Circle.pptx
Week_3-Circle.pptx
AndreaDaraug2
 
Circles any centre
Circles any centreCircles any centre
Circles any centre
Shaun Wilson
 
10994479.ppt
10994479.ppt10994479.ppt
10994479.ppt
ALIZAIB KHAN
 
48 circle part 1 of 2
48 circle part 1 of 248 circle part 1 of 2
48 circle part 1 of 2tutulk
 
3. apply distance and midpoint
3.  apply distance and midpoint3.  apply distance and midpoint
3. apply distance and midpoint
Regina McDonald, MA.Ed
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
Mazharul Islam
 
Formulario Geometria Analitica
Formulario Geometria AnaliticaFormulario Geometria Analitica
Formulario Geometria Analitica
Antonio Guasco
 
Unit 3
Unit 3Unit 3
Assignment For Matlab Report Subject Calculus 2
Assignment For Matlab Report Subject  Calculus 2Assignment For Matlab Report Subject  Calculus 2
Assignment For Matlab Report Subject Calculus 2
Laurie Smith
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
HebaEng
 
2.7 more parabolas a&amp; hyperbolas (optional) t
2.7 more parabolas a&amp; hyperbolas (optional) t2.7 more parabolas a&amp; hyperbolas (optional) t
2.7 more parabolas a&amp; hyperbolas (optional) t
math260
 
MA8353 TPDE
MA8353 TPDEMA8353 TPDE
MA8353 TPDE
rmkceteee
 
17 integrals of rational functions x
17 integrals of rational functions x17 integrals of rational functions x
17 integrals of rational functions x
math266
 
Cricle.pptx
Cricle.pptxCricle.pptx

Similar to 10CSL67 CG LAB PROGRAM 6 (20)

Equation of a Circle in standard and general form
Equation of  a Circle in standard and general formEquation of  a Circle in standard and general form
Equation of a Circle in standard and general form
 
CIRCLES.pptx
CIRCLES.pptxCIRCLES.pptx
CIRCLES.pptx
 
Circle
CircleCircle
Circle
 
Computer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.pptComputer_Graphics_circle_drawing_techniq.ppt
Computer_Graphics_circle_drawing_techniq.ppt
 
Week_3-Circle.pptx
Week_3-Circle.pptxWeek_3-Circle.pptx
Week_3-Circle.pptx
 
Circles any centre
Circles any centreCircles any centre
Circles any centre
 
10994479.ppt
10994479.ppt10994479.ppt
10994479.ppt
 
48 circle part 1 of 2
48 circle part 1 of 248 circle part 1 of 2
48 circle part 1 of 2
 
3. apply distance and midpoint
3.  apply distance and midpoint3.  apply distance and midpoint
3. apply distance and midpoint
 
Bresenhamcircle derivation
Bresenhamcircle derivationBresenhamcircle derivation
Bresenhamcircle derivation
 
Formulario Geometria Analitica
Formulario Geometria AnaliticaFormulario Geometria Analitica
Formulario Geometria Analitica
 
Unit 3
Unit 3Unit 3
Unit 3
 
Assignment For Matlab Report Subject Calculus 2
Assignment For Matlab Report Subject  Calculus 2Assignment For Matlab Report Subject  Calculus 2
Assignment For Matlab Report Subject Calculus 2
 
math1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdfmath1مرحلة اولى -compressed.pdf
math1مرحلة اولى -compressed.pdf
 
2.7 more parabolas a&amp; hyperbolas (optional) t
2.7 more parabolas a&amp; hyperbolas (optional) t2.7 more parabolas a&amp; hyperbolas (optional) t
2.7 more parabolas a&amp; hyperbolas (optional) t
 
MA8353 TPDE
MA8353 TPDEMA8353 TPDE
MA8353 TPDE
 
Maths05
Maths05Maths05
Maths05
 
Line circle draw
Line circle drawLine circle draw
Line circle draw
 
17 integrals of rational functions x
17 integrals of rational functions x17 integrals of rational functions x
17 integrals of rational functions x
 
Cricle.pptx
Cricle.pptxCricle.pptx
Cricle.pptx
 

More from Vanishree Arun

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 910CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 9
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 710CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 410CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 4
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 2
 10CSL67 CG LAB PROGRAM 2 10CSL67 CG LAB PROGRAM 2
10CSL67 CG LAB PROGRAM 2
Vanishree Arun
 
10CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 110CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 1
Vanishree Arun
 

More from Vanishree Arun (9)

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10
 
10CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 910CSL67 CG LAB PROGRAM 9
10CSL67 CG LAB PROGRAM 9
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
 
10CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 710CSL67 CG LAB PROGRAM 7
10CSL67 CG LAB PROGRAM 7
 
10CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 510CSL67 CG LAB PROGRAM 5
10CSL67 CG LAB PROGRAM 5
 
10CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 410CSL67 CG LAB PROGRAM 4
10CSL67 CG LAB PROGRAM 4
 
10CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 310CSL67 CG LAB PROGRAM 3
10CSL67 CG LAB PROGRAM 3
 
10CSL67 CG LAB PROGRAM 2
 10CSL67 CG LAB PROGRAM 2 10CSL67 CG LAB PROGRAM 2
10CSL67 CG LAB PROGRAM 2
 
10CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 110CSL67 CG LAB PROGRAM 1
10CSL67 CG LAB PROGRAM 1
 

Recently uploaded

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
Kamal Acharya
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
ClaraZara1
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
BrazilAccount1
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
veerababupersonal22
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
MdTanvirMahtab2
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
karthi keyan
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
gestioneergodomus
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
gdsczhcet
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
AJAYKUMARPUND1
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
Intella Parts
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
Kerry Sado
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
Amil Baba Dawood bangali
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Dr.Costas Sachpazis
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
AmarGB2
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
Vijay Dialani, PhD
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
symbo111
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
ongomchris
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
JoytuBarua2
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
WENKENLI1
 

Recently uploaded (20)

Standard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - NeometrixStandard Reomte Control Interface - Neometrix
Standard Reomte Control Interface - Neometrix
 
Student information management system project report ii.pdf
Student information management system project report ii.pdfStudent information management system project report ii.pdf
Student information management system project report ii.pdf
 
6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)6th International Conference on Machine Learning & Applications (CMLA 2024)
6th International Conference on Machine Learning & Applications (CMLA 2024)
 
AP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specificAP LAB PPT.pdf ap lab ppt no title specific
AP LAB PPT.pdf ap lab ppt no title specific
 
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERSCW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
CW RADAR, FMCW RADAR, FMCW ALTIMETER, AND THEIR PARAMETERS
 
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)
 
CME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional ElectiveCME397 Surface Engineering- Professional Elective
CME397 Surface Engineering- Professional Elective
 
DfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributionsDfMAy 2024 - key insights and contributions
DfMAy 2024 - key insights and contributions
 
Gen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdfGen AI Study Jams _ For the GDSC Leads in India.pdf
Gen AI Study Jams _ For the GDSC Leads in India.pdf
 
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
Pile Foundation by Venkatesh Taduvai (Sub Geotechnical Engineering II)-conver...
 
Forklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella PartsForklift Classes Overview by Intella Parts
Forklift Classes Overview by Intella Parts
 
Hierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power SystemHierarchical Digital Twin of a Naval Power System
Hierarchical Digital Twin of a Naval Power System
 
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
NO1 Uk best vashikaran specialist in delhi vashikaran baba near me online vas...
 
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
Sachpazis:Terzaghi Bearing Capacity Estimation in simple terms with Calculati...
 
Investor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptxInvestor-Presentation-Q1FY2024 investor presentation document.pptx
Investor-Presentation-Q1FY2024 investor presentation document.pptx
 
ML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptxML for identifying fraud using open blockchain data.pptx
ML for identifying fraud using open blockchain data.pptx
 
Building Electrical System Design & Installation
Building Electrical System Design & InstallationBuilding Electrical System Design & Installation
Building Electrical System Design & Installation
 
space technology lecture notes on satellite
space technology lecture notes on satellitespace technology lecture notes on satellite
space technology lecture notes on satellite
 
Planning Of Procurement o different goods and services
Planning Of Procurement o different goods and servicesPlanning Of Procurement o different goods and services
Planning Of Procurement o different goods and services
 
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdfGoverning Equations for Fundamental Aerodynamics_Anderson2010.pdf
Governing Equations for Fundamental Aerodynamics_Anderson2010.pdf
 

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.
  • 4. Eight-Way Symmetry (1, 3) (3, 1) (3, -1) (1, -3)(-1, -3) (-3, -1) (-3, 1) (-1, 3) 2 R Assume x=1, y=3 (x, y)(-x, y) (-y, x) (-y,-x) (y, x) (y, -x) (x, -y)(-x, -y)
  • 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
  • 9. 222 ) 2 1()1( ) 2 1,1( ryx yxfp kk kkcirck For the boundary condition, x=0, y=r Substitute in the equation p0=d d=(0+1)2 + (r- ½ )2 – r2 d = 5/4 – r 1-r For integer values of pixel coordinates, we can approximate p0= d =1-r
  • 10. #include<GL/glut.h> void draw_pixel(GLint cx, GLint cy) { glColor3f(1.0,0.0,0.0); glBegin(GL_POINTS); glVertex2i(cx,cy); glEnd(); }
  • 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
  • 12. // Midpoint Circle Drawing Algorithm void Circle_draw(GLint h, GLint k, GLint r) { GLint d =1-r, x=0, y=r; while(y > x) { plotpixels(h,k,x,y); if(d < 0) // choose E, ( d)E = 2Xk+3 d+=2*x+3; else // choose SE, ( d)SE = 2Xk-2Yk+5 { d+=2*(x-y)+5; --y; } ++x; } plotpixels(h,k,x,y); }
  • 13. void Cylinder_draw() { GLint xc=100, yc=100, r=50, i,n=50; for(i=0;i<n;i+=3) Circle_draw(xc,yc+i,r); } void parallelepiped(int x1,int x2,int y1,int y2) { glColor3f(0.0, 0.0, 1.0); glBegin(GL_LINE_LOOP); glVertex2i(x1,y1); glVertex2i(x2,y1); glVertex2i(x2,y2); glVertex2i(x1,y2); glEnd(); }
  • 14. void parallelepiped_draw() { int x1=200,x2=300,y1=100,y2=175, i, n=40; for(i=0;i<n;i+=2) parallelepiped(x1+i,x2+i,y1+i,y2+i); } void init(void) { glClearColor(1.0,1.0,1.0,0.0); glMatrixMode(GL_PROJECTION); gluOrtho2D(0.0,400.0,0.0,300.0); }
  • 16. void main(int argc, char **argv) { glutInit(&argc,argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB); glutInitWindowPosition(50,50); glutInitWindowSize(400,300); glutCreateWindow("Cylinder,parallelePiped Disp by Extruding Circle &Quadrilaterl "); init(); glutDisplayFunc(display); glutMainLoop(); }