C Program for 2D Transformation (Translation, Rotation and Scaling)

Program /* This program is for the transformation of 2D shape (Triangle) for other shape edit only shape codes 1. Translation 2. Rotat...

Program

/*
This program is for the transformation of 2D shape (Triangle) for other shape edit only shape codes
1. Translation
2. Rotation
3. Scaling
Here,
x1,x2,x3,y1,y2,y3 variable to draw triangle.
x11,x22,x33,y11,y22,y33 variables are for new position of triangle.
sfx and sfy are scaling factor.
tpx and tpy are for translation point.
ang is for angle for rotation and t variable is use for angle in radian.
a and b is for arbitary point
c for choice/option.
*/

#include <graphics.h>
#include <stdio.h>
#include <conio.h>
#include<math.h>
void main()
{
int gm,gd=DETECT,midx,midy,c;
float x1,x2,x3,y1,y2,y3,x11,x22,x33,y11,y22,y33,sfx,sfy,tpx,tpy,ang,t,a,b;
clrscr();
initgraph(&gd,&gm,"..\\bgi");
midx=getmaxx()/2;
midy=getmaxy()/2;
line(midx,0,midx,getmaxy());
line(0,midy,getmaxx(),midy);
printf("2D Translation, Rotation and Scaling\n");
printf("Enter the points (x1,y1), (x2,y2) and (x3,y3) of triangle\n");
scanf("%f%f%f%f%f%f",&x1,&y1,&x2,&y2,&x3,&y3);
setcolor(WHITE);
line(midx+x1,midy-y1,midx+x2,midy-y2);
line(midx+x2,midy-y2,midx+x3,midy-y3);
line(midx+x3,midy-y3,midx+x1,midy-y1);
printf("\n 1.Transaction\n 2.Rotation\n 3.Scalling\n 4.exit\n");
a:  printf("Enter your choice:");
scanf("%d",&c);
switch(c)
{
case 1:
printf("Enter the translation factor\n");
scanf("%f%f",&tpx,&tpy);
x11=x1+tpx;
y11=y1+tpy;
x22=x2+tpx;
y22=y2+tpy;
x33=x3+tpx;
y33=y3+tpy;
setcolor(RED);
line(midx+x11,midy-y11,midx+x22,midy-y22);
line(midx+x22,midy-y22,midx+x33,midy-y33);
line(midx+x33,midy-y33,midx+x11,midy-y11);
break;

case 2:
printf("Enter the angle of rotation\n");
scanf("%f",&ang);
printf("Enter rotetion point\n");
scanf("%f%f",&a,&b);
t=3.14*ang/180;
x11=abs(x1*cos(t)-y1*sin(t)+a*(1-cos(t))+b*sin(t));
y11=abs(x1*sin(t)+y1*cos(t)+b*(1-cos(t))-a*sin(t));
x22=abs(x2*cos(t)-y2*sin(t)+a*(1-cos(t))+b*sin(t));
y22=abs(x2*sin(t)+y2*cos(t)+b*(1-cos(t))-a*sin(t));
x33=abs(x3*cos(t)-y3*sin(t)+a*(1-cos(t))+b*sin(t));
y33=abs(x3*sin(t)+y3*cos(t)+b*(1-cos(t))-a*sin(t));
setcolor(BLUE);
line(midx+x11,midy-y11,midx+x22,midy-y22);
line(midx+x22,midy-y22,midx+x33,midy-y33);
line(midx+x33,midy-y33,midx+x11,midy-y11);
break;
case 3:
printf("Enter the scalling factor\n");
scanf("%f%f",&sfx,&sfy);
printf("Enter scaling point\n");
scanf("%f%f",&a,&b);
x11=x1*sfx+a*(1-sfx);
y11=y2*sfy+b*(1-sfy);
x22=x2*sfx+a*(1-sfx);
y22=y2*sfy+b*(1-sfy);
x33=x3*sfx+a*(1-sfx);
y33=y3*sfy+b*(1-sfy);
setcolor(YELLOW);
line(midx+x11,midy-y11,midx+x22,midy-y22);
line(midx+x22,midy-y22,midx+x33,midy-y33);
line(midx+x33,midy-y33,midx+x11,midy-y11);
break;

case 4:
exit(0);
break;

default:
printf("Enter the correct choice\n");
}
goto a;
getch();
}

Output












COMMENTS

Name

Accident Alert,1,AI,2,Array,1,Aurdino,1,C,2,Computer Graphics,9,Data Science,3,Dataset,1,Decoratot,1,Django,1,ESP32,1,Fixed point/iteration method,1,Greater or smaller,1,html,1,Image Processing,1,JAVA,1,Javascript,22,Machine Learning,1,Matlab,3,Numerical Method,13,OOP,1,Other,3,PHP,1,Point operation,1,Python,11,Raspberry pi,1,Recommendation System,1,Regression,1,Reservation System,1,Robotics,1,Simulation,2,sine wave,1,String Handling Function,1,Web scrap,1,Webpage,1,
ltr
item
COMPUTER PROGRAMMING: C Program for 2D Transformation (Translation, Rotation and Scaling)
C Program for 2D Transformation (Translation, Rotation and Scaling)
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqiq0RYdGmVZ-Sz86FDiH8zGIOtnqz8MxTWQAi2BJy9jXcRWlNBLVL6IGPzpqQfIU1bj1tUezdIQNPdH6INOUjRCfwsebMobxZn8YltZ3VkEP4Yoc3eQ919im-MWRt_knmenjj_pEfMXg/s640/1.png
https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqiq0RYdGmVZ-Sz86FDiH8zGIOtnqz8MxTWQAi2BJy9jXcRWlNBLVL6IGPzpqQfIU1bj1tUezdIQNPdH6INOUjRCfwsebMobxZn8YltZ3VkEP4Yoc3eQ919im-MWRt_knmenjj_pEfMXg/s72-c/1.png
COMPUTER PROGRAMMING
https://computerprogram4ru.blogspot.com/2017/10/c-program-for-2d-transformation.html
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/
https://computerprogram4ru.blogspot.com/2017/10/c-program-for-2d-transformation.html
true
8672391763020279633
UTF-8
Loaded All Posts Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy