views:

281

answers:

5

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?

A: 

Is there a way to figure out whether the camera is painting eastward or not?

Yes, it's simple. Just check the appropriate camera vector component. For example, in a RH coordinate system, with Z being up, if cameraVector.X > 0, it's pointing eastward.

Reed Copsey
I wish it were that simple. It's an *arbitrary* coordinate system for a reason. The camera is oriented on a giant sphere, and all I can assume is that the both the direction and the north vector are unit vectors.
Andrei Krotkov
(The up-vector is arbitrary as well)
Andrei Krotkov
But - your coordinate system has to have some type of world coordinate system - all you need to do is check your camera's vector in respect to the world coordinate system. If you know north, and the type of coordinate system, you should know which direction is "east" as well...
Reed Copsey
But he might not be interested in the outer coordinate system. Just as we on Earth are often not interested in how we're moving through the solar system or relative to the galactic center It sounds like he has a "planet" north on his sphere. I'm pretty sure the answer comes down to a couple cross and dot products, but without some sample data to verify his frames of reference, it's just guessing.
Nosredna
A: 

When you initially create the sphere, why not set a variable pointing north, so you can compare the direction of the vector in question with the reference vector that is always pointing north. This way, if you move the camera, then your reference may need to be adjusted, but that is a known quantity, and you still have a reference to determine the direction.

James Black
A: 

Could you elaborate a little bit? I think you might just need to cross your north vector with your forward vector and check the resultant vector's z component. But I admit I might be misunderstanding your situation.


OK. I just read everything (all questions, answers, comments) again.

I think you want to cross forward and north, and then dot that with the vector that goes from the center of the sphere to the location of the camera. Or something.

How about some sample values?

Nosredna
A: 

Unfortunately not using the computation above. One way would be to do a projection of the camera vector onto a D-1 surface tangent to the sphere then examine the resulting vector to see which way it is pointing.

caskey
+1  A: 

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.

CHaskell2