Update: please check the end of the post I may have found a solution.
I'm making a node tree whose purpose is to tilt the points of a curve so they face a reference object. A Plane is generated from the curve and so it also faces the reference object. I think I am almost there except for a problem of angle calculation.
In the following example, I am attaching a 3D gizmo to the faces of the reference objet (a sphere) as well as the curve points. The idea is to calculate the angle difference on a specific axis between the reference object closest face's normal and a vector of the curve point (here tangent) then set the tilt to that angle. This seems to be working except sometimes some rotations change range such as moving from -64° to 114° when moving the last curve point (the one selected on the example file when opening it).I guess I have to clamp the angles in some way but I am not sure how to prevent them from skipping like this and what the right range should be.
Here is a screen of the last curve point having wrong tilt as well as the node tree applied on the curve:
UPDATE: I have a potential solution for this using quaternions: instead of using Rotation To Euler before subtracting the two angles, I used Rotation To Quaternion. Then I got the W of each quaternion using cos(Z/2) and made the subtract on these. So far it looks good, I'll update the post if I find any issue.