Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

I recently started with 2d transformations in my class. I was just working with a program when I realized the formula I am using rotates the object spirally inwards. I have no idea whats over about this. I expected my figures to be rotated about a point but rather they all deform with every degree of rotation. I used a single point & realized that the point was moving spirally inwards with every degree I moved.

Can someone help me & let me know why it falls in rather than following circle or if that is what is expected of 2d rotation. I somehow felt its something related to how we view in 2d plane (or the imaginary z index here) but simply can't get around it.

I am following wiki & talking about this :

alt text

x' = xcosθ − ysinθ

y' = xsinθ + ycosθ

share|improve this question
    
This question might be better suited for stackoverflow.com. You also need to show the code you have. Most likely it is a precision issue/bug. Mathematically, there is no reason for it to spiral inwards. ($x^2 + y^2$ should not change). –  Aryabhata Oct 4 '10 at 16:00
    
I should have...well its a pity I considered my code out of doubt & came running to join math.SE for this problem. I guess shows my dread for maths :) –  loxxy Oct 4 '10 at 16:30

1 Answer 1

up vote 7 down vote accepted

My guess is that this is a very classic error in computer graphics implementation; you have to make sure that you don't accidentally use the new value of X when computing the new value of y! For instance, this code:

x = x*cos(theta) - y*sin(theta);
y = x*sin(theta) + y*cos(theta);

will actually perform the following operation:

x' =x cos θ - y sin θ
y' = x cos θ sin θ + y (cos θ - sin2θ)

and for small values of θ (i.e., incremental rotation) will generally cause the point <x,y> to spiral in towards <0,0>.

share|improve this answer
    
Beautiful! I would have probably revised my whole math for this...Thank you so much. –  loxxy Oct 4 '10 at 16:27
    
Like magic! Correct diagnosis from almost zero information. Thanks for posting that. –  T.. Oct 4 '10 at 17:43
    
"very classic" - :D Yes, I've been bitten by that error too back in the day. +1 –  J. M. Oct 4 '10 at 23:24

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.