Rotate instances around a point
Hello,
I have multiple text instances which are positioned using the coordinates of a sphere. I like to rotate each instance around the centre point of the sphere so that the text still faces outward and is oriented the right way up. Any suggestions?
Thank!
Multiple answers to this.
But before starting, remainder that there are two ways to rotate shapes in [jit.gl.multiple], either by providing a 4-plane matrix with an angle and an axis of rotation (rotate attribute), either by providing a 3-plane matrix with rotations along X, Y and Z axis (rotatexyz attribute).
In your case (orientating shapes along the surface of a sphere), first approach can be relatively easy to implement assuming you have the normal vectors for each point. In a perfect sphere with (0,0,0) as origin, normals are nothing more than the position vertices, normalized. But since your sphere is slightly squished, this won't work perfectly.
So I came up with multiple solutions.
The simplest one is to use rotatexyz and compute the rotation along only one axis (Y). This is pretty straightforward with [cartopol], but might not give the exact desired result:

This kinda works, but all words remain perfectly vertical.
To get the rotation perfectly matching the squished sphere surface, you need more math. Also, position alone isn't enough, you also need normals (ie in which direction a shape should point toward). [jit.gl.gridshape] gives you normals, but since you modify the position vertices, the normals it gives no longer match the new shape.
From this point, you could assume that your squished sphere is close enough to a perfect sphere and still consider that normals and normalized positions are the same thing, in which case you can compute the angle-axis rotation using a bit of vector maths (I always struggle with that myself so I got a bit of help from Claude to generate the jit.gen code):

It's a bit better, but you'll notice that as you get further away from the equator, the orientation of the text gets a bit wrong (it would be perfectly right if the sphere wasn't squished, ie. if you removed this [* 0.5] in your first [jit.gen]).
Finally, for a true "perfect" rotation, we really need the corrected normals. Instead of computing them ourselves, I suggest to change the way you generate your initial sphere, and make use of the new jit.geom objects:

Notice that the way we compute the rotation from the normals didn't changed, we just have proper normals to start with.
That's one way but there are multiple others. Like you could use this trick to compute the rotation from the normals by using [jit.anim.node] internal math instead of doing it yourself in [jit.gen].