Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Yaw, Pitch and Roll from a 3D vector

I have a direction vector that applied to a position gives me the point at which the camera should look. How can I get from that yaw, pitch and roll in order to use glRotatef properly?

Thanks in advance

like image 462
Jack Avatar asked May 06 '10 16:05

Jack


People also ask

How do I find my yaw?

Measurement. Yaw velocity can be measured by measuring the ground velocity at two geometrically separated points on the body, or by a gyroscope, or it can be synthesized from accelerometers and the like. It is the primary measure of how drivers sense a car's turning visually.

What is pitch yaw and roll on a robot?

Pitch is a counterclockwise rotation of m about the y-axis. Roll is a counterclockwise rotation of s about the x-axis. Source publication. A strategy for heterogeneous multi-robot self-localization system.


2 Answers

None of these equations are 'wrong' but all are a little clumsy. Ryder052, you example does not account certain cases as you've commented. Why not use atan2?

Given unit (normalized) direction vector d

pitch = asin(-d.Y);
yaw = atan2(d.X, d.Z)
like image 200
dreamwagon Avatar answered Sep 23 '22 15:09

dreamwagon


You cannot get yaw, pitch and roll from a direction vector as the direction vector will only tell which direction to look in (yaw and pitch)

To get the yaw and pitch you use trigonometry - I assume you have some working knowledge. Check out this wiki page for some useful diagrams to visualize the angles.

Letting Y = yaw, P = pitch.

First to get yaw you want:

tan(Y) = x/(-y)

Now to get pitch:

tan(P) = sqrt(x^2 + y^2)/z

To get the actual values for Y and P you'll need to use inverse tan, I've written it above using tan to make the derivation clearer.

Note that the minus signs depend on how you define you angles and axes, but you should get the idea.

You can then set roll to be 0 or whatever you like.

like image 24
pheelicks Avatar answered Sep 25 '22 15:09

pheelicks