c - Rotating points around another arbitrary point -
given following test code inside function:
int orientation = 0; // increments 359, loops 0 int tempx, tempy; float radians = orientation * (m_pi / 180); tempx = point->x; tempy = point->y; tempx = (int) (tempx * cos(radians) - tempy * sin(radians)); tempy = (int) (tempx * sin(radians) + tempy * cos(radians)); tempx = tempx + origin->x; tempy = tempy + origin->y; with following points (relative origin): (-100, 0), (0, -100), (0, 100) strange plot:

the blue , green lines overlapping paths. intersection @ middle (with barely-visible yellow point) origin. points in correct position when orientation 0 or 180 in non-circular path @ other angles. i've done plenty of linear algebra in time, has me stumped. i'm not sure if i'm overlooking in c itself, or if i'm not seeing problem.
you reusing tempx after rotating it. try following instead:
tempx = (int) (point->x* cos(radians) - point->y* sin(radians)); tempy = (int) (point->x* sin(radians) + point->y* cos(radians)); and see if fixes things or not.
Comments
Post a Comment