SlideShare ist ein Scribd-Unternehmen logo
1 von 11
Downloaden Sie, um offline zu lesen
PROGRAM 1
Program to recursively subdivide a tetrahedron to
form 3D Sierpinski gasket. The number of recursive
steps is to be specified by the user.
3D Sierpinski gasket
• A fractal which can be constructed by
a recursive procedure; at each step a
triangle is divided into four new
triangles.
• The central triangle is removed and
each of the other three treated as the
original was, and so on, creating an
infinite regression in a finite space.
• Origin:
1970s: named after Wacław
Sierpiński (1882–1969), Polish
mathematician
• Application :
Fractal geometry
No. of divisions : 0
No. of divisions : 1
V0(0,0,10)
V1(0,10,-10)
V2(-10,-10,-10) V3(10,-10,-10)
-X +X
-Y
+Y
No. of divisions : 1
No. of divisions : 3
#include <stdio.h>
#include <GL/glut.h>
typedef float point[3];
/* initial tetrahedron */
point v[4] = { {0.0, 0.0, 10.0}, {0.0, 10.0, -10.0},
{-10.0, -10.0, -10.0}, {10.0, -10.0, -10.0}
};
int n;
/* display one triangle */
void triangle( point a, point b, point c)
{ glBegin(GL_POLYGON);
glVertex3fv(a);
glVertex3fv(b);
glVertex3fv(c);
glEnd();
}
/* triangle subdivision */
void divide_triangle(point a, point b, point c, int m)
{
point p1, p2, p3;
int i;
if(m>0)
{
for(i=0; i<3; i++) p1[i]=(a[i]+b[i])/2;
for(i=0; i<3; i++) p2[i]=(a[i]+c[i])/2;
for(i=0; i<3; i++) p3[i]=(b[i]+c[i])/2;
divide_triangle(a, p1, p2, m-1);
divide_triangle(c, p2, p3, m-1);
divide_triangle(b, p3, p1, m-1);
}
else
triangle(a,b,c); /* draw triangle at end of recursion */
}
/* Apply triangle subdivision to faces of tetrahedron */
void tetrahedron( int m)
{
glColor3f(1.0,0.0,0.0);
divide_triangle(v[0], v[1], v[2], m);
glColor3f(0.0,1.0,0.0);
divide_triangle(v[3], v[2], v[1], m);
glColor3f(0.0,0.0,1.0);
divide_triangle(v[0], v[3], v[1], m);
glColor3f(0.0,0.0,0.0);
divide_triangle(v[0], v[2], v[3], m);
}
void display()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// to reset the buffer and for hidden surface removal
glLoadIdentity();
tetrahedron(n);
glFlush();
}
void myReshape(int w, int h)
{
glViewport(0, 0, w, h);
glMatrixMode(GL_PROJECTION);
// matrix mode – defines CTM, GL_PROJECTION to view in ortho
glLoadIdentity(); // identity matrix resets the matrix to its default state
if (w <= h)
glOrtho(-12.0, 12.0, -12.0 * (GLfloat) h / (GLfloat) w, 12.0 * (GLfloat) h / (GLfloat) w, -12.0, 12.0);
else
glOrtho(-12.0 * (GLfloat) w / (GLfloat) h, 12.0 * (GLfloat) w / (GLfloat) h, -12.0, 12.0, -12.0, 12.0);
glMatrixMode(GL_MODELVIEW); // transformations done in model view
glutPostRedisplay();
}
void main(int argc, char **argv)
{
printf(" No. of Divisions ? ");
scanf("%d",&n);
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH);
/* This is to view the behind triangle */
glutInitWindowSize(500, 500);
glutCreateWindow("3D Gasket");
glClearColor (1.0, 1.0, 1.0, 1.0);
glutReshapeFunc(myReshape);
glutDisplayFunc(display);
glEnable(GL_DEPTH_TEST); // enable the hidden surface
glutMainLoop();
}

Weitere ähnliche Inhalte

Was ist angesagt?

حساب النهايات جبرياً
حساب النهايات جبرياًحساب النهايات جبرياً
حساب النهايات جبرياًsdthgpr
 
79ecb3d9 65f4-4161-b97d-63711df5d6c5
79ecb3d9 65f4-4161-b97d-63711df5d6c579ecb3d9 65f4-4161-b97d-63711df5d6c5
79ecb3d9 65f4-4161-b97d-63711df5d6c5spoider
 
