Calculating roll from yaw, pitch, and up vector - math

If I have a camera's yaw, pitch, and up vector (always [0,1,0] in my case), what's the best way to calculate the corresponding roll?

When a camera's up vector is (0,1,0), the effect is to lock its yaw to 0 degrees.

Related

Euler Angles to OpenGL direction vector?

I am currently working on block-breaking in a Minecraft clone. In order to do so, I want use the camera's Euler angles to determine the direction vector of the camera's ray.
I have 2 angles: pitch and yaw.
Pitch rotates along the X axis and is positive when the player looks down, and negative when the player looks up. It cannot be greater than 90 degrees (looking straight down) and cannot be smaller than -90 degrees (looking straight up)
Yaw rotates along the Y axis. It can be a negative number and a positive number, depending on how many times the player turned and in which direction. For example, the player spawns in (yaw = 0) and instantly spins counter-clockwise 360 degrees. In such a case, yaw = -360.
As stated in the question, I am using OpenGL, so when yaw = 0, the player is looking down the negative Z-axis.
How can I generate a direction vector (must be a unit-vector) using only the Euler angles with the restrictions described above?
From your description of Pitch and Yaw, I am assuming that you are using a left-hand reference (pitch=0 and yaw=0 gives a camera vector (0.0, 0.0, 1.0).
The Pitch parameter moves the camera vector in the YZ plane :
Y = cos(pitchInRadians)
Z = sin(pitchInRadians)
The Yaw parameter moves the camera vector in the XZ plane :
X = sin(yawInRadians)
Z = cos(yawInRadians)
Combining the two would give you your final camera vector :
Cv = (sin(yaw), cos(pitch), sin(pitch)*cos(yaw))
As you should have noted, the angles are in radians. Since your post mentions angles in degrees, you will have to convert your degree angles to radians first :
radians = (degrees * PI) /180

Convert pitch, roll, and yaw angles

I have a pitch, roll, and yaw angles (in degrees). I want to find the angle to north.
My goal is to transform this info (pitch+roll+yaw) to a simple compass degrees.

Vector being cast from a central point

I want to break a circle up into X number of rays that will fire out from a given point.
The problem I'm having is how do I calculate the vector of each ray given X which is the number of rays fired equal distance from each other around a circle.
There are 2π radians (360 degrees) in a circle. You want to divide this value by X to tell you the difference of angle that you need between each ray. Call this difference Z. Start with a ray pointing at 0 radians, and repeatedly add Z to it. At each iteration, generate a new ray, and stop after X iterations.
For each ray above defined by its value in radians, use trigonometry (sine and cosine) to construct the X and Y component values of the ray direction vector.

Nullifying an angle in a Rotation Matrix

Say I have a Rotation Matrix, which is used to rotate a 3D model.
Is it possible to set the yaw of the rotation matrix to zero before applying it to the model?
Regards, Adam.
RotMatrix=R(yaw)*R(pitch)*R(roll)
to eliminate yaw factor, we can left-multiply this matrix on negative yaw matrix
RotMatrixNew=R(-yaw)*R(yaw)*R(pitch)*R(roll) = I**R*(pitch)*R(roll) = R(pitch)*R(roll)
If yaw angle isn't known before, then it could be calculated as
yaw = ArcTan2(RotMatrix[2][1], RotMatrix[1][1])

Calculate 3D rotation of a point

How do I calculate the pitch, yaw, and roll angles for a point in 3D space?
I'm working on a game where the player character must face towards an object that's flying around.
For yaw, use the atan2() of the X and Y coordinates. For the pitch, use the X-Y magnitude and the Z coordinate. Points don't have a roll.

Resources