"Absolute" rotation of a mesh

Hi,

I’ve made a polygon with a set of points and i’d like to know the “absolute” rotation of the resulted mesh, thats to say the three values of the rotation of the mesh compared to the origin [0,0,0]

Here’s my PG : https://playground.babylonjs.com/#WM8ZHJ#16

Is it possible to do that ?

Thanks in advance,

Boris

I believe that mesh.absoluteRotationQuaternion() will do this.
Returns the current mesh absolute rotation - Mesh | Babylon.js Documentation

Thanks for your answer but i don’t think so.

Here’s the PG with a console.log and the absolute rotation Quaternion is equal to {0,0,0,1} which does not represents the angles of my mesh.

chatGPT’s advice

To determine the “absolute” rotation of a polygon mesh compared to the origin [0, 0, 0], you can calculate the rotation angles around the three axes (x, y, and z) using the mesh’s normal vectors.

  1. Calculate the average normal vector of all the polygons in the mesh. This can be done by summing up the normal vectors of each polygon and normalizing the result.
  2. Convert the normal vector to Euler angles, which represent rotations around the x, y, and z axes. The conversion method depends on the coordinate system and conventions used in your specific application or programming language.
  3. The resulting Euler angles will give you the rotation values around the x, y, and z axes. These angles represent the “absolute” rotation of the mesh compared to the origin [0, 0, 0].

Note that this method assumes that the mesh is oriented in a way that aligns with the global coordinate system, and the normal vectors of the polygons accurately represent the mesh’s orientation.

3 Likes

What do you mean by:

?

Your mesh has no rotation, so the quaternion is the identity quaternion (0,0,0,1).

I’ve found the answer with the help of @CodingCrusader

The “rotation” of my mesh related to the three axes is represented by the normal of the surface

2 Likes

Sorry, i thought i had found the solution but i did not totally.

My final purpose is to have the box tangent to the polygon like that :

image

I have the normal of the polygon but i do not know how to compute that.

Here’s my PG : https://playground.babylonjs.com/#WM8ZHJ#19

Thanks for your answer.

I would first draw the normals like in this example to orient myself about the current situation. Babylon.js Playground (babylonjs-playground.com)

Next I would search or ask the chatbot to give me the formula to calculate the tangenz between two vectors:

To calculate the tangent of the angle between two vectors, you first need to find the dot product of the vectors and their magnitudes. Here are the steps:

  1. Calculate the dot product of the two vectors: DotProduct = Vector1 · Vector2 (Note: · denotes the dot product)
  2. Calculate the magnitudes of the vectors: Magnitude1 = |Vector1| Magnitude2 = |Vector2| (Note: | | denotes the magnitude or length of a vector)
  3. Calculate the tangent of the angle between the vectors: Tangent = DotProduct / (Magnitude1 * Magnitude2)

The resulting value, “Tangent,” will give you the tangent of the angle between the two vectors.

Yes, I agree but what are my two vectors ?

You can calculate the vector of the box with the roations on the axis.