I have a line segment joining two 3D points AB, and a vector V which is normal to it.
I need to know the angle of AB in the plane described with V as the plane normal, that is: in the plane of the two vectors (AB) and (AB cross-product V)
The points A and B (red dots) have x,y coordinates in the camera image, and an extrapolated depth (z) from the camera itself. The vector V (white line) is calculated from two more points with the same process. I have successfully matched rotation around the Z axis (camera view direction) so a (Unity) 3D object will track the wrist angle as it 'waves' (rotation in that single plane). Now I want to also include twisting motion defined as rotation around the wrist bone (blue ellipse attempting to represent rotation in a plane) like tipping a cup. This image is from a fixed webcam, but I would like the process to also work from a mobile phone (moving camera, with translation and rotation potentially) and one of my assumptions has been that if everything is camera relative via the screen projection, this will be automatically included.
By using a 'dumb as bricks' approach I have it working when the arm is horizontal... I can't work out how to make it work at other angles e.g. vertical:
Vector3 AB = (B - A); return -Mathf.Atan2(AB.z, AB.y) * Mathf.Rad2Deg;
UPDATE3: This question now seems to have two parts:
- what can I use as a fixed reference direction when the plane can be orientated in any direction?
- how do I get an angle between that fixed reference and the line in that plane?
In searching I've come across both Rogrigues' Rotation Formula and this answer about rotating planes, but I haven't been able to work out how to apply either of them to this particular problem (I do feel like I'm missing a really obvious trick!)
Edit: My first idea is to rotate A and B so that V is aligned with the cartesian X axis and (ABxV) is aligned with Y, then use atan2(dy, dz). I have just started to look for a working solution to performing that rotation. Edit2: It's been pointed out referring to a cartesian X axis is ambiguous... I'm not sure but I think camera axis (horizontal/vertical in the image plane plus depth) might serve?
An alternative description of the geometry is that I have a cylinder with its long axis aligned with V, and the points A,B are opposite sides of the end-cap circumference... and I need to know the rotation of the cylinder around its long axis described by AB (relative to any arbitrary consistent 0 angle).
UPDATE: In case it breaks assumptions, my values are all measurements from a live camera, so the 'normal' vector V may not be exactly normal to AB... it should always be pretty close though (within a few degrees).