/* This program will rotate an object ( triangle) using an arbitrary point */
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int i,xmid,ymid,x1,y1,x2,y2,x3,y3,x,y,dy,dx,p,gap=50,temp,xr,yr;
int x1dash,y1dash,x2dash,y2dash,x3dash,y3dash;
float m;
double theta;
char str[5];
clrscr();
initgraph(&gd,&gm,"..\\bgi");
printf("Enter first co-ords of the triangle\n");
scanf("%d %d",&x1,&y1);
printf("Enter second co-ords of the triangle\n");
scanf("%d %d",&x2,&y2);
printf("Enter third co-ords of the triangle\n");
scanf("%d %d",&x3,&y3);
xmid= getmaxx()/2;
ymid= getmaxy()/2;
line(5,ymid,getmaxx()-5,ymid);
line(xmid+3,5,xmid+3,getmaxy()-5);
for( i= xmid+gap;i<getmaxx()-5;i=i+gap)
{
outtextxy(i,ymid-3,"|");
itoa(i-xmid,str,10);
outtextxy(i,ymid+3,str);
}
for( i= ymid-gap;i>5;i=i-gap)
{
outtextxy(xmid,i,"-");
itoa(ymid-i,str,10);
outtextxy(xmid+5,i,str);
}
for( i= xmid-gap;i>5;i=i-gap)
{
outtextxy(i,ymid-3,"|");
itoa(-(xmid-i),str,10);
outtextxy(i-6,ymid+3,str);
}
for( i= ymid+gap;i<getmaxy()-5;i=i+gap)
{
outtextxy(xmid,i,"-");
itoa(-(i-ymid),str,10);
outtextxy(xmid+8,i,str);
}
line(x1+xmid,ymid-y1,x2+xmid,ymid-y2);
line(x2+xmid,ymid-y2,x3+xmid,ymid-y3);
line(x3+xmid,ymid-y3,x1+xmid,ymid-y1);
printf("Enter the degree to rotate");
scanf("%lf",&theta);
theta= ((float) theta *3.14f )/(float)180; // converting theta to radian
printf("Enter the arbitrary point to rotate");
scanf("%d%d",&xr,&yr);
x1dash=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
x2dash=xr+(x2-xr)*cos(theta)-(y2-yr)*sin(theta);
x3dash=xr+(x3-xr)*cos(theta)-(y3-yr)*sin(theta);
y1dash=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
y2dash=yr+(x2-xr)*sin(theta)+(y2-yr)*cos(theta);
y3dash=yr+(x3-xr)*sin(theta)+(y3-yr)*cos(theta);
line(x1dash+xmid,ymid-y1dash,x2dash+xmid,ymid-y2dash);
line(x2dash+xmid,ymid-y2dash,x3dash+xmid,ymid-y3dash);
line(x3dash+xmid,ymid-y3dash,x1dash+xmid,ymid-y1dash);
getch();
closegraph();
}
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
void main()
{
int gd=DETECT,gm;
int i,xmid,ymid,x1,y1,x2,y2,x3,y3,x,y,dy,dx,p,gap=50,temp,xr,yr;
int x1dash,y1dash,x2dash,y2dash,x3dash,y3dash;
float m;
double theta;
char str[5];
clrscr();
initgraph(&gd,&gm,"..\\bgi");
printf("Enter first co-ords of the triangle\n");
scanf("%d %d",&x1,&y1);
printf("Enter second co-ords of the triangle\n");
scanf("%d %d",&x2,&y2);
printf("Enter third co-ords of the triangle\n");
scanf("%d %d",&x3,&y3);
xmid= getmaxx()/2;
ymid= getmaxy()/2;
line(5,ymid,getmaxx()-5,ymid);
line(xmid+3,5,xmid+3,getmaxy()-5);
for( i= xmid+gap;i<getmaxx()-5;i=i+gap)
{
outtextxy(i,ymid-3,"|");
itoa(i-xmid,str,10);
outtextxy(i,ymid+3,str);
}
for( i= ymid-gap;i>5;i=i-gap)
{
outtextxy(xmid,i,"-");
itoa(ymid-i,str,10);
outtextxy(xmid+5,i,str);
}
for( i= xmid-gap;i>5;i=i-gap)
{
outtextxy(i,ymid-3,"|");
itoa(-(xmid-i),str,10);
outtextxy(i-6,ymid+3,str);
}
for( i= ymid+gap;i<getmaxy()-5;i=i+gap)
{
outtextxy(xmid,i,"-");
itoa(-(i-ymid),str,10);
outtextxy(xmid+8,i,str);
}
line(x1+xmid,ymid-y1,x2+xmid,ymid-y2);
line(x2+xmid,ymid-y2,x3+xmid,ymid-y3);
line(x3+xmid,ymid-y3,x1+xmid,ymid-y1);
printf("Enter the degree to rotate");
scanf("%lf",&theta);
theta= ((float) theta *3.14f )/(float)180; // converting theta to radian
printf("Enter the arbitrary point to rotate");
scanf("%d%d",&xr,&yr);
x1dash=xr+(x1-xr)*cos(theta)-(y1-yr)*sin(theta);
x2dash=xr+(x2-xr)*cos(theta)-(y2-yr)*sin(theta);
x3dash=xr+(x3-xr)*cos(theta)-(y3-yr)*sin(theta);
y1dash=yr+(x1-xr)*sin(theta)+(y1-yr)*cos(theta);
y2dash=yr+(x2-xr)*sin(theta)+(y2-yr)*cos(theta);
y3dash=yr+(x3-xr)*sin(theta)+(y3-yr)*cos(theta);
line(x1dash+xmid,ymid-y1dash,x2dash+xmid,ymid-y2dash);
line(x2dash+xmid,ymid-y2dash,x3dash+xmid,ymid-y3dash);
line(x3dash+xmid,ymid-y3dash,x1dash+xmid,ymid-y1dash);
getch();
closegraph();
}
If the arbitrary point is (320,240) and the rotating angle is 90.
ReplyDeleteThen it's not rotating..
Kindly give the solution of the problem.
just change values while converting theta into radian ....theta=(theta*6.2832)/360....hope so it will work
Deletedo u have c++ code of same programs for Ubuntu OS.
ReplyDelete