R – Signed Angle in 3D Vectors

3dmathopenglvector

This is a purely math question, I believe.

I have a camera object in an arbitrary coordinate system. I have the direction vector of the camera, and I have a vector that points in the direction of north along the surface of the sphere.

I wish to calculate the angle of the camera in regards to the north vector. Is there a simple way to calculate the final sign of the angle? I'm aware than angle = acos(dir dot north), but when I implement it, the angle is clamped to [0,180] degrees. Is there a way to figure out whether the camera is painting eastward or not?

Best Answer

So, N is the north vector, F is the forward vector, V is the vector from the middle of sphere out to the current location of the camera.

N cross V should get you a vector that points eastward (E). Then, I think you just want to project (just dot, since we only care about the sign) F onto E and check the sign. Positive means it's pointing east-ish, zero means it's pointing north or south, negative means it's pointing west-ish.

Depending on what exact question you're asking of the data, you can fiddle with it, but knowing how to grab a vector that means 'east from where I am' should help.

Does this sound right? I'mma bit rusty with this stuff.

Related Topic