In: Computer Science
2D object transformations(Use NetBeans IDE)
Task: create a program that realizes 2D transformations for 2D
object with at least three
control points:
• Movement
o The user must be able to input the movement step (in
pixels)
o The movement can be controlled with keyboard cursor keys
(←↑→↓)
• Scaling
o The user must be able to input the scaling parameters
o The scaling should be controlled with keyboard keys (for example
"Page
Up", "Page Down")
• Rotation
o The user must be able to input the angle of rotation (in
degrees)
o The user must be able to input a point, around which the object
will rotate
(X, Y)
o Automatic rotation must be implemented, the user pushes a button
and the
object begins to rotate around the given point (animation using
timer)
Hello,
Code :
#include <iostream.h>
#include <conio.h>
#include <graphics.h>
#include <math.h>
int main()
{
int p1=345,q1=120,p2=190,q2=300,p3=120,q3=420,op;
int gdriver = DETECT,gmode;
initgraph(&gdriver,&gmode,”C:\TC\BGI”);
do{
cleardevice();
gotoab(1,1);
line(p1,q1,p2,q2);
line(p2,q2,p3,q3);
line(p3,q3,p1,q1);
cout<<“\n 1.Movement 2.Scaling 3.Rotation 4.Exit \n Select
any option : “;
cin>>op;
switch(op)
{
case 1:
float tp,tq;
cout<<“Enter the movement value of tp & tq: “;
cin>>tp>>tq;
p1+=tp;p2+=tp;p3+=tp;
q1+=tq;q2+=tq;q3+=tq;
break;
case 2:
float sp,sq;
cout<<“Enter the scalling value of sp & sq: “;
cin>>sp>>sq;
p1*=sp;p2*=sp;p3*=sp;
q1*=sq;q2*=sq;q3*=sq;
break;
case 3:
float degree;
cout<<“Enter the angle which you want to rotate: “;
cin>>degree;
degree = degree*3.14/180;
int a,b;
a=p1;b=q1;
p1 = a*cos(degree)-b*sin(degree);
q1 = a*sin(degree)+b*cos(degree);
a=p2;b=q2;
p2 = a*cos(degree)-b*sin(degree);
q2 = a*sin(degree)+b*cos(degree);
a=p3;b=q3;
p3 = a*cos(degree)-b*sin(degree);
q3 = a*sin(degree)+b*cos(degree);
break;
case 4:
break;
default:
cout<<“The option you selected is not valid”;
}
}
while(op!=4);
closegraph();
return 0;
}