Original Post
I am using the Mathematics and Physics for Programmers book and Im trying to apply the rotation formula that they give: x = x coord of one of the vertices. y = y coord of one of the vertices. s = the x coordinate of the center of the polygon t = the y coordinate of the center of the polygon @ = how much i want to rotate the polygon in radians x = sqrt(pow((x-s),2)+pow((y-t),2)) * cos(@-atan((y-t),(x-s))) + s; y = sqrt(pow((x-s),2)+pow((y-t),2)) * sin(@-atan((y-t),(x-s))) + t; here is my code that I have so far. I am jusing the Windows GDI to draw everything. Rect is filled with the different vertices. newx and newy is what i used to supply the center of the polygon/triangle I used the constant double because the compiler complained of not knowing which version of the pow cos sin function to use. When degree = 90 this is what the debugger says rect[0] = x=160 y=190 rect[1] = x=108 y=189 rect[2] = x=48 y= 198 When degree = 45 rect[0] = x=157 y=250 rect[1] = x=155 y=196 rect[2] = x=98 y= 186 When degree = 135 rect[0] = x=106 y=101 rect[1] = x=54 y=137 rect[2] = x=48 y= 138 the triangle ends up not rotating correctly and I am not sure why it isnt. [Edited by - Supaflyfrank on January 1, 2007 5:23:35 PM]
void Paddle::DrawPaddle(HDC hDC)
{
HBRUSH hBrush = CreateSolidBrush( RGB(255,0,0));
HGDIOBJ oldbrush = SelectObject(hDC,hBrush);
POINT rect[3];
int degree = 90;
double radian = degree*(PI/180);
rect[0].x = 100;
rect[0].y = 100;
rect[1].x = 150;
rect[1].y = 200;
rect[2].x = 50;
rect[2].y = 200;
double newx = (rect[0].x+rect[1].x+rect[2].x)*.3333333333333333;
double newy = (rect[0].y+rect[1].y+rect[2].y)*.3333333333333333;
rect[0].x = sqrt(pow(rect[0].x-newx,2)+pow(rect[0].y-newy,2))*cos(degree-atan2(rect[0].y-newy,rect[0].x-newx))+newx;
rect[0].y = sqrt(pow(rect[0].x-newx,2)+pow(rect[0].y-newy,2))*sin(degree-atan2(rect[0].y-newy,rect[0].x-newx))+newy;
rect[1].x = sqrt(pow(rect[1].x-newx,2)+pow(rect[1].y-newy,2))*cos(degree-atan2(rect[1].y-newy,rect[1].x-newx))+newx;
rect[1].y = sqrt(pow(rect[1].x-newx,2)+pow(rect[1].y-newy,2))*sin(degree-atan2(rect[1].y-newy,rect[1].x-newx))+newy;
rect[2].x = sqrt(pow(rect[2].x-newx,2)+pow(rect[2].y-newy,2))*cos(degree-atan2(rect[2].y-newy,rect[2].x-newx))+newx;
rect[2].y = sqrt(pow(rect[2].x-newx,2)+pow(rect[2].y-newy,2))*sin(degree-atan2(rect[2].y-newy,rect[2].x-newx))+newy;
Polygon(hDC,rect,3);
SelectObject(hDC,oldbrush);
DeleteObject(hBrush);
}