2D ROTATION PROBLEM
I want to rotate point P1(100,100) about point P2(0,0) by 90 degree.
My src is like this:
int x = 100;
int y = 100;
float angle = 90*(3.14/180);
do {
x1 = x*cos(angle)-y*sin(angle);
y1 = x*sin(angle)+y*cos(angle);
line(x1,y1,0,0,redcolor);
x = x1;
y = y1;
}while(...);
Why doesn't this work??????? Can sombody out their help me please? Source example might be helpful.
NO FANCY STUFF, Please! I just want straight forward code/info (no matrix and all that).
PS: Does this has to do something about projection? Do I convert x,y before or after?
float angle; int x, y, nx, ny; x = 100; for(angle = 0.0; angle < 6.28; angle += anglei)
const float anglei = 3.14159 / 180.0;
y = 0;
{
nx = x * cos(angle) - y * sin(angle);
ny = x * sin(angle) + y * cos(angle);
line(nx + 160, ny + 100, 0, 0, redcolor);
}
Now...here were your problems...one small issue may have been the cumulative error of rotating a new vector by 90 degrees every time, instead of rotating the same vector by a different angle. Another problem is you weren't translating the lines to somewhere on screen, so 3 of the 4 lines you were drawing would be off screen. Oh well, I hope this helps...It should draw 360 lines, all the way around point (160, 100), one for each degree from 0 to 359.