Talk:Rotating an object about local angles/axes
Jump to navigation
Jump to search
How to use[edit source]
Thank you very much for this nice piece of code.
However, I'm not quite clear about is's usage.
Assuming that I want to rotate an object about it's local z-axis by 30°... how is that supposed to be implemented in the code? Do I just have to add it to the worldAngZ-variable?
Diarrhoe 15:17, 6 June 2011 (EDT)
- Maybe I should have been a little bit clearer. Basically this is an algorithm, meaning that you have an input and an output. The input are the axis order and the local angles; the output are the world angles.
- For your example this algorithm is not necessary, because any rotation about only one axis is always a world rotation already (because the local axes are still orthogonal with the world axes). The conversion from local to world axes becomes necessary if a second angle is changed. E.g. you want to rotate an object about the local Z axis by 30° and have it tilted on the X axis by 45°. If you choose an axis order of 2 = xzy, the object is first rotated about the X angle. The local Z-axis has changed now (it's perpendicular to the x and y axes)! Then the Z rotation is added to the previous rotation.
- Here's how you could implement the example in a script:
- First you need an object to rotate, in this case it's myObject.
- Then you set the desired angles and order.
set localAngX to 45 set localAngY to 0 set localAngZ to 30 set axisOrder to 2
- Then you let the bulk of the code run as it is presented in the article.
set sx to sin localAngX set cx to cos localAngX ... ... ... ... ... set worldAngX to -ATan2 r23 r33 set worldAngY to -ASin r13 set worldAngZ to -ATan2 r12 r11 endif
- Finally apply the calculated world rotation to the object.
myObject.setAngle x worldAngX myObject.setAngle y worldAngY myObject.setAngle z worldAngZ
- You don't manually change the world angles.
- Mind you, this code also works for rotations about a single axis. But it would be wasteful to do a conversion in that case.
- Hope that helps. If not I'll try again. ThePhilanthropy 17:32, 6 June 2011 (EDT)
- All right, I think I got it right now.
- Guess I missunderstood the previous version including getAngle and wondered about the difference between localAngX/Y/Z and worldAngX/Y/Z.
- However, you were right assuming that I meant an additional rotation to an object already rotated about an other axis. I should have made it clearer.
- Thanks for the explanation anyway.
- Diarrhoe 10:59, 7 June 2011 (EDT)
- All right, I think I got it right now.