I rotate a cube around the Y-axis, and I ask rotation to get the arc of rotation, but the arc is in the range of -90 degrees and +90 degrees, how can I get its true rotation Angle at 0-360 degrees
Have a look at this fiddle:
wonderful !!!, Thank you very much
Why do I use this to return values before -90 to 90 degrees, my version of three.js is 94
I know, I calculated the value of ratatiaon I got from the cube, but the value I get is always in the range of -90 to 90. What should I do?
.rotate( angle ) is not a method of
Mesh. What method do you really use?
The reason for the reported output is not easy to explain. Rotations in
three.js are internally represented as quaternions. You maybe worked so far with the
Object3D.rotation property which represents rotation as euler angles. But there is also
Object3D.quaternion. Both properties represent the rotation of the respective object. As soon as you change a property, the other one gets synchronized by
Object3D.rotateY() does internally change
Object3D.quaternion. The synchronization now produces a correct but unexpected euler angle. You can easily see this if you log
Object3D.rotation and not only the y property like in this fiddle.
As you can see, at a certain point the x and z property change and represent a correct rotation together with the y property. AFAIK, there is no API method that allows you to calculate the angle between 0 and 360 degrees. In some sense, this range is unusual since you assume a certain direction of the rotation (CW/CCW). It’s more common to compute the shortest angle between two rotations which lies in the range of 0 and 180 degrees. This can be done with
Quaternion.angelTo() which produces the same result like Unity’s Quaternion.Angle.
The fiddle computes the shortest angle between the default rotation (the object looks along the positive z-axis when no rotation is applied) and the current rotation of an object.
Because I also had problems with the angles, I have dealt a little with the quaternions and angles.
For this I created a visualization. Maybe that’s helpful?
My actual usage scenario is like this, I render a car, but I need to rotate the car, I need to know exactly which direction the car is pointing. Is there any way to achieve this
Is it what you’re looking for?
I verified, this is feasible, thank you very much.