Calc224FinalExamReview
Calc224FinalExamReviewCalc224FinalExamReview
Calc224FinalExamReviewTori Peña
 
Bicubic interpolation codes
Bicubic interpolation codesBicubic interpolation codes
Bicubic interpolation codesmmjalbiaty
 
All three forms (variety)
All three forms (variety)All three forms (variety)
All three forms (variety)MsKendall
 
Fractal Rendering in Developer C++ - 2012-11-06
Fractal Rendering in Developer C++ - 2012-11-06Fractal Rendering in Developer C++ - 2012-11-06
Fractal Rendering in Developer C++ - 2012-11-06Aritra Sarkar
 
Giaotrinhmaplenguyenchanhtu1
Giaotrinhmaplenguyenchanhtu1Giaotrinhmaplenguyenchanhtu1
Giaotrinhmaplenguyenchanhtu1Thuy Lan
 

Was ist angesagt? (19)

Rolle's theorem
Rolle's theorem Rolle's theorem
Rolle's theorem
 
New day 8 examples
New day 8 examplesNew day 8 examples
New day 8 examples
 
حساب النهايات جبرياً
حساب النهايات جبرياًحساب النهايات جبرياً
حساب النهايات جبرياً
 
79ecb3d9 65f4-4161-b97d-63711df5d6c5
79ecb3d9 65f4-4161-b97d-63711df5d6c579ecb3d9 65f4-4161-b97d-63711df5d6c5
79ecb3d9 65f4-4161-b97d-63711df5d6c5
 
Calc224FinalExamReview
Calc224FinalExamReviewCalc224FinalExamReview
Calc224FinalExamReview
 
Gradient
GradientGradient
Gradient
 
Hw #2
Hw #2Hw #2
Hw #2
 
MATHS SYMBOLS - #1 - EXPONENTIALS and THEIR PROPERTIES
MATHS SYMBOLS - #1 - EXPONENTIALS and THEIR PROPERTIESMATHS SYMBOLS - #1 - EXPONENTIALS and THEIR PROPERTIES
MATHS SYMBOLS - #1 - EXPONENTIALS and THEIR PROPERTIES
 
Bicubic interpolation codes
Bicubic interpolation codesBicubic interpolation codes
Bicubic interpolation codes
 
Gp
GpGp
Gp
 
All three forms (variety)
All three forms (variety)All three forms (variety)
All three forms (variety)
 
Fractal Rendering in Developer C++ - 2012-11-06
Fractal Rendering in Developer C++ - 2012-11-06Fractal Rendering in Developer C++ - 2012-11-06
Fractal Rendering in Developer C++ - 2012-11-06
 
Figures
FiguresFigures
Figures
 
Special factor patterns
Special factor patternsSpecial factor patterns
Special factor patterns
 
201707 SER332 Lecture 17
201707 SER332 Lecture 17   201707 SER332 Lecture 17
201707 SER332 Lecture 17
 
Htdp27.key
Htdp27.keyHtdp27.key
Htdp27.key
 
Notes 10-5
Notes 10-5Notes 10-5
Notes 10-5
 
Factoring
FactoringFactoring
Factoring
 
Giaotrinhmaplenguyenchanhtu1
Giaotrinhmaplenguyenchanhtu1Giaotrinhmaplenguyenchanhtu1
Giaotrinhmaplenguyenchanhtu1
 

Ähnlich wie 10CSL67 CG LAB PROGRAM 1

Fourier series example
Fourier series exampleFourier series example
Fourier series exampleAbi finni
 
Delaunay triangulation from 2-d delaunay to 3-d delaunay
Delaunay triangulation   from 2-d delaunay to 3-d delaunayDelaunay triangulation   from 2-d delaunay to 3-d delaunay
Delaunay triangulation from 2-d delaunay to 3-d delaunaygreentask
 
TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...
TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...
TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...Two Sigma
 
TM plane wave scattering from finite rectangular grooves in a conducting plan...
TM plane wave scattering from finite rectangular grooves in a conducting plan...TM plane wave scattering from finite rectangular grooves in a conducting plan...
TM plane wave scattering from finite rectangular grooves in a conducting plan...Yong Heui Cho
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingMark Kilgard
 
CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics PipelineMark Kilgard
 
Mm chap08 -_lossy_compression_algorithms
Mm chap08 -_lossy_compression_algorithmsMm chap08 -_lossy_compression_algorithms
Mm chap08 -_lossy_compression_algorithmsEellekwameowusu
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfcontact41
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksJinTaek Seo
 
Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)
Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)
Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)Kyuseok Hwang(allosha)
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3Droxlu
 
Butterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite NetworksButterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite NetworksSeyed-Vahid Sanei-Mehri
 
TAO Fayan_X-Ray and MIP volume rendering
TAO Fayan_X-Ray and MIP volume renderingTAO Fayan_X-Ray and MIP volume rendering
TAO Fayan_X-Ray and MIP volume renderingFayan TAO
 

Ähnlich wie 10CSL67 CG LAB PROGRAM 1 (20)

Fourier series example
Fourier series exampleFourier series example
Fourier series example
 
testpang
testpangtestpang
testpang
 
Delaunay triangulation from 2-d delaunay to 3-d delaunay
Delaunay triangulation   from 2-d delaunay to 3-d delaunayDelaunay triangulation   from 2-d delaunay to 3-d delaunay
Delaunay triangulation from 2-d delaunay to 3-d delaunay
 
DCT
DCTDCT
DCT
 
DCT
DCTDCT
DCT
 
DCT
DCTDCT
DCT
 
TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...
TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...
TRIEST: Counting Local and Global Triangles in Fully-Dynamic Streams with Fix...
 
TM plane wave scattering from finite rectangular grooves in a conducting plan...
TM plane wave scattering from finite rectangular grooves in a conducting plan...TM plane wave scattering from finite rectangular grooves in a conducting plan...
TM plane wave scattering from finite rectangular grooves in a conducting plan...
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
CS 354 More Graphics Pipeline
CS 354 More Graphics PipelineCS 354 More Graphics Pipeline
CS 354 More Graphics Pipeline
 
Mm chap08 -_lossy_compression_algorithms
Mm chap08 -_lossy_compression_algorithmsMm chap08 -_lossy_compression_algorithms
Mm chap08 -_lossy_compression_algorithms
 
Im looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdfIm looking for coding help I dont really need this to be explained.pdf
Im looking for coding help I dont really need this to be explained.pdf
 
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeksBeginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
Beginning direct3d gameprogramming06_firststepstoanimation_20161115_jintaeks
 
5th Semester Electronic and Communication Engineering (2013-June) Question Pa...
5th Semester Electronic and Communication Engineering (2013-June) Question Pa...5th Semester Electronic and Communication Engineering (2013-June) Question Pa...
5th Semester Electronic and Communication Engineering (2013-June) Question Pa...
 
2013-June: 5th Semester E & C Question Papers
2013-June: 5th Semester E & C Question Papers2013-June: 5th Semester E & C Question Papers
2013-June: 5th Semester E & C Question Papers
 
Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)
Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)
Shaderx5 2.6normalmappingwithoutprecomputedtangents 130318 (1)
 
openFrameworks 007 - 3D
openFrameworks 007 - 3DopenFrameworks 007 - 3D
openFrameworks 007 - 3D
 
Butterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite NetworksButterfly Counting in Bipartite Networks
Butterfly Counting in Bipartite Networks
 
Finger detection
Finger detectionFinger detection
Finger detection
 
TAO Fayan_X-Ray and MIP volume rendering
TAO Fayan_X-Ray and MIP volume renderingTAO Fayan_X-Ray and MIP volume rendering
TAO Fayan_X-Ray and MIP volume rendering
 

Mehr von Vanishree Arun

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

Mehr von 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 6
10CSL67 CG LAB PROGRAM 610CSL67 CG LAB PROGRAM 6
10CSL67 CG LAB PROGRAM 6
 
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
 

Kürzlich hochgeladen

NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...Amil baba
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueBhangaleSonal
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...drmkjayanthikannan
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadhamedmustafa094
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startQuintin Balsdon
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilVinayVitekari
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationBhangaleSonal
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxJuliansyahHarahap1
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Arindam Chakraborty, Ph.D., P.E. (CA, TX)
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network DevicesChandrakantDivate1
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"mphochane1998
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwaitjaanualu31
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptNANDHAKUMARA10
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiessarkmank1
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdfKamal Acharya
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxSCMS School of Architecture
 

Kürzlich hochgeladen (20)

NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
NO1 Top No1 Amil Baba In Azad Kashmir, Kashmir Black Magic Specialist Expert ...
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
kiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal loadkiln thermal load.pptx kiln tgermal load
kiln thermal load.pptx kiln tgermal load
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Moment Distribution Method For Btech Civil
Moment Distribution Method For Btech CivilMoment Distribution Method For Btech Civil
Moment Distribution Method For Btech Civil
 
DC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equationDC MACHINE-Motoring and generation, Armature circuit equation
DC MACHINE-Motoring and generation, Armature circuit equation
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
Navigating Complexity: The Role of Trusted Partners and VIAS3D in Dassault Sy...
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
Computer Networks Basics of Network Devices
Computer Networks  Basics of Network DevicesComputer Networks  Basics of Network Devices
Computer Networks Basics of Network Devices
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills KuwaitKuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
Kuwait City MTP kit ((+919101817206)) Buy Abortion Pills Kuwait
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptxS1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
S1S2 B.Arch MGU - HOA1&2 Module 3 -Temple Architecture of Kerala.pptx
 

10CSL67 CG LAB PROGRAM 1

  • 1. PROGRAM 1 Program to recursively subdivide a tetrahedron to form 3D Sierpinski gasket. The number of recursive steps is to be specified by the user.
  • 2. 3D Sierpinski gasket • A fractal which can be constructed by a recursive procedure; at each step a triangle is divided into four new triangles. • The central triangle is removed and each of the other three treated as the original was, and so on, creating an infinite regression in a finite space. • Origin: 1970s: named after Wacław Sierpiński (1882–1969), Polish mathematician • Application : Fractal geometry
  • 7. #include <stdio.h> #include <GL/glut.h> typedef float point[3]; /* initial tetrahedron */ point v[4] = { {0.0, 0.0, 10.0}, {0.0, 10.0, -10.0}, {-10.0, -10.0, -10.0}, {10.0, -10.0, -10.0} }; int n; /* display one triangle */ void triangle( point a, point b, point c) { glBegin(GL_POLYGON); glVertex3fv(a); glVertex3fv(b); glVertex3fv(c); glEnd(); }
  • 8. /* triangle subdivision */ void divide_triangle(point a, point b, point c, int m) { point p1, p2, p3; int i; if(m>0) { for(i=0; i<3; i++) p1[i]=(a[i]+b[i])/2; for(i=0; i<3; i++) p2[i]=(a[i]+c[i])/2; for(i=0; i<3; i++) p3[i]=(b[i]+c[i])/2; divide_triangle(a, p1, p2, m-1); divide_triangle(c, p2, p3, m-1); divide_triangle(b, p3, p1, m-1); } else triangle(a,b,c); /* draw triangle at end of recursion */ }
  • 9. /* Apply triangle subdivision to faces of tetrahedron */ void tetrahedron( int m) { glColor3f(1.0,0.0,0.0); divide_triangle(v[0], v[1], v[2], m); glColor3f(0.0,1.0,0.0); divide_triangle(v[3], v[2], v[1], m); glColor3f(0.0,0.0,1.0); divide_triangle(v[0], v[3], v[1], m); glColor3f(0.0,0.0,0.0); divide_triangle(v[0], v[2], v[3], m); }
  • 10. void display() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // to reset the buffer and for hidden surface removal glLoadIdentity(); tetrahedron(n); glFlush(); } void myReshape(int w, int h) { glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); // matrix mode – defines CTM, GL_PROJECTION to view in ortho glLoadIdentity(); // identity matrix resets the matrix to its default state if (w <= h) glOrtho(-12.0, 12.0, -12.0 * (GLfloat) h / (GLfloat) w, 12.0 * (GLfloat) h / (GLfloat) w, -12.0, 12.0); else glOrtho(-12.0 * (GLfloat) w / (GLfloat) h, 12.0 * (GLfloat) w / (GLfloat) h, -12.0, 12.0, -12.0, 12.0); glMatrixMode(GL_MODELVIEW); // transformations done in model view glutPostRedisplay(); }
  • 11. void main(int argc, char **argv) { printf(" No. of Divisions ? "); scanf("%d",&n); glutInit(&argc, argv); glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH); /* This is to view the behind triangle */ glutInitWindowSize(500, 500); glutCreateWindow("3D Gasket"); glClearColor (1.0, 1.0, 1.0, 1.0); glutReshapeFunc(myReshape); glutDisplayFunc(display); glEnable(GL_DEPTH_TEST); // enable the hidden surface glutMainLoop(); }