0
575views
Write a program in object oriented language for 2D transformation which include functions (i) translation in X direction (ii) Rotation
1 Answer
0
0views

Answer:

void main()
{
  int x1,y1,x2,y2,x3,y3,option;
  float tx;
  float deg,th;
  float xt1,yt1,xt2,yt2,xt3,yt3;
  int gdriver = DETECT,gmode;
  initgraph(&gdriver,&gmode,”C:\TC\BGI”);
  cout<<“Enter coordinates of a triangle: “;
  cin>>x1>>y1>>x2>>y2>>x3>>y3;
  line(x1,y1,x2,y2);
  line(x2,y2,x3,y3);
  line(x3,y3,x1,y1);
  cout<<“\nEnter 1 for Translation, or 2 for Rotation : “;
  cin>>option;
  if(option==1)
  {
    cout<<“Enter tx: “;
    cin>>tx;
    xt1=x1+tx;
    yt1=y1;
    xt2=x2+tx;
    yt2=y2;
    xt3=x3+tx;
    yt3=y3;
    line(xt1,yt1,xt2,yt2);
    line(xt2,yt2,xt3,yt3);
    line(xt3,yt3,xt1,yt1);
  }
  else if(option==2)
  {
    cout<<“Enter angle: “;
    cin>>deg;
    th = deg*3.14/180;
    xt1 = x1*cos(th)-y1*sin(th);
    yt1 = x1*sin(th)+y1*cos(th);
    xt2 = x2*cos(th)-y2*sin(th);
    yt2 = x2*sin(th)+y2*cos(th);
    xt3 = x3*cos(th)-y3*sin(th);
    yt3 = x3*sin(th)+y3*cos(th);
    line(xt1,yt1,xt2,yt2);
    line(xt2,yt2,xt3,yt3);
    line(xt3,yt3,xt1,yt1);
  }
  else
  {
    cout<<“Invalid choice”;
  }
    getch();
}
Please log in to add an answer.