Andrei Krotkov
Andrei Krotkov

Reputation: 5684

Signed Angle in 3D Vectors

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?

Upvotes: 1

Views: 1199

Answers (5)

CHaskell2
CHaskell2

Reputation: 100

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.

Upvotes: 1

Nosredna
Nosredna

Reputation: 86206

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?

Upvotes: 0

caskey
caskey

Reputation: 12695

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.

Upvotes: 0

James Black
James Black

Reputation: 41858

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.

Upvotes: 0

Reed Copsey
Reed Copsey

Reputation: 564413

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.

Upvotes: 0

Related Questions