• Create Account

### #Actualalvaro

Posted 28 April 2012 - 05:49 PM

First of all, rotating by using atan2, adding an angle and then using sine and cosine to get coordinates is a very inefficient way to perform 2D rotations. That's actually the same procedure I came up with when I did this kind of thing the first time around, at the age of 13. So many memories...

So here's the better way:
new_x = old_x * cos(angle) - old_y * sin(angle)
new_y = old_x * sin(angle) + old_y * cos(angle)

With that out of the way, what your code is doing is composing three rotations around axes. You haven't explained why you think the results are incorrect. Chances are your intuitions about rotations are a bit off and the code is working just fine.

So what's an example of inputs into this function that produce output that you consider incorrect? What result did you expect instead?

### #2alvaro

Posted 28 April 2012 - 05:48 PM

First of all, rotating by using atan2, adding an angle and then using sine and cosine to get coordinates is a very inefficient way to perform 2D rotations. That's actually the same procedure I came up with when I did this kind of thing the first time around, at the age of 13. So many memories...

So here's the better way:
new_x = old_x * cos(angle) - old_y * sin(angle)
new_y = old_x * sin(angle) + old_y * cos(angle)

With that out of the way, what your code is doing is composing three rotations around axes. You haven't explained why you think the results are incorrect. Chances are your intuitions about rotations are a bit off and the code is working just fine.

So what's an example of inputs into this function that has a result that you consider incorrect? What result did you expect instead?

### #1alvaro

Posted 28 April 2012 - 05:47 PM

First of all, rotating by using atan2, adding an angle and then using sine and cosine to get coordinates is a very inefficient way to perform 2D rotations. That's actually the same procedure I came up with when I did this kind of thing the first time around, at the age of 13.

So here's the better way:
new_x = old_x * cos(angle) - old_y * sin(angle)
new_y = old_x * sin(angle) + old_y * cos(angle)

With that out of the way, what your code is doing is composing three rotations around axes. You haven't explained why you think the results are incorrect. Chances are your intuitions about rotations are a bit off and the code is working just fine.

So what's an example of inputs into this function that has a result that you consider incorrect? What result did you expect instead?

PARTNERS