Upcoming SlideShare
×

# Computer graphics

2,449 views

Published on

CS2405

Published in: Education
1 Like
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

Views
Total views
2,449
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
140
0
Likes
1
Embeds 0
No embeds

No notes for slide

### Computer graphics

1. 1. 44210205028 DATE: DDA LINE DRAWING ALGORITHM EX NO: 1 (a) AIM: To implement DDA Line Drawing Algorithm using C. Functions used: Line() :- The function line() is used to draw a line from(x1,y1) to (x2,y2) Syntax :- line (x1,y1,x2,y2) initgraph() :- This function takes thee arguments and they are i). The video driver to be used (gd). ii).The graphics mode (gm). iii).The path name. Syntax:- Initgraph(gd,gm,path) ALGORITHM: Step 1: Start Step 2: Get the values of the end points as(x1, y1) &(x2, y2) Step 3: Assign ax,ab,ya,yb Step 4: Compute dx=xb-xa Step 5: Compute dy=yb-ya Step 6: Assign dx=xb-xa,dsy=yb-ya Step 7: If dy>dx then interchange the values of dx and dy and assign exch=1 Step 8: Compute xinc=dx/steps & yinc=dy/steps,x=xa,y=ya Step 9: Put a pixel on(x,y) Step 14: Stop
2. 2. 44210205028 PROGRAM: #include "stdio.h" #include "conio.h" #include "math.h" #include "graphics.h" main() { int gd=DETECT,gm; int xa,xb,ya,yb; int dx,dy,steps,k,xinc,yinc,x,y; initgraph(&gd,&gm,"c:tcbgi"); printf("Enter the two left end pixel points(xa,ya):n"); scanf("%d%d",&xa,&ya); printf("Enter the two Right end pixel points(xb,yb):n"); scanf("%d%d",&xb,&yb); dx=xb-xa; dy=yb-ya; if(abs(dx)>abs(dy)) steps=abs(dx); else steps=abs(dy); xinc=dx/steps; yinc=dy/steps; x=xa; y=ya; putpixel(x,y,6); for(k=1;k<=steps;k++) { x=x+xinc;
3. 3. 44210205028 y=y+yinc; putpixel(x,y,6); } getch(); return(0); } OUTPUT Enter The Two Left Endpoints(xa,ya) : 234 124 Enter The Two Right Endpoints(xb,yb) : 578 321 RESULT: Thus DDA Line Drawing Algorithm was implemented using C .
4. 4. 44210205028 DATE: BRESENHAM’S LINE DRAWING ALGORITHM EX NO: 1(b) AIM: To implement Bresenham’s line drawing Algorithm for drawing lines. Functions used: Line() :- The function line() is used to draw a line from(x1,y1)to (x2,y2) Syntax: line (x1,y1,x2,y2) initgraph() :- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).The path name. Syntax: Initgraph(gd,gm,path) ALGORITHM: Step1: Include the graphics header file and obtain graphics mode and driver. Step2: Get the co-ordinates of two end points of a line (x1,y1) & (x2,y2) and store left end point in (x1,y1). Step3: Load (x1,y1) into frame buffer that means plot the first point. Step4: Calculate constants dx,dy,2dy,2dy-2dx and obtain value for decision parameter p=2dy-dx. Step5: At each x along the line perform the test if p<0, next point to plot is (x+1,y) and p+1=p+2dy otherwise (x+1,y+1) & p+1=p+2dy-2dx Step6: Repeat steps dx times. Step7: Display a line.
5. 5. 44210205028 PROGRAM: #include "stdio.h" #include "conio.h" #include "math.h" #include "graphics.h" main() { int gd=DETECT,gm; int xa,xb,ya,yb; int dx,dy,x,y,xend,p; initgraph(&gd,&gm,"c:tcbgi"); printf("Enter The Two Left Endpoints(xa,ya):n"); scanf("%d%d",&xa,&ya); printf("Enter The Two Right Endpoints(xb,yb):n"); scanf("%d%d",&xb,&yb); dx=abs(xa-xb); dy=abs(ya-yb); p=2*dy-dx; if(xa>xb) { x=xb; y=yb; xend=xa; } else { x=xa; y=ya; xend=xb; } putpixel(x,y,6);
6. 6. 44210205028 while(x<xend) { x=x+1; if(p<0) { p=p+2*dy; } else { y=y+1; p=p+2*(dy-dx); } putpixel(x,y,6); } getch(); return(0); } OUTPUT: Enter The Two Left Endpoints(xa,ya): 234 124 Enter The Two Right Endpoints(xb,yb): 578 321 RESULT: Thus Bresenham’s line drawing Algorithm Algorithm was implemented using C.
7. 7. 44210205028 DATE: BRESENHAM’S CIRCLE DRAWING ALGORITHM EX NO: 1(c) AIM: To implement Bresenham’s circle drawing algorithm using C. Functions used: Circle() :- The function circle() is used to draw a circle using(x,y) as centre point. Syntax:- circle (x,y,radius) initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM:
8. 8. 44210205028 Step1: Include the graphics header file and obtain graphics mode and driver. Step 2: Get the center point (a,b)and radius r of the circle. Step 3: Initialize the variables and decision parameter as,x=0;y=r;p=1-r; Step 4: If (p<0)then the next point along the circle is (x+1,y) and p=p+2*x+1; Else the next point along the circle is (x=1,y-1) and p=p+2*(x-y)+1; Step 5: Repeat step4 until x<y. Step 6: Plot the pixel to display the circle using put pixel function. Step 7: Display the circle PROGRAM: #include "stdio.h" #include "conio.h" #include "math.h" #include "graphics.h" main() { int gd=DETECT,gm; int xcenter,ycenter,radius; int p,x,y; initgraph(&gd,&gm,"c:tcbgi"); x=0; printf("Enter The Radius Value:n"); scanf("%d",&radius); y=radius; printf("Enter The xcenter and ycenter Values:n"); scanf("%d%d",&xcenter,&ycenter); plotpoints(xcenter,ycenter,x,y); p=1-radius; while(x<y) {
9. 9. 44210205028 if(p<0) x=x+1; else { x=x+1; y=y-1; } if(p<0) p=p+2*x+1; else p=p+2*(x-y)+1; plotpoints(xcenter,ycenter,x,y); } getch(); return(0); } int plotpoints(int xcenter,int ycenter,int x,int y) { putpixel(xcenter+x,ycenter+y,1); putpixel(xcenter-x,ycenter+y,1); putpixel(xcenter+x,ycenter-y,1); putpixel(xcenter-x,ycenter-y,1); putpixel(xcenter+y,ycenter+x,1); putpixel(xcenter-y,ycenter+x,1); putpixel(xcenter+y,ycenter-x,1); putpixel(xcenter-y,ycenter-x,1); } OUTPUT
10. 10. 44210205028 Enter the Radius Value: 80 Enter The xcenter and ycenter Values :230 260 RESULT: Thus Bresenham’s circle drawing Algorithm was implemented using C. DATE:
11. 11. 44210205028 BRESENHAM’S ELLIPSE DRAWING ALGORITHM EX NO: 1(d) AIM: To implement Bresenham’s ellipse drawing algorithm using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM:
12. 12. 44210205028 Step1: Include the graphics header file and obtain graphics mode and driver. Step 2.Input rx,ry and ellipse center(xc,yc) and obtain the first point on an ellipse centered at origin as (x0,y0)=(0,ry). Step 3.Calculate the initial value of the decision parameter in region 1 as p10= ry2- rx2 ry+(1/4)rx2. Step 4.At each xk position in region 1,starting at k=0,perform the following text: a) If p1k<0, the next point along the ellipse centered on (0,0) is (xk+1,yk) and p1k+1=pk+2 ry2 xk+1+ ry2. b) Otherwise, the next point along the ellipse is (xk+1,yk-1) and p1k+1=p1k+2 ry2 xk+1-2 ry2yk+1+ ry2 with 2 ry2 xk+1=2 ry2xk+2ry2,2rx2 yk+1=2rx2yk-2rx2. Step 5. Calculate the initial value of the decision parameter in region 2 using the last point (x0,y0) calculated in region 1 as p20=ry2(x0+(1/2))2+ rx2(y0-1)2- rx2 ry2 Step 6. At each yk position in region2, starting at k=0,perform the following test: a) If p2k>0, the next point along the ellipse centered on (0,0) is (xk,yk-1) andp2 k+1=p2 k-2rx2 y k+1+ rx2 b) Otherwise, the next point along the ellipse is (xk+1,yk-1) & p2k+1=p2 k+2 ry2 xk+1-2 rx2yk+1+ rx2 using the same incremental calculations for x and y as in region 1. Step 7. Repeat the steps for region 1 until 2 ry2>=2 rx2y. Step 8. Plot the pixel to display the ellipse using put pixel function. PROGRAM: #include "stdio.h"
13. 13. 44210205028 #include "conio.h" #include "math.h" #include "graphics.h" main() { int gd=DETECT,gm; int xcenter,ycenter,rx,ry; int p,x,y,px,py,rx1,ry1,rx2,ry2; initgraph(&gd,&gm,"c:tcbgi"); printf("Enter The Radius Value:n"); scanf("%d%d",&rx,&ry); printf("Enter The xcenter and ycenter Values:n"); scanf("%d%d",&xcenter,&ycenter); ry1=ry*ry; rx1=rx*rx; ry2=2*ry1; rx2=2*rx1; /* REGION 1 */ x=0; y=ry; plotpoints(xcenter,ycenter,x,y); p=(ry1-rx1*ry+(0.25*rx1)); px=0; py=rx2*y; while(px<py) { x=x+1; px=px+ry2; if(p>=0) y=y-1;
14. 14. 44210205028 py=py-rx2; if(p<0) p=p+ry1+px; else p=p+ry1+px-py; plotpoints(xcenter,ycenter,x,y); /* REGION 2*/ p=(ry1*(x+0.5)*(x+0.5)+rx1*(y-1)*(y-1)-rx1*ry1); while(y>0) { y=y-1; py=py-rx2; if(p<=0) { x=x+1; px=px+ry2; } if(p>0) p=p+rx1-py; else p=p+rx1-py+px; plotpoints(xcenter,ycenter,x,y); } } getch(); return(0); } int plotpoints(int xcenter,int ycenter,int x,int y) { putpixel(xcenter+x,ycenter+y,6); putpixel(xcenter-x,ycenter+y,6); putpixel(xcenter+x,ycenter-y,6);
15. 15. 44210205028 putpixel(xcenter-x,ycenter-y,6); OUTPUT Enter The Radius Value(Rx,Ry) :10 30 Enter The xcenter and ycenter Values :300 150 RESULT: Thus Bresenham’s ellipse drawing Algorithm was implemented using C. DATE:
16. 16. 44210205028 IMPLEMENTATION OF LINE, CIRCLE, ELLIPSE EX NO: 2 ATTRIBUTES AIM: To implement the different attributes of line, circle, ellipse using C. ALGORITHM: Step1:-Start the program for line, circle, ellipse type Step2:-Include the necessary package Step3:-Declare the line type in lname and fill type in fname character Step4:-Using setline style and line function to draw the different line function Step5:-Using ellipse function to draw the different circle, ellipse function Step6:-Finally terminate the function PROGRAM: #include <graphics.h>
17. 17. 44210205028 #include <stdlib.h> #include <string.h> #include <stdio.h> #include <conio.h> void main() { int gd=DETECT,gm; int s; char *fname[] = { "EMPTY FILL","SOLID FILL","LINE FILL", "LTSLASH FILL","SLASH FILL","BKSLASH FILL", "LTBKSLASH FILL","HATCH FILL", "XHATCH FILL","INTERLEAVE FILL", "WIDE DOT FILL","CLOSE DOT FILL","USER FILL" }; char *lname[]={"SOLID LINE","DOTTED LINE","CENTER LINE","DASHED LINE","USERBIT LINE"}; initgraph(&gd,&gm," "); clrscr(); cleardevice(); outtextxy(20,20,"LINE STYLES"); for (s=0;s<5;s++) { setlinestyle(s,1,2); setcolor(s+2); line(100,30+s*50,250,250+s*50); outtextxy(255,250+s*50,lname[s]); } getch(); cleardevice(); setlinestyle(0,0,0); for (s=0;s<12;s++) {
18. 18. 44210205028 setfillstyle(s,s+0); setcolor(15); outtextxy(20,20,"ELLIPSE WITH VARIOUS FILL ATTRIBUTES"); fillellipse(150,20+s*40,30,15); outtextxy(275,30+s*40,fname[s]); outtextxy(360,20,"CIRCLE WITH VARIOUS FILL ATTRIBUTES"); fillellipse(450,20+s*40,18,18); } getch(); } OUTPUT: LINE STYLES SOLID LINE DOTTED LINE CENTER LINE DASHED LINE USER BIT LINE ELLIPSE & CIRCLE FILL STYLES
19. 19. 44210205028 RESULT: Thus the different attributes of line, circle, ellipse was implemented using C.
20. 20. 44210205028 DATE: 2D – BASIC TRANSFORMATIONS EX NO: 3 AIM: To perform the 2D transformation such as translation, rotation, scaling using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM: Step1:- Start the program Step2:-Enter the choice for transformation. Step 3:-. Perform the translation, rotation, scaling of 2D object. Step 4:- Get the needed parameters for the transformation from the user. Step 5:-. In case of rotation, object can be rotated about x or y axis. Step 6:-. Display the transmitted object in the screen. PROGRAM:
21. 21. 44210205028 #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> #include<stdlib.h> void menu(); void input(); void input1(); void output(); void output1(); void translation(); void rotation(); void scaling(); int a[10][10],b[10][10],b1[10][10],diff,i,j,x,option,temp,angle,tx,ty,fx,fy,sh,k,n,axis,y; float sx,sy; void menu() { printf("menun"); printf("0.drawn"); printf("1.Translationn"); printf("2.rotationn"); printf("3.scalingn"); printf("4.exitn"); printf("enter the choice:"); scanf("%d",&option); switch(option) { case 0: input(); menu(); break;
22. 22. 44210205028 case 1: translation(); break; case 2: rotation(); break; case 3: scaling(); break; case 4: exit(0); break; } input(); } void input() { printf("enter the number of vertices:" ); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter the coordinates:"); scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i+1][0],&a[i+1][1]); } } void output() { cleardevice(); for(i=0;i<n;i++) { line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); }
23. 23. 44210205028 for(i=0;i<n;i++) { b[i][0]=0; b[i][1]=0; }} void input1() { cleardevice(); for(i=0;i<n;i++) { line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); } } void output1() { cleardevice(); for(i=0;i<n;i++) { line(b[i][0],b[i][1],b[i+1][0],b[i+1][1]); } } void translation() { output(); printf("enter the tranformation vertex tx,ty:n"); scanf("%d%d",&tx,&ty); for(i=0;i<=n;i++) { b[i][0]=a[i][0]+tx; b[i][1]=a[i][1]+ty; }
24. 24. 44210205028 output1(); delay(10); menu(); } void rotation() { output(); printf("enter the rotating angle:"); scanf("%d",&y); printf("enter the pivot point:"); scanf("%d%d",&fx,&fy); k=(y*3.14)/180; for(i=0;i<=n;i++) { b[i][0]=fx+(a[i][0]-fx)*cos(y)+(a[i][1]-fy)*sin(y); b[i][1]=fy+(a[i][0]-fx)*sin(y)-(a[i][1]-fy)*cos(y); } output1(); delay(10); menu(); } void scaling() { output(); printf("enter the scaling factorn"); scanf("%f%f",&sx,&sy); printf("enter the fixed point:"); scanf("%d%d",&fx,&fy); for(i=0;i<=n;i++)
25. 25. 44210205028 { b[i][0]=a[i][0]*sx+fy*(1-sx); b[i][1]=a[i][1]*sy+fy*(1-sy); } output1(); delay(10); menu(); } OUTPUT Menu 0.Draw 1.Translation 2.Rotation 3.Scaling 4.Shearing 5.Reflection 6.Exit Enter the choice : 0 Enter the number of vertices : 3 Enter the coordinates :- 30 150 10 200 Enter the coordinates :- 10 200 60 200 Enter the coordinates :- 60 200 30 150 TRANSLATION
26. 26. 44210205028 Enter the choice : 1 Enter the translation factor 30 30 ROTATION Enter the choice : 2 Enter the angle 70 Enter the pivot point 100 200 SCALING
27. 27. 44210205028 Enter the choice : 3 Enter the scaling factor 0.3 0.3 Enter the fixed point 200 100 RESULT: Thus the basic 2D transformations was performed successfully using C.
28. 28. 44210205028 DATE: 2D – COMPOSITE TRANSFORMATIONS EX NO: 4 AIM: To perform the 2D composite transformation such as translation, rotation, scaling using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM: Step1:- Start the program Step2:-Enter the choice for transformation. Step 3:-. Perform the reflection and shearing of 2D object. Step 4:- Get the needed parameters for the transformation from the user. Step 5:-. Incase of rotation, object can be rotated about x or y axis. Step 6:-. Display the transmitted object in the screen PROGRAM:
29. 29. 44210205028 #include<stdio.h> #include<conio.h> #include<graphics.h> #include<dos.h> #include<math.h> #include<stdlib.h> void menu(); void input(); void input1(); void output(); void output1(); void shearing(); void reflection(); inta[10][10],b[10][10],b1[10][10],diff,i,j,x,option,temp,angle,tx,ty,fx,fy,sh,k,n, axis,y; float sx,sy; void menu() { printf("menun"); printf("0.drawn"); printf("1.shearingn"); printf("2.reflectionn"); printf("3.exitn"); printf("enter the choice:"); scanf("%d",&option); switch(option) { case 0: input(); menu(); break; case 1 : shearing(); break;
30. 30. 44210205028 case 2: reflection(); break; case 3: exit(0); break; } input(); } void input() { printf("enter the number of vertices:" ); scanf("%d",&n); for(i=0;i<n;i++) { printf("enter the coordinates:"); scanf("%d%d%d%d",&a[i][0],&a[i][1],&a[i+1][0],&a[i+1][1]); } } void output() { cleardevice(); for(i=0;i<n;i++) { line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); } for(i=0;i<n;i++) { b[i][0]=0; b[i][1]=0; } }
31. 31. 44210205028 void input1() { cleardevice(); for(i=0;i<n;i++) { line(a[i][0],a[i][1],a[i+1][0],a[i+1][1]); } } void output1() { cleardevice(); for(i=0;i<n;i++) { line(b[i][0],b[i][1],b[i+1][0],b[i+1][1]); } } void shearing() { output(); printf("enter the shear value:"); scanf("%d",&sh); printf("enter the axis for shearing if x-axis then 1 if y-axis the 0:"); scanf("%d",&axis); if(axis==1) { for(i=0;i<=n;i++) { if(i!=0 && i!=3) { b[i][0]=a[i][0]+sh; b[i][1]=a[i][1]; }
32. 32. 44210205028 else { b[i][0]=a[i][0]; b[i][1]=a[i][1]; } } } else { for(i=0;i<=n;i++) { if(i!=1) { b[i][1]=a[i][1]+sh; b[i][0]=a[i][0]; } else { b[i][0]=a[i][0]; b[i][1]=a[i][1]; } } } output1(); delay(10); menu(); } void reflection() { output(); diff=a[1][1]-a[0][1]; for(i=0;i<=n;i++) {
33. 33. 44210205028 if(i==0||i==3) { b[i][0]=a[i][0]; b[i][1]=a[i][1]+(2*diff)+10; } else { b[i][0]=a[i][0]; b[i][1]=a[i][1]+10; } } for(i=0;i<n;i++) { line(b[i][0],b[i][1],b[i+1][0],b[i+1][1]); } menu(); } void main() { int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi"); menu(); getch(); } OUTPUT
34. 34. 44210205028 Menu 0.Draw 1.Shearing 2.Reflection 3.Exit Enter the choice : 0 Enter the number of vertices : 3 Enter the coordinates :- 30 150 10 200 Enter the coordinates :- 10 200 60 200 Enter the coordinates :- 60 200 30 150 SHEARING Enter the choice : 1 Enter the Shear value 50 Enter the axis for shearing if x-axis then 1 if y-axis the 0: 1 Enter the axis for shearing if x-axis then 1 if y-axis the 0: 0
35. 35. 44210205028 REFLECTION Enter the choice : 2 RESULT: Thus the composite 2D transformations was performed successfully using C.
36. 36. 44210205028 DATE: COHEN SUTHERLAND LINE CLIPPING EX NO: 5(a) AIM: To perform Cohen-Sutherland line clipping using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM: Step 1. Create a class with functions drawwindow, drawline, setcode, visibility and reset endpoint. Step 2. Using the function line set the parameters to draw window. Step 3. Using the function defined in class sulc, setcode is used to save the line inside window and to the line outside the window. Step 4. Using the function visibility i).Check the code to know the points inside or outside the window. ii).If the code value is zero the point is inside the window.
37. 37. 44210205028 Step 5. Using the function reset end point i). if the code value for the line is outside the window. ii).reset the endpoint to the boundary of the window. Step 6. Initialize the graphics functions Step 7. Declare the variables x1, x2, y1, y2 of array type. Step 8. Get the value of two endpoints x1, y1 and x2, y2 to draw the line. Step 9. Using the object c, display the window before clipping. Step 10. Using the function setcode, visibility display the clipped window only with lines inside the window class was displayed after clipping. PROGRAM: #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> float cxl,cxr,cyt,cyb; code(float ,float); void clip(float ,float,float,float); void rect(float ,float,float,float); main() { float x1,y1,x2,y2; int g=0,d; initgraph(&g,&d,"c:tcbin"); settextstyle(1,0,1); outtextxy(40,15,"BEFORE CLIPPING"); printf("n Please Enter Left,Bottom,Right,Top Of Clip Window"); scanf("%f%f%f%f",&cxl,&cyb,&cxr,&cyt); rect(cxl,cyb,cxr,cyt); getch(); printf("n Enter The Line Coordinate");
38. 38. 44210205028 scanf("%f%f%f%f",&x1,&y1,&x2,&y2); line(x1,y1,x2,y2); getch(); cleardevice(); settextstyle(1,0,1); outtextxy(40,15,"AFTER CLIPPING"); clip(x1,y1,x2,y2); getch(); closegraph(); } void clip(float x1,float y1,float x2,float y2) { int c,c1,c2; float x,y; c1=code(x1,y1); c2=code(x2,y2); getch(); while((c1!=0)||(c2!=0)) { if((c1&c2)!=0) goto out; c=c1; if(c==0) c=c2; if((c&1)==1) { y=y1+(y2-y1)*(cxl-x1); x=cxl; } else if((c&2)==2) {
39. 39. 44210205028 y=y1+(y2-y1)*(cxl-x1)/(x2-x1); x=cxr; } else if((c&8)==8) { x=x1+(x2-x1)*(cyb-y1)/(y2-y1); y=cyb; } else if((c&4)==4) { x=x1+(x2-x1)*(cyt-y1)/(y2-y1); y=cyt; } if(c==c1) { x1=x; y1=y; c1=code(x,y); } else { x2=x; y2=y; c2=code(x,y); } } out: rect(cxl,cyb,cxr,cyt); line(x1,y1,x2,y2); }
40. 40. 44210205028 code(float x ,float y) { int c=0; if(x<cxl) c=1; else if(x>cxr) c=2; else if(y<cyb) c=c|8; else if(y>cyt) c=c|4; return c; } void rect(float xl,float yb,float xr,float yt) { line(xl,yb,xr,yb); line(xr,yb,xr,yt); line(xr,yt,xl,yt); line(xl,yt,xl,yb); } OUTPUT BEFORE CLIPPING Please Enter Left , Bottom , Right , Top Of The Clip window 200 200 400 400 Please Enter The Line Coordinates (X1, Y1, X2, Y2)
41. 41. 44210205028 150 300 400 450 AFTER CLIPPING RESULT: Thus Cohen-Sutherland clipping was implemented using C.
42. 42. 44210205028 DATE: WINDOW TO VIEWPORT MAPPING EX NO: 5(b) AIM: To perform window to viewport mapping using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM: Step1: Input the minimum and maximum coordinates of a window. Step2: Input the minimum and maximum coordinates of a view port. Step3: Get the coordinates of a point. Step4: Display a point using set pixel function. PROGRAM:
43. 43. 44210205028 #include<stdio.h> #include<conio.h> #include<graphics.h> #include<math.h> main() { float sx,sy; int w1,w2,w3,w4,x1,x2,x3,x4,y1,y2,y3,y4,v1,v2,v3,v4; int gd=DETECT,gm; initgraph(&gd,&gm,"c:tcbgi"); printf("Enter The Coordinate x1,y1,x2,y2,x3,y3n"); scanf("%d%d%d%d%d%d",&x1,&y1,&x2,&y2,&x3,&y3); cleardevice(); w1=5; w2=5; w3=635; w4=465; rectangle(w1,w2,w3,w4); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); getch(); v1=425; v2=75; v3=550; v4=250; sx=(float)(v3-v1)/(w3-w1); sy=(float)(v4-v2)/(w4-w2); rectangle(v1,v2,v3,v4); x1=v1+floor(((float)(x1-w1)*sx)+.5); x2=v1+floor(((float)(x2-w1)*sx)+.5);
44. 44. 44210205028 x3=v1+floor(((float)(x3-w1)*sx)+.5); y1=v2+floor(((float)(y1-w2)*sy)+.5); y2=v2+floor(((float)(y2-w2)*sy)+.5); y3=v2+floor(((float)(y3-w2)*sy)+.5); line(x1,y1,x2,y2); line(x2,y2,x3,y3); line(x3,y3,x1,y1); getch(); return 0; } OUTPUT Enter The Coordinate x1,y1,x2,y2,x3,y3 100 200 300 400 500 350
45. 45. 44210205028 RESULT: Thus the window to view port mapping was implemented using C.
46. 46. 44210205028 DATE: SUTHERLAND – HODGEMAN POLYGON CLIPPING EX NO: 6 AIM: To perform Sutherland – Hodgeman polygon clipping using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM: Step1: Get the minimum and maximum coordinates of both window and view port. Step2: Get the number of sides of a polygon and its corresponding coordinates. Step3: If the polygon lies within region code window, display it. Step4. If any one of the polygon side is neither inside nor outside the boundary, find point of intersection and clip the region that lies outside the boundary. Step5:. Display the polygon after clipping. PROGRAM:
47. 47. 44210205028 #include<stdio.h> #include<conio.h> #include<graphics.h> typedef enum { left,right,bottom,top } edge; #define N_EDGE 4 #define TRUE 1 #define FALSE 0 struct point { int x; int y; }p,wmin,wmax,p1,p2,ipt,i,pin[50],pout[50],first[50],s[50],i; int inside(struct point p,int b,struct point wmin,struct point wmax) { switch(b) { case left: if(p.x<wmin.x) return (FALSE); break; case right: if(p.x>wmax.x) return (FALSE); break; case bottom: if(p.y<wmin.y) return (FALSE); break; case top: if(p.y>wmax.y) return (FALSE);
48. 48. 44210205028 break; } return (TRUE); } int cross(struct point p1,struct point p2,int b,struct point wmin,struct point wmax) { if(inside(p1,b,wmin,wmax)==inside(p2,b,wmin,wmax)) return (FALSE); else return (TRUE); } struct point intersect(struct point p1,struct point p2,int b,struct point wmin,struct point wmax) { float m; if(p1.x!=p2.x) m=(p1.y-p2.y)/(p1.x-p2.x); switch(b) { case left: ipt.x=wmin.x; ipt.y=p2.y+(wmin.x-p2.x)*m; break; case right: ipt.x=wmax.x; ipt.y=p2.y+(wmax.x-p2.x)*m; break; case bottom: ipt.y=wmin.y; if(p1.x!=p2.x)
49. 49. 44210205028 ipt.x=p2.x+(wmin.y-p2.y)/m; else ipt.x=p2.x; break; case top: ipt.y=wmax.y; if(p1.x!=p2.x) ipt.x=p2.x+(wmax.y-p2.y)/m; else ipt.x=p2.x; break; } return(ipt);} void clippoint(struct point p,int b,struct point wmin,struct point wmax,struct point *pout,int *cnt,struct point *first[],struct point *s) { if(!first[b]) first[b]=&p; else if(cross(p,s[b],b,wmin,wmax)) { ipt=intersect(p,s[b],b,wmin,wmax); if(b<top) clippoint(ipt,b+1,wmin,wmax,pout,cnt,first,s); else { pout[*cnt]=ipt; (*cnt)++; } } s[b]=p;
50. 50. 44210205028 if(inside(p,b,wmin,wmax)) if(b<top) clippoint(p,b+1,wmin,wmax,pout,cnt,first,s); else { pout[*cnt]=p; (*cnt)++; } } void closeclip(struct point wmin,struct point wmax,struct point *pout,int *cnt,struct point *first[],struct point *s) { int b; for(b=left;b<=top;b++) { if(cross(s[b],*first[b],b,wmin,wmax)) { i=intersect(s[b],*first[b],b,wmin,wmax); if(b<top) clippoint(i,b+1,wmin,wmax,pout,cnt,first,s); else { pout[*cnt]=i; (*cnt)++; } } } } int clippolygon(struct point wmin,struct point wmax,int n,struct point
51. 51. 44210205028 *pin,struct point *pout) { struct point *first[N_EDGE]={0,0,0,0},s[N_EDGE]; int i,cnt=0; for(i=0;i<=n;i++) clippoint(pin[i],left,wmin,wmax,pout,&cnt,first,s); closeclip(wmin,wmax,pout,&cnt,first,s); return(cnt); } void main() { int c,gm,gr,n,j,np; clrscr(); detectgraph(&gm,&gr); initgraph(&gm,&gr,"d:tcBGI"); printf("Enter the window minimum coordinates"); scanf("%d%d",&wmin.x,&wmin.y); printf("Enter the window max coordinates"); scanf("%d%d",&wmax.x,&wmax.y); rectangle(wmin.x,wmax.y,wmax.x,wmin.y); printf("Enter the no of sides in polygon:n"); scanf("%d",&n); printf("Enter the coordinates(x,y)for pin ,pout:n"); for(j=0;j<n;j++) { scanf("%d%d",&pin[j].x,&pin[j].y); scanf("%d%d",&pout[j].x,&pout[j].y); } detectgraph(&gm,&gr); initgraph(&gm,&gr,"d:tcBGI"); outtextxy(10,10,"BEFORE CLIPPING"); for(j=0;j<n;j++)
52. 52. 44210205028 { if(j!=n-1) line(pin[j].x,pin[j].y,pout[j].x,pout[j].y); else line(pin[j].x,pin[j].y,pout[j].x,pout[j].y); } rectangle(wmin.x,wmax.y,wmax.x,wmin.y); printf("n1.polygon clipping 2.exit"); scanf("%d",&c); switch(c) { case 1: detectgraph(&gm,&gr); initgraph(&gm,&gr,"d:tcBGI"); rectangle(wmin.x,wmax.y,wmax.x,wmin.y); np=clippolygon(wmin,wmax,n,pin,pout); for(j=0;j<np-1;j++) { outtextxy(10,10,"AFTER CLIPPING"); line(pout[j].x,pout[j].y,pout[(j+1)].x,pout[(j+1)].y); } break; case 2: exit(0); } getch(); } OUTPUT
53. 53. 44210205028 Enter the window minimum coordinates : 200 200 Enter the window max coordinates :400 400 Enter the no of sides in polygon :3 Enter the coordinates(x,y)for pin ,pout 150 300 250 175 250 175 350 410 350 410 150 300 BEFORE CLIPPING 1.polygon clipping Press :- 1 2 Exit
54. 54. 44210205028 AFTER CLIPPING RESULT: Thus Sutherland - Hodgeman polygon clipping was implemented using C.
55. 55. 44210205028 DATE: 3D – BASIC TRANSFORMATIONS EX NO: 7 AIM: To perform 3D transformations such as Rotation, scaling and Translation using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM: Step1:Enter the choice for transformation. Step2: Perform the translation, rotation, scaling of 3D object. Step3: Get the needed parameters for the transformation from the user. Step4: Increase of rotation, object can be rotated about x or y or z axis. Step5: Display the transmitted object in the screen
56. 56. 44210205028 PROGRAM: #include<stdio.h> #include<math.h> #include<conio.h> #include<graphics.h> int gd=DETECT,gm,i,ch,sh,a1,b1,c1; float temp,theta,temp1; float a,b,c; double x1,x2,y1,y2; void draw_cube(double edge[20][3]) { initgraph(&gd,&gm,"..bgi"); clearviewport(); for(i=0;i<19;i++) { x1=edge[i][0]+edge[i][2]*(cos(2.3562)); y1=edge[i][1]-edge[i][2]*(sin(2.3562)); x2=edge[i+1][0]+edge[i+1][2]*(cos(2.3562)); y2=edge[i+1][1]-edge[i+1][2]*(sin(2.3562)); line(x1+320,240-y1,x2+320,240-y2); } line(320,240,320,25); line(320,240,550,240); line(320,240,150,410); getch(); closegraph(); } void draw_cube1(double edge1[20][3]) { initgraph(&gd,&gm,"..bgi"); clearviewport();
57. 57. 44210205028 for(i=0;i<19;i++) { x1=edge1[i][0]+edge1[i][2]*(cos(2.3562)); y1=edge1[i][1]-edge1[i][2]*(sin(2.3562)); x2=edge1[i+1][0]+edge1[i+1][2]*(cos(2.3562)); y2=edge1[i+1][1]-edge1[i+1][2]*(sin(2.3562)); line(x1+320,240-y1,x2+320,240-y2);} line(320,240,320,25); line(320,240,550,240); line(320,240,150,410); getch(); closegraph(); } void scale(double edge1[20][3],double edge[20][3]) { printf("Enter The Scaling Factors :=n"); scanf("%f %f %f",&a,&b,&c); initgraph(&gd,&gm,"..bgi"); clearviewport(); for(i=0;i<20;i++) { edge1[i][0]=edge[i][0]*a; edge1[i][1]=edge[i][1]*b; edge1[i][2]=edge[i][2]*c; } draw_cube1(edge1); closegraph(); } void translate(double edge1[20][3],double edge[20][3])
58. 58. 44210205028 { printf(" Enter The Translation Factors :=n"); scanf("%d %d %d",&a1,&b1,&c1); initgraph(&gd,&gm,"..bgi"); clearviewport(); for(i=0;i<20;i++) { edge1[i][0]=edge[i][0]+a1; edge1[i][1]=edge[i][1]+b1; edge1[i][2]=edge[i][2]+c1; } draw_cube1(edge1); closegraph(); } void rotate(double edge1[20][3],double edge[20][3]) { clrscr(); printf("-=[ Rotate About ]=-n"); printf("1:==> X-Axis n"); printf("2:==> Y-Axis n"); printf("3:==> Z-Axis n"); printf(" Enter Your Choice :=n"); scanf("%d",&ch); printf("Enter the anglen"); scanf("%f",&theta); switch(ch) { case 1: theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge1[i][0]=edge[i][0];
59. 59. 44210205028 temp=edge[i][1]; temp1=edge[i][2]; edge1[i][1]=temp*cos(theta)-temp1*sin(theta); edge1[i][2]=temp*sin(theta)+temp1*cos(theta); } draw_cube1(edge1); break; case 2: theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge1[i][1]=edge[i][1]; temp=edge[i][0]; temp1=edge[i][2]; edge1[i][0]=temp*cos(theta)+temp1*sin(theta); edge1[i][2]=-temp*sin(theta)+temp1*cos(theta); } draw_cube1(edge1); break; case 3: theta=(theta*3.14)/180; for(i=0;i<20;i++) { edge1[i][2]=edge[i][2]; temp=edge[i][0]; temp1=edge[i][1]; edge1[i][0]=temp*cos(theta)-temp1*sin(theta); edge1[i][1]=temp*sin(theta)+temp1*cos(theta); } draw_cube1(edge1);
60. 60. 44210205028 break; } } void main() { int choice; double edge1[20][3],edge[20][3]= { 100,0,0, 100,100,0, 0,100,0, 0,100,100, 0,0,100, 0,0,0, 100,0,0, 100,0,100, 100,75,100, 75,100,100, 100,100,75, 100,100,0, 100,100,75, 100,75,100, 75,100,100, 0,100,100, 0,100,0, 0,0,0, 0,0,100, 100,0,100 while(1) { clrscr(); };
61. 61. 44210205028 printf("3D BASIC TRANSFORMATIONSn"); printf("1:==> Draw Cuben"); printf("2:==> Translaten"); printf("3:==> Scaling n"); printf("4:==> Rotation n"); printf("5:==> Exit n"); printf("Enter Your Choice :=n"); scanf("%d",&choice); switch(choice) { case 1: draw_cube(edge); break; case 2: translate(edge1,edge); break; case 3: scale(edge1,edge); break; case 4: rotate(edge1,edge); break; case 5: exit(0); default: printf(" Press A Valid Key...!!! "); getch();
62. 62. 44210205028 break; } closegraph(); }} OUTPUT 3D BASIC TRANSFORMATIONS 1:Draw Circle 2::Translation 3:Scaling 4:Rotaion 5:Exit
63. 63. 44210205028 TRANSLATION Enter your choice :- 1 Enter the Traanlation Factor :- 50 60 70 0.2 0.3 SCALING Enter your choice :- 2 Enter the Scaling Factors :- 0.3
64. 64. 44210205028 ROTATION Rotate About 1: X-Axis 2:Y-Axis 3:Z-Axis Enter your choice :- 1 Enter the angle :- 30 Enter your choice :- 2 Enter the angle :- 30 Enter your choice :- 3 Enter the angle :- 30 RESULT:
65. 65. 44210205028 Thus 3D Basic transformations was implemented using C. DATE: 3D – COMPOSITE TRANSFORMATIONS EX NO: 8 AIM: To perform 3D composite transformations such as shearing, reflection using C. Functions used: initgraph():- This function takes thee arguments and they are i).The video driver to be used (gd). ii).The graphics mode (gm). iii).the path name. Syntax:- Initgraph(gd,gm,path) Putpixel () :- The function putpixel() is used to place a pixel at particular coordinate. Syntax:- Putpixel(x,y,color) ALGORITHM: Step1:Enter the choice for transformation. Step2: Perform the translation, rotation, scaling of 3D object. Step3: Get the needed parameters for the transformation from the user. Step4: Increase of rotation, object can be rotated about x or y or z axis. Step5: Display the transmitted object in the screen
66. 66. 44210205028 PROGRAM: #include<stdio.h> #include<stdio.h> #include<math.h> #include<conio.h> #include<graphics.h> int gd=DETECT,gm,i,ch,sh; double x1,x2,y1,y2; void draw_cube(double edge[20][3]) { initgraph(&gd,&gm,"..bgi"); clearviewport(); for(i=0;i<19;i++) { x1=edge[i][0]+edge[i][2]*(cos(2.3562)); y1=edge[i][1]-edge[i][2]*(sin(2.3562)); x2=edge[i+1][0]+edge[i+1][2]*(cos(2.3562)); y2=edge[i+1][1]-edge[i+1][2]*(sin(2.3562)); line(x1+320,240-y1,x2+320,240-y2); } line(320,240,320,25); line(320,240,550,240); line(320,240,150,410); getch(); closegraph(); } void draw_cube1(double edge1[20][3]) {
67. 67. 44210205028 initgraph(&gd,&gm,"..bgi"); clearviewport(); for(i=0;i<19;i++) { x1=edge1[i][0]+edge1[i][2]*(cos(2.3562)); y1=edge1[i][1]-edge1[i][2]*(sin(2.3562)); x2=edge1[i+1][0]+edge1[i+1][2]*(cos(2.3562)); y2=edge1[i+1][1]-edge1[i+1][2]*(sin(2.3562)); line(x1+320,240-y1,x2+320,240-y2); } line(320,240,320,25); line(320,240,550,240); line(320,240,150,410); getch(); closegraph(); } void reflect(double edge1[20][3],double edge[20][3]) { int ch; int i; clrscr(); printf("-=[ Reflection About ]=-n"); printf("1:==> X-Axis n"); printf("2:==> Y-Axis n"); printf("3:==> Z-Axis n"); printf(" Enter Your Choice :=n"); scanf("%d",&ch); switch(ch) { case 1: for(i=0;i<20;i++)
68. 68. 44210205028 { edge1[i][0]=edge[i][0]; edge1[i][1]=-edge[i][1]; edge1[i][2]=-edge[i][2]; } draw_cube1(edge1); break; case 2: for(i=0;i<20;i++) { edge1[i][1]=edge[i][1]; edge1[i][0]=-edge[i][0]; edge1[i][2]=-edge[i][2]; } draw_cube1(edge1); break; case 3: for(i=0;i<20;i++) { edge1[i][2]=edge[i][2]; edge1[i][0]=-edge[i][0]; edge1[i][1]=-edge[i][1]; } draw_cube1(edge1); break; } } void shear(double edge1[20][3],double edge[20][3]) { int ch,sh; int i;
69. 69. 44210205028 clrscr(); printf("-=[ Shearing About ]=-n"); printf("1:==> X-Axis n"); printf("2:==> Y-Axis n"); printf("3:==> Z-Axis n"); printf(" Enter Your Choice :=n"); scanf("%d",&ch); printf("ENter shear valuen"); scanf("%d",&sh); switch(ch) { case 1: for(i=0;i<20;i++) { if(edge[i][0]==100&&edge[i] [1]==100&&edge[i][2]==0||edge[i][0]==100&&edge[i][1]==100&&edge[i][2]==100|| edge[i][0]==0&&edge[i][1]==100&&edge[i][2]==100||edge[i][0]==0&&edge[i] [1]==100&&edge[i][2]==0) { edge1[i][0]=edge[i][0]+sh; edge1[i][1]=edge[i][1]; edge1[i][2]=edge[i][2]; } else { edge1[i][0]=edge[i][0]; edge1[i][1]=edge[i][1]; edge1[i][2]=edge[i][2]; } } draw_cube1(edge1); break; case 2:
70. 70. 44210205028 for(i=0;i<20;i++) { if(edge[i][0]==100&&edge[i][1]==100&&edge[i][2]==0|| edge[i][0]==100&&e dge[i][1]==100&&edge[i][2]==100||edge[i][0]==100&&edge[i] [1]==0&&edge[i][2]==0||edge[i][0]==100&&edge[i][1]==0&&edge[i][2]==100) { edge1[i][0]=edge[i][0]; edge1[i][1]=edge[i][1]+sh; edge1[i][2]=edge[i][2]; } else { edge1[i][0]=edge[i][0]; edge1[i][1]=edge[i][1]; edge1[i][2]=edge[i][2]; }} draw_cube1(edge1); break; case 3: for(i=0;i<20;i++) { if(edge[i][0]==100&&edge[i] [1]==100&&edge[i][2]==0||edge[i][0]==100&&e dge[i][1]==100&&edge[i][2]==100) { edge1[i][0]=edge[i][0]; edge1[i][1]=edge[i][1]; edge1[i][2]=edge[i][2]-sh; } else { edge1[i][0]=edge[i][0]; edge1[i][1]=edge[i][1];
71. 71. 44210205028 edge1[i][2]=edge[i][2]; }} draw_cube1(edge1); break; }} void main() { int choice; double edge1[20][3],edge[20][3]= { 100,0,0, 100,100,0, 0,100,0, 0,100,100, 0,0,100, 0,0,0, 100,0,0, 100,0,100, 100,100,100, 100,100,100, 100,100,0, 100,100,0, 100,100,100, 100,100,100, 100,100,100, 0,100,100, 0,100,0, 0,0,0, 0,0,100, 100,0,100 }; while(1) { clrscr();
72. 72. 44210205028 printf("3D COMPOSITE ETRANSFORMATIONSn"); printf("1:==>Draw Cuben "); printf("2:==>Reflectionn "); printf("3:==>Shearingn"); printf("4:==>Exitn"); printf("Enter Your Choice :=n"); scanf("%d",&choice); switch(choice) { case 1: draw_cube(edge); break; case 2: reflect(edge1,edge); break; case 3: shear(edge1,edge);; break; case 4: exit(0); default: printf(" Press A Valid Key...!!! n"); getch(); break; } closegraph(); } }
73. 73. 44210205028 OUTPUT: 3D COMPOSIITE TRANSFORMATIONS 1:Draw Cube 2:Reflection 3:Shearing 4: Exit Enter the choice : 1
74. 74. 44210205028 REFLECTION Enter the choice :- 2 REFLECTION IS ABOUT 1:X-AXIS 2:Y-AXIS 3:Z-AXIS Enter the choice : 1 Enter the choice : 2 Enter the choice : 3
75. 75. 44210205028 SHEARING Enter the choice :- 3 SHEARING IS ABOUT 1:X-AXIS 2:Y-AXIS 3:Z-AXIS Enter the choice : 1 Enter the choice : 2 Enter the choice : 3
76. 76. 44210205028
77. 77. 44210205028 RESULT: 3D Composite transformations was implemented using C. DATE: 3D MODEL EX NO: 9 AIM: To perform the 3D model using Maya or 3d MAX software DESCRIPTION: In 3D computer graphics, 3D modeling (also known as meshing) is the process of developing a mathematical representation of any three-dimensional surface of object (either inanimate or living) via specialized software. The product is called a 3D model. It can be displayed as a two-dimensional image through a process called 3D rendering or used in a computer simulation of physical phenomena. The model can also be physically created using 3D Printing devices. Models may be created automatically or manually. The manual modeling process of preparing geometric data for 3D computer graphics is similar to plastic arts such as sculpting. Models 3D models represent a 3D object using a collection of points in 3D space, connected by various geometric entities such as triangles, lines, curved surfaces, etc. Being a collection of data (points and other information), 3D models can be created by hand, algorithmically (procedural modeling), or scanned. 3D models are widely used anywhere in 3D graphics. Actually, their use predates the widespread use of 3D graphics on personal computers. Many computer games used pre-rendered images of 3D models as sprites before computers could render them in real-time.
78. 78. 44210205028 3D models are used in a wide variety of fields. The medical industry uses detailed models of organs. The movie industry uses them as characters and objects for animated and reallife motion pictures. The video game industry uses them as assets for computer and video games. The science sector uses them as highly detailed models of chemical compounds. The architecture industry uses them to demonstrate proposed buildings and landscapes through Software Architectural Models. The engineering community uses them as designs of new devices, vehicles and structures as well as a host of other uses. In recent decades the earth science community has started to construct 3D geological models as a standard practice. Representation A modern render of the iconic Utah teapot model developed by Martin Newell (1975). The Utah teapot is one of the most common models used in 3D graphics education. Almost all 3D models can be divided into two categories. • Solid - These models define the volume of the object they represent (like a rock). These are more realistic, but more difficult to build. Solid models are mostly used for nonvisual simulations such as medical and engineering simulations, for CAD and specialized visual applications such as ray tracing and constructive solid geometry • Shell/boundary - these models represent the surface, e.g. the boundary of the object, not its volume (like an infinitesimally thin eggshell). These are easier to work with than solid models. Almost all visual models used in games and film are shell models. Because the appearance of an object depends largely on the exterior of the object, boundary representations are common in computer graphics. Two dimensional surfaces are a good analogy for the objects used in graphics, though quite often these objects are non-manifold. Since surfaces are not finite, a discrete digital approximation is required: polygonal meshes (and to a lesser extent subdivision surfaces) are by far the most common representation, although point-based representations have been gaining some popularity in recent years. Level sets are a useful representation for deforming surfaces which undergo many topological changes such as fluids.
79. 79. 44210205028 The process of transforming representations of objects, such as the middle point coordinate of a sphere and a point on its circumference into a polygon representation of a sphere, is called tessellation. This step is used in polygon-based rendering, where objects are broken down from abstract representations ("primitives") such as spheres, cones etc., to so-called meshes, which are nets of interconnected triangles. Meshes of triangles (instead of e.g. squares) are popular as they have proven to be easy to render using scanline rendering.[1] Polygon representations are not used in all rendering techniques, and in these cases the tessellation step is not included in the transition from abstract representation to rendered scene. Modeling processes 3D computer modeling of the Great mosquee of Kairouan also called the Mosque of Uqba (in Kairouan, Tunisia) There are five popular ways to represent a model: • Polygonal modeling - Points in 3D space, called vertices, are connected by line segments to form a polygonal mesh. Used, for example, by Blender. The vast majority of 3D models today are built as textured polygonal models, because they are flexible and because computers can render them so quickly. However, polygons are planar and can only approximate curved surfaces using many polygons. • NURBS modeling - NURBS Surfaces are defined by spline curves, which are influenced by weighted control points. The curve follows (but does not necessarily interpolate) the points. Increasing the weight for a point will pull the curve closer to that point. NURBS are truly smooth surfaces, not approximations using small flat surfaces, and so are particularly suitable for organic modeling. Maya, Rhino 3d and solidThinking are the most wellknown commercial programs which use NURBS natively. • Splines & Patches modeling - Like NURBS, Splines and Patches depend on curved lines to define the visible surface. Patches fall somewhere between NURBS and polygons in terms of flexibility and ease of use.
80. 80. • 44210205028 Primitives modeling - This procedure takes geometric primitives like balls, cylinders, cones or cubes as building blocks for more complex models. Benefits are quick and easy construction and that the forms are mathematically defined and thus absolutely precise, also the definition language can be much simpler. Primitives modeling is well suited for technical applications and less for organic shapes. Some 3D software can directly render from primitives (like POV-Ray), others use primitives only for modeling and convert them to meshes for further operations and rendering. • Sculpt modeling - Still fairly new method of modeling 3D sculpting has become very popular in the few short years it has been around. There are 2 types of this currently, Displacement which is the most widely used among applications at this moment, and volumetric. Displacement uses a dense model (often generated by Subdivision surfaces of a polygon control mesh) and stores new locations for the vertex positions through use of a 32bit image map that stores the adjusted locations. Volumetric which is based loosely on Voxels has similar capabilities as displacement but does not suffer from polygon stretching when there are not enough polygons in a region to achieve a deformation. • Both of these methods allow for very artistic exploration as the model will have a new topology created over it once the models form and possibly details have been sculpted. The new mesh will usually have the original high resolution mesh information transferred into displacement data or normal map data if for a game engine. The modeling stage consists of shaping individual objects that are later used in the scene. There are a number of modeling techniques, including: o constructive solid geometry o implicit surfaces o subdivision surfaces Modeling can be performed by means of a dedicated program (e.g., form•Z, Maya, 3DS Max, Blender, Lightwave, Modo, solidThinking) or an application component (Shaper,
81. 81. 44210205028 Lofter in 3DS Max) or some scene description language (as in POV-Ray). In some cases, there is no strict distinction between these phases; in such cases modeling is just part of the scene creation process (this is the case, for example, with Caligari trueSpace and Realsoft 3D). Complex materials such as blowing sand, clouds, and liquid sprays are modeled with particle systems, and are a mass of 3D coordinates which have either points, polygons, texture splats, or sprites assigned to them. Sculpt Scene setup • The geometry in 3D modeling is completely described in 3-D space; objects can be viewed from any angle, revealing the lighting from different angles. Modeled and ray traced in Cobalt • Scene setup involves arranging virtual objects, lights, cameras and other entities on a scene which will later be used to produce a still image or an animation. • Lighting is an important aspect of scene setup. As is the case in real-world scene arrangement, lighting is a significant contributing factor to the resulting aesthetic and visual quality of the finished work. As such, it can be a difficult art to master. Lighting effects can contribute greatly to the mood and emotional response effected by a scene, a fact which is well-known to photographers and theatrical lighting technicians. It is usually desirable to add color to a model's surface in a user controlled way prior to rendering. Most 3D modeling software allows the user to color the model's vertices, and that color is then interpolated across the model's surface during rendering. This is often how models are colored by the modeling software while the model is being created. The most common method of adding color information to a 3D model is by applying a 2D texture image to the model's surface through a process called texture mapping. Texture images are no different than any other digital image, but during the texture mapping process, special pieces of information (called texture coordinates or UV coordinates) are added to the model that indicate which parts of the texture image map to which parts of the 3D model's surface. Textures allow 3D models to look significantly more detailed and realistic than they would otherwise.
82. 82. 44210205028 Other effects, beyond texturing and lighting, can be done to 3D models to add to their realism. For example, the surface normals can be tweaked to affect how they are lit, certain surfaces can have bump mapping applied and any other number of 3D rendering tricks can be applied. 3D models are often animated for some uses. They can sometimes be animated from within the 3D modeler that created them or else exported to another program. If used for animation, this phase usually makes use of a technique called "keyframing", which facilitates creation of complicated movement in the scene. With the aid of keyframing, one needs only to choose where an object stops or changes its direction of movement, rotation, or scale, between which states in every frame are interpolated. These moments of change are known as keyframes. Often extra data is added to the model to make it easier to animate. For example, some 3D models of humans and animals have entire bone systems so they will look realistic when they move and can be manipulated via joints and bones, in a process known as skeletal animation. Compared to 2D methods A fully textured and lit rendering of a 3d model. 3D photorealistic effects are often achieved without wireframe modeling and are sometimes indistinguishable in the final form. Some graphic art software includes filters that can be applied to 2D vector graphics or 2D raster graphics on transparent layers. Advantages of wireframe 3D modeling over exclusively 2D methods include: • Flexibility, ability to change angles or animate images with quicker rendering of the changes; • Ease of rendering, automatic calculation and rendering photorealistic effects rather than mentally visualizing or estimating; • Accurate photorealism, less chance of human error in misplacing, overdoing, or forgetting to include a visual effect. Disadvantages compare to 2D photorealistic rendering may include a software learning curve and difficulty achieving certain photorealistic effects. Some photorealistic effects may be achieved with special rendering filters included in the 3D modeling software. For the best of both worlds, some artists use a combination of 3D modeling followed by editing the 2D computer-rendered images from the 3D model.
83. 83. 44210205028 3D model market 3CT (3D Catalog Technology) has revolutionized the 3D model market by offering quality 3D model libraries free of charge for professionals using various CAD programs. Some believe that this uprising technology is gradually eroding the traditional "buy and sell" or "object for object exchange" markets although the quality of the products do not match those sold on specialized 3d marketplaces. A large market for 3D models (as well as 3D-related content, such as textures, scripts, etc.) still exists - either for individual models or large collections. Online marketplaces for 3D content allow individual artists to sell content that they have created. Often, the artists' goal is to get additional value out of assets they have previously created for projects. By doing so, artists can earn more money out of their old content, and companies can save money by buying pre-made models instead of paying an employee to create one from scratch..
84. 84. 44210205028 DATE: GENERATING FRACTAL IMAGE EX NO: 10 AIM: To generate fractal images. DESCRIPTION: A fractal is "a rough or fragmented geometric shape that can be split into parts, each of which is (at least approximately) a reduced-size copy of the whole,"[1] a property called self-similarity. Roots of the idea of fractals go back to the 17th century, while mathematically rigorous treatment of fractals can be traced back to functions studied by Karl Weierstrass, Georg Cantor and Felix Hausdorff a century later in studying functions that were continuous but not differentiable; however, the term fractal was coined by Benoît Mandelbrot in 1975 and was derived from the Latin fractus meaning "broken" or "fractured." A mathematical fractal is based on an equation that undergoes iteration, a form of feedback based on recursion. There are several examples of fractals, which are defined as portraying exact selfsimilarity, quasi self-similarity, or statistical self-similarity. While fractals are a mathematical construct, they are found in nature, which has led to their inclusion in artwork. They are useful in medicine, soil mechanics, seismology, and technical analysis Characteristics A fractal often has the following features: o It has a fine structure at arbitrarily small scales.
85. 85. o 44210205028 It is too irregular to be easily described in traditional Euclidean geometric language. o It is self-similar (at least approximately or stochastically). o It has a Hausdorff dimension which is greater than its topological dimension (although this requirement is not met by space-filling curves such as the Hilbert curve). o It has a simple and recursive definition. Because they appear similar at all levels of magnification, fractals are often considered to be infinitely complex (in informal terms). Natural objects that are approximated by fractals to a degree include clouds, mountain ranges, lightning bolts, coastlines, snow flakes, various vegetables (cauliflower and broccoli), and animal coloration patterns. However, not all self-similar objects are fractals—for example, the real line (a straight Euclidean line) is formally self-similar but fails to have other fractal characteristics; for instance, it is regular enough to be described in Euclidean terms. Images of fractals can be created using fractal-generating software. Images produced by such software are normally referred to as being fractals even if they do not have the above characteristics, such as when it is possible to zoom into a region of the fractal that does not exhibit any fractal properties. Generation Four common techniques for generating fractals are: • Escape-time fractals – (also known as "orbits" fractals) These are defined by a formula or recurrence relation at each point in a space (such as the complex plane). Examples of this type are the Mandelbrot set, Julia set, the Burning Ship fractal, the Nova fractal and the Lyapunov fractal. The 2d vector fields that are generated by one or two iterations of escape-time formulae also give rise to a fractal form when points (or pixel data) are passed through this field repeatedly. • Iterated function systems – These have a fixed geometric replacement rule. Cantor set, Sierpinski carpet, Sierpinski gasket, Peano curve, Koch snowflake,
86. 86. 44210205028 Harter-Highway dragon curve, T-Square, Menger sponge, are some examples of such fractals. • Random fractals – Generated by stochastic rather than deterministic processes, for example, trajectories of the Brownian motion, Lévy flight, fractal landscapes and the Brownian tree. The latter yields so-called mass- or dendritic fractals, for example, diffusion-limited aggregation or reactionlimited aggregation clusters. • Strange attractors – Generated by iteration of a map or the solution of a system of initial-value differential equations that exhibit chaos. Classification Fractals can also be classified according to their self-similarity. There are three types of self-similarity found in fractals • Exact self-similarity – This is the strongest type of self-similarity; the fractal appears identical at different scales. Fractals defined by iterated function systems often display exact self-similarity. For example, the Sierpinski triangle and Koch snowflake exhibit exact self-similarity. • Quasi-self-similarity – This is a looser form of self-similarity; the fractal appears approximately (but not exactly) identical at different scales. Quasiself-similar fractals contain small copies of the entire fractal in distorted and degenerate forms. Fractals defined by recurrence relations are usually quasiself-similar but not exactly self-similar. The Mandelbrot set is quasi-selfsimilar, as the satellites are approximations of the entire set, but not exact copies. • Statistical self-similarity – This is the weakest type of self-similarity; the fractal has numerical or statistical measures which are preserved across scales. Most reasonable definitions of "fractal" trivially imply some form of statistical self-similarity. (Fractal dimension itself is a numerical measure which is preserved across scales.) Random fractals are examples of fractals which are statistically self-similar.
87. 87. 44210205028 In nature • Approximate fractals are easily found in nature. These objects display selfsimilar structure over an extended, but finite, scale range. Examples include clouds, river networks, fault lines, mountain ranges, craters, snow flakes, crystals, lightning, cauliflower or broccoli, and systems of blood vessels and pulmonary vessels, and ocean waves. Coastlines may be loosely considered fractal in nature. • Trees and ferns are fractal in nature and can be modeled on a computer by using a recursive algorithm. This recursive nature is obvious in these examples —a branch from a tree or a frond from a fern is a miniature replica of the whole: not identical, but similar in nature. The connection between fractals and leaves is currently being used to determine how much carbon is contained in trees. • In 1999, certain self similar fractal shapes were shown to have a property of "frequency invariance"—the same electromagnetic properties no matter what the frequency—from Maxwell's equations (see fractal antenna). In creative works • Fractal patterns have been found in the paintings of American artist Jackson Pollock. While Pollock's paintings appear to be composed of chaotic dripping and splattering, computer analysis has found fractal patterns in his work. • Decalcomania, a technique used by artists such as Max Ernst, can produce fractal-like patterns. It involves pressing paint between two surfaces and pulling them apart. • Cyberneticist Ron Eglash has suggested that fractal-like structures are prevalent in African art and architecture. Circular houses appear in circles of circles, rectangular houses in rectangles of rectangles, and so on. Such scaling
88. 88. 44210205028 patterns can also be found in African textiles, sculpture, and even cornrow hairstyles. • In a 1996 interview with Michael Silverblatt, David Foster Wallace admitted that the structure of the first draft of Infinite Jest he gave to his editor Michael Pietsch was inspired by fractals, specifically the Sierpinski triangle (aka Sierpinski gasket) but that the edited novel is "more like a lopsided Sierpinsky Gasket". Applications o Classification of histopathology slides in medicine o Fractal landscape or Coastline complexity o Enzyme/enzymology (Michaelis-Menten kinetics) o Generation of new music o Signal and image compression o Creation of digital photographic enlargements o Seismology o Fractal in soil mechanics o Computer and video game design, especially computer graphics for organic environments and as part of procedural generation o Fractography and fracture mechanics o Fractal antennas – Small size antennas using fractal shapes o Small angle scattering theory of fractally rough systems o T-shirts and other fashion o Generation of patterns for camouflage, such as MARPAT o Digital sundial o Technical analysis of price series (see Elliott wave principle)
89. 89. 44210205028 DATE: OPENGL TO WORK WITH VISUAL C++ EX NO: 11 INSTALLATION : 1. Install Visual C++ 2008 Express Edition (To support OpenGL). 2. Copy all the .h files into the C:Program FilesMicrosoft SDKsWindowsv6.1IncludeGL folder. Header Files (.h files) : Gl.h, glu.h, glut.h, freeglut.h, freeglut_ext.h , freeglut_std.h 3. Copy all the .lib files into the C:Program FilesMicrosoft SDKsWindowsv6.1Lib folder. Library files (.lib files) : opengl32.lib, glut32.lib, glu32.lib 4. Copy all the .dll files into the C:Windowssystem32 folder. Dynamic Link Library Files (.dll) : freeglut.dll , glut32.dll Working with Console Application Program in OpenGL 1. Creating a Project 1. Start Visual C++ and Under the File menu select New → Project (Ctrl+Shift+N). 2. Select project types as Win32 and Win32 Console Application. 3. Give a User name for the Project. 4. Add a GLUT program to the project in the window. 2. Linking OpenGL Libraries 1. Under the Project menu select Project Properties (Alt+F7) at the bottom. 2. Select Configuration Properties → Select “C/C++” → “Preprocessor” → In preprocessor definitions additionally include the path where gl/glut.h is present. Example : C:Program FilesMicrosoft SDKs Windows v6.0A Include 3. Select "Linker" folder and click "Input" .