Friday 27 September 2013

3D TRANSFORMATION - ROTATION in C Aglorithm | Computer Graphics Lab Manual | IT department | Final Year




AIM:

To implement 3D transformation of Rotation.

ALGORITHM:


1. Give the specification for the rotation axis and the rotation angle accomplish the required rotation in five steps.

2. Translate the object so that the rotation axis passes through the coordinate origin.

3. Rotate the object so that the axis of rotation coincides with one of the coordinate axis.

4. Perform the specified rotations above that coordinate axis.

5. Apply the inverse translation to bring the rotation axis back to the original rotation.

SOURCE CODE:

#include

#include

#include

#include

void main()

{

int gd=VGA,gm=VGAMED;

initgraph(&gd,&gm,"c:\\tc\\bgi");

int n,d,p1[10][3],p2[10][3],p3[10][3],p4[10][3];

int t,i;

setcolor(15);setcolor(8);

settextstyle(1,0,2);

cout<<"\n enter the number of lines"<
cin>>n;

cout<<"\n enter the points"<
for(i=1;i<=n;i++)

cin>>p1[i][1]>>p1[i][2];

cout<<"\n enter the depth value"<
cin>>d;

for(i=1;i<=n;i++)

{

p2[i][1]=p1[i][1]+d;

p2[i][2]=p1[i][2]+d;

}

cout<<"enter the angle for rotation"<
cin>>t;

cleardevice();

outtextxy(50,50,"befor rotation");

for(i=1;i<=n;i++)

line(p1[i][1],p1[i][2],p1[i+1][1],p1[i+1][2]);

line(p1[1][1],p1[1][2],p1[n][1],p1[n][2]);

for(i=1;i<=n-1;i++)

line(p2[i][1],p2[i][2],p2[i+1][1],p2[i+1][2]);

line(p2[1][1],p2[1][2],p2[n][1],p2[n][2]);

for(i=1;i<=n;i++)

line(p1[i][1],p1[i][2],p2[i][1],p2[i][2]);

for(i=1;i<=n;i++)

{

p3[i][1]=p1[i][1]*cos(t*3.14/180)-p1[i][2]*sin(t*3.14/180);

p3[i][2]=p1[i][1]*sin(t*3.14/180)+p1[i][2]*cos(t*3.14/180);

p4[i][1]=p2[i][1]*cos(t*3.14/180)-p2[i][2]*sin(t*3.14/180);

p4[i][2]=p2[i][1]*sin(t*3.14/180)+p2[i][2]*cos(t*3.14/180);

}

outtextxy(200,200,"after rotation");

for(i=1;i<=n-1;i++)

line(p3[i][1],p3[i][2],p3[i+1][1],p3[i+1][2]);

line(p3[1][1],p3[1][2],p3[n][1],p3[n][2]);

for(i=1;i<=n-1;i++)

line(p4[i][1],p4[i][2],p4[i+1][1],p4[i+1][2]);

line(p4[1][1],p4[1][2],p4[n][1],p4[n][2]);

for(i=1;i<=n-1;i++)

line(p3[i][1],p3[i][2],p4[i][1],p4[i][2]);

getch();

}

OUTPUT:

Enter the no of lines: 4

Enter the values: 50 60 70 80 90 55 65 75

Enter the depth: 10

Enter the angle of rotation: 40





No comments:

Don't You Think this Awesome Post should be shared ??
| 3D TRANSFORMATION - ROTATION in C Aglorithm | Computer Graphics Lab Manual | IT department | Final Year |
Back To Top Related Posts Plugin for WordPress, Blogger...