Help with sattelite rotation

Guys, can you help me to make rotation of ball around white line be evenly?

I’ve tried to use 2d rotation method but it works bad when line is rotating.

Here is a current version https://www.babylonjs-playground.com/#LWSI5A#6
look at line 108

Looks like it is hitting a Gimbal lock state at specific points. You can usually get around this by nesting inside a node and having the outer node rotate one axis while the other rotates the other.

This might be of help Rotate Around an Axis About a Point - Babylon.js Documentation

I’ve made a progress with this function (make quaternion from normal vector)
Original from GitHub - mattdesl/three-quaternion-from-normal: Builds a ThreeJS quaternion from a normal vector

    var axis = BABYLON.Vector3.Zero();
    function setDirection(normal, quaternion) {    
        quaternion = quaternion || new BABYLON.Quaternion();

        axis.set(normal.z, 0, -normal.x).normalize();
        var radians = Math.acos(normal.y);

        quaternion = BABYLON.Quaternion.RotationAxisToRef(
            axis, radians, quaternion
        );

        return quaternion;
    }

Here is a result https://www.babylonjs-playground.com/#LWSI5A#8

It’s almost ok, but in one position rotation accelerates. Not sure why it is, but it is not critical for me.
Perhaps this solution will also be useful to someone.

it’s a good point, but what if I have only position (vector) value, not mesh. All that pivot functions not work with simple vector value. So I need clean math function for a vector only

@JohnK ah, sorry, I was wrong, I missed a TransformNode that invented special for these purposes

made a correct solution in “babylon.js way” https://www.babylonjs-playground.com/#LWSI5A#9 and it works perfect

thank you very much!

1 Like

But it is not working for static position =(
May be you have ideas how to solve it?

Made a “hack” version https://www.babylonjs-playground.com/#LWSI5A#10
is it possible to rotate axis and keep position of green line in sync whith it without rotation (lie on of two one)?

yet another attempt to solve it :slight_smile: this time with analogue to THREE.Quaternion().setFromUnitVectors function (taken from here)

    function setFromUnitVectors(v1, v2) {
        var angle = Math.acos(BABYLON.Vector3.Dot(v1, v2));
        var axis = BABYLON.Vector3.Cross(v1, v2);
        var quaternion = BABYLON.Quaternion.RotationAxis(axis, angle);
        return quaternion;
    }

https://www.babylonjs-playground.com/#LWSI5A#13

and seems like it is OK now. I hope it is over. Sorry for flooding messages :slight_smile:

2 Likes