# rotateAround question

Hello everyone,

I’m a struggling with the TransformNode.rotateAround method

`rotateAround(point: BABYLON.Vector3, axis: BABYLON.Vector3, amount: number)`

the spec says :
“Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space.”

Yet, as far as I can figure out, the axis and the point of origin seems to be in “local space” not world space

It’s a bit confusing.

I’ve made a PG, maybe some of you can help me better understand this.

https://www.babylonjs-playground.com/#8LFTCH#302

Is it normal ? only a documentation error ?

Best

Pinging @JohnK who is our space expert

Will have a look but will be tomorrow now.

2 Likes

Hope this explains that the axis and point are in world space https://playground.babylonjs.com/#Z3W74Y#57

The point and the axis together define the line that the mesh will rotate about.

Rotate Around works like this, in world space:

From the current position of the mesh imagine a line that meets, and is perpendicular to, the line defined by the point and the axis. The place where they meet will be the center of rotation and the rotation will take place in a plane that passes through the mesh position and whose normal is the axis.

Have fun trying out any vector for the position of the point and any vector to replace the BABYLON.Axis.X vector.

I’m sorry, I still think it’s not world space
The axis seem to require “parent local space”, and not “world space”.

Your rotating object has no parent … so “parent local space” == “world space” !

Just add a parent to it with some scaling, and Voila ! rotation is messed up (lines 25-27)

https://playground.babylonjs.com/#Z3W74Y#58

Well of course! Adding a parent has changed the frame of reference. The world space of the pilot is now its parent local space.

https://playground.babylonjs.com/#Z3W74Y#59

Scaling the TransformNode by 0.5 means that the point (8, 1, 1) in the now world space of the pilot becomes the point (4, 0.5, 0,5) in Babylon world space and the marker and line have to be adjusted accordingly to draw them in the Babylon world space.

None scaled version complete with wire frame box for ref. https://playground.babylonjs.com/#Z3W74Y#60

To be mathematically correct then

Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space.

Should be

Rotates the mesh around the line defined by the point and axis vector for the passed angle (amount) expressed in radians, in the plane determined using the axis as the plane normal and the position of the mesh as a point on the plane in the frame of reference used to describe the point, axis and mesh position .

I think generally that any description for any object within the API that uses the phrase ‘world space’ means that the object position, rotation and scale is in Babylon world space and any action and vector parameters are in that space also. The change of frame of reference by the use of parents or any other means on the object means that the user needs to consider that the working space for the object has changed.

OK… I get it now. We just don’t agree on the meaning of “world space”

The way I learned 3D, and the way i’ve seen it applied in every other engines : the term “world space” has a meaning : it’s the main frame of reference, the one in which all other are expressed by matrix composition. It is shared by all objects.
I’m guessing it’s what babylon calls “absolute coordinates”.

When you say : “The world space of the pilot is now its parent local space.” I simply disagree on a sementic level.

Anyway, I now have my answer. It’s a semantic problem and not a mathematical one.

However, one last playground with a behavior I don’t realy understand.
Using the same parenting as before, but changing rotation and position of the parent, NOT scale, will keep the rotation working properly. Based on what you just said, It should not.

https://playground.babylonjs.com/#Z3W74Y#63

Please note in your PG #63 in lines 26 to 31 you use X, Y, Z rather than x, y, z and so they have no affect on the results.

I would say that is what is meant by world space in the comment Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space.

It is when you add a parent to the mesh things change.

You are correct and unless we agree on terminology there will always be confusion. In the end it all comes down to the coding used for the rotateAbout method. All I am doing is examining what happens in the various situations you are stating and trying to describe what happens and how and why the actions are what they are. There are multiple frames of reference being used and really we need to define and be clear about each of them.

Frame of reference 1, the, as you say, the main frame of reference the world space
Frame of reference 2, the object local space, usually on creation of an object the local space origin is the world space position of the object and local axes directions match those of the world space
Frame of reference 3, the object-world space with origin the world space position of the object and object-world axes matching the world space axes

So it looks like when you add a transform node as a parent the rotateAbout is applied in frame of reference 3

This PG applies not rotation to the transform node only a translation and only a translation is applied to the marker point and the line https://playground.babylonjs.com/#Z3W74Y#64

What happens if the transform node is translated and rotated https://playground.babylonjs.com/#Z3W74Y#65 ? You are right in that rotateAbout is taking place in frame of reference 3 the object-world space

My statement should be amended to

Well of course! Adding a parent has changed the frame of reference. The frame of reference of the pilot is now the parent_world space.

Which in many ways makes the API more reflective of the situation. Rx

3 Likes

Please note in your PG #63 in lines 26 to 31 you use X, Y, Z rather than x, y, z and so they have no affect on the results.

Well… indeed… Old habits from my C# engine…