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:

curved paths

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

Popular posts from this blog

Linux vanilla kernel on QEMU and networking with eth0 -

rdbms - what exactly the undo information lives in oracle? -

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -