Tuesday, 15 April 2014

C++ Program to rotate a line

/*Program to rotate a line*/
#include<iostream.h>
#include<conio.h>
#include<graphics.h>
#include<math.h>
main()
{
int gd=DETECT,gm,x1,y1,a,b;
float sinth,costh,x2,y2;
initgraph(&gd,&gm,"c:\\turboc3\\bgi");
cout<<"enter line cordinates";
cin>>x1>>y1>>x2>>y2;
line(x1,y1,x2,y2);
cout<<"enter angle";
cin>>a;
costh=cos((3.14*a)/180);
sinth=sin((3.14*a)/180);
cout<<"enter 1 for anticlockwise or 0 for clockwise rotation";
cin>>b;
if(b==1)
{
x2=(x2*costh)-(y2*sinth);
y2=(x2*sinth)+(y2*costh);
line(x1,y1,x2,y2);
}
else
{
x2=(x2*costh)+(y2*sinth);
y2=(y2*costh)-(x2*sinth);
line(x1,y1,x2,y2);
}
getch();
closegraph();
}

No comments:

Post a Comment