EX.NO:6 2 – DIMENSIONAL TRANSFORMATION
AIM
To perform the various 2-dimensional transformations such as translation, rotation.
Algorithm
Step 1: Input the figure.
Step 2: Display the menu as 1.Translation 2.Rotation 3.Scaling 4.Shearing 5.reflection 6 ..Exit
Step 3: Get the choice from the user.
Step 4: If the choice is 1 get the translation vector. Add the translation vector to the original coordinate position to move to a new position.
Step 5: If the choice is 2 get the rotation angle. Rotate the figure with respect to the specified angle.
Step 6: If the choice is 3 get the scaling factor. scale the figure with respect to the specified scaling factor.
Step 7: If the choice is 4 get the shearing factor.and shear the e the figure with respect to the specified shearing factor
Step 8: If the choice is 5 get the reflecting axis. Reflect the figure with respect to the specified axis.
Step 9: If choice is 6 exit the program.
PROGRAM
#include<stdio.h>
#include<conio.h>
#include<graphics.h>
#include<dos.h>
#include<math.h>
#include<stdlib.h>
void menu();
void input();
void output();
void translation();
void rotation();
void scaling();
void shearing();
void reflection();
int a[10][2],i,x,option,temp,angle,tx,ty,fx,fy,sh,k,n,axis,y;
float sx,sy;
void menu()
{
printf("menu\n");
printf("1.Translation\n");
printf("2.rotation\n");
printf("3.scaling\n");
printf("4.shearing\n");
printf("5.reflection\n");
printf("6.exit\n");
printf("enter the choice:");
scanf("%d",&option);
switch(option)
{
case 1:
input();
translation();
break;
case 2:
input();
rotation();
break;
case 3:
input();
scaling();
break;
case 4 :
input();
shearing();
break;
case 5:
input();
reflection();
break;
case 6:
exit(0);
break;
}
}
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]);
}
}
void translation()
{
output();
printf("enter the tranformation vertex tx,ty:\n");
scanf("%d%d",&tx,&ty);
for(i=0;i<=n;i++)
{
a[i][0]=a[i][0]+tx;
a[i][1]=a[i][1]+ty;
}
output();
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++)
{
a[i][0]=fx+(a[i][0]-fx)*cos(k)-(a[i][1]-fy)*sin(k);
a[i][1]=fy+(a[i][0]-fx)*sin(k)-(a[i][1]-fy)*cos(k);
}
output();
delay(10);
menu();
}
void scaling()
{
output();
printf("enter the scaling factor\n");
scanf("%f%f",&sx,&sy);
printf("enter the fixed point:");
scanf("%d%d",&fx,&fy);
for(i=0;i<=n;i++)
{
a[i][0]=a[i][0]*sx+fy*(1-sx);
a[i][1]=a[i][1]*sy+fy*(1-sy);
}
output();
delay(10);
menu();
}
void shearing()
{
output();
printf("enter the shear value:");
scanf("%d",&sh);
printf("enter the fixed point:");
scanf("%d%d",&fx,&fy);
printf("enter the axis for shearing if x-axis then 1 if y-axis the 0:");
scanf("%d",&axis);
for(i=0;i<=n;i++)
{
if(axis==1)
{
a[i][0]=a[i][0]+sh*(a[i][1]-fy);
}
else
{
a[i][1]=a[i][1]+sh*(a[i][0]-fx);
}
}
output();
delay(10);
menu();
}
void reflection()
{
output();
for(i=0;i<=n;i++)
{
temp=a[i][0];
a[i][0]=a[i][1];
a[i][1]=temp;
}
output();
delay(10);
menu();
}
void main()
{
int gd=DETECT,gm;
initgraph(&gd,&gm,"c:\\tcplus\\bgi");
menu();
getch();
}
OUTPUT
2. Rotation
3. Scaling
4. Shearing
5. Reflection
6. Exit
TRANSLATION
Enter the choice : 1
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
Enter the translation vector Tx, Ty : 90 60
ROTATION
Enter the choice : 2
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
SCALING
Enter the choice : 3
Enter the number of Vertices: 3
Enter the coordinates : 30 150 10 200
Enter the coordinates : 10 200 60 200
REFLECTION
Enter the choice : 5
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]
Result:
Thus the program is executed successfully.
3 comments:
Nice blog!! I was looking for blogs related of Engineering Lab Equipment supplier, then i found this blog. This is really nice and interested to read. thanks to author for sharing this type of information.
Do you need Digital Pyrometer, best-infrared thermometer, high-temperature pyrometer or optical pyrometer well we "Maxwell" is leading Digital Pyrometer Manufacturer in India and providing various Pyrometer services at the reasonable price so just contact us at +91 9810346000 moreover you can visit us https://www.maxwelltips.com
VINTAGE RATING TIPS TO PRAGMATIC BACK | The Tatters
VINTAGE RATING TIPS TO PRAGMATIC BACK titanium chords · SEGA Master System · apple watch titanium Saturn · Sega Genesis · Sega Saturn · ford escape titanium for sale Super Nintendo · Super NES · Super Famicom babyliss pro nano titanium straightener · Super Famicom titanium cup
Post a Comment