When I rotate an object, how do I know its true Angle of rotation

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

Hi!
Have a look at this fiddle:
https://jsfiddle.net/prisoner849/md7L2dn5/
It uses THREE.Math.radToDeg().

1 Like

OK, thanks

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?
···
mesh.rotate(angle)
THREE.Math.radToDeg(mesh.rotation.y)
···

.rotate( angle ) is not a method of Mesh. What method do you really use?

sorry, rotateY

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 three.js.

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.

3 Likes

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?

https://discourse.threejs.org/t/quaternion-axis-angle-visualization/1358

2 Likes

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?
https://threejs.org/docs/index.html#api/en/core/Object3D.getWorldDirection

1 Like

I verified, this is feasible, thank you very much.