Rotation problem

• 12-11-2003
planet_abhi
Rotation problem
Below is the code to rotate a triangle to specified angle but it can't.
what is the problem?

Code:

``` # include<graphics.h> # include<conio.h> # include<math.h> # include<stdio.h> # include<process.h> # include<iostream.h> # include<dos.h> float x1=40,y1=360,x2=80,y2=360,x3=60,y3=260; void dgrid(void); void draw_image(int ,int ,int,int,int,int); void info(void); void trans(void); void scale(void); void rotate(); int main() { int gd=0,gm=0; initgraph(&gd,&gm,"e:\\tc\\bgi"); char ch; int flag=0; cleardevice(); draw_image(x1,y1,x2,y2,x3,y3); info(); do { ch=getch(); switch(ch) { case 'T' | 't': outtextxy(80,447,"Translate"); trans(); break; case 'R' | 'r': outtextxy(340,447,"  Roatating"); rotate(); break; case 'S' | 's': outtextxy(240,447,"Scaling"); scale(); break; case 'e' | 'E': flag=1; break; default : float tone[7]={130.81,146.83,164.81,174.61,196,220,246.94}; for(int i=0;i<=7;i++) { sound(tone[i]*7); delay(30); } nosound(); } }while(flag==0); closegraph(); restorecrtmode(); return(0); } void dgrid(void) { setfillstyle(SOLID_FILL,RED); circle(30,400,4); floodfill(31,399,15); line(30,0,30,420); line(10,400,636,400); setfillstyle(HATCH_FILL,GREEN); floodfill(120,100,WHITE); outtextxy(12,370,"Y"); outtextxy(632,410,"X"); outtextxy(7,50,"50"); outtextxy(7,100,"100"); outtextxy(7,150,"150"); outtextxy(7,200,"200"); outtextxy(7,250,"250"); outtextxy(7,300,"300"); outtextxy(7,350,"350"); } void draw_image(int a,int b,int c,int d,int e,int f) { cleardevice(); dgrid(); line(a,b,c,d); line(c, d, e, f); line( a, b, e, f); } void info() { outtextxy(59,467,"T : Translate        S : Scale        R : Rotate        E : Exit"); } void trans(void) { //works } void scale(void) { //works } void rotate() { int angle; outtextxy(340,410,"Enter Angle"); cin>>angle; angle=(angle*3.14)/180; x1=x1*cos(angle)+y1*sin(angle); y1=-x1*sin(angle)+y1*cos(angle); x2=x2*cos(angle)+y2*sin(angle); y2=-x2*sin(angle)+y2*cos(angle); x3=x3*cos(angle)+y3*sin(angle); y3=-x3*sin(angle)+y3*cos(angle); draw_image(x1,y1,x2,y2,x3,y3); info(); }```

also i want to get input from user at the bottom of screen what shuold i do?
• 12-11-2003
...
i dont know how much this will help, but....

i was running into a similar problem rotating a bitmap to point at the mouse cursor. i stressed over a solution and had people from all over trying to figure out how to do it.

then yesterday i was sitting at my computer programming, when it hit me... all of this stuff we were trying to do with vectors and whatever else, i was able to reduce to one line of code.

Code:

```rotation = - atan2( mouse_y - (screen_height / 2),                       mouse_x - (screen_width / 2) );```
thats the rotation of the bitmap in radians. i didnt use graphics.h ( which i believe is the borland graphics library, correct me if im wrong ); mine was done in directx. but that one line of code was able to point the bitmap (which was always in the center of the screen) to the mouse pointer.