Calculate 3D rotation of a point - math

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.

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

how to get the rotation angle around y axis if i know the the initial point(x,y) and the resulted point(x',y) after rotation in 2D space

I have an object rotates around the y axis in 2 dimension image, i want to know the angle of rotation around y axis, if i already have the initial point(X,Y) and the point(X',Y) after rotation.
I have tried to follow the 3 dimension rotation equations (https://www.siggraph.org/education/materials/HyperGraph/modeling/mod_tran/3drota.htm) to evaluate the value of rotation angle no matter the direction of rotation,but i do not know the Z value from the 2 dimension to evaluate the rotation angle from the equations.
I figure out that i can't know the accurate rotation angles because i don't have full information about the location of points after and before rotation , i just have a projection of points(after and before the rotation)(x,y) in 2D image(plan) as "Nico Schertler" said in the comments, so i found an approximate solution which is to map the 2D object to similar 3D model for the same object and simulate the same motion on the 3D object to know approximated information about angles, in my case i want to know the rotation angles of a human head (head pose) so i mapped some 2D head features point to another 3D model and after deep diving into mathematics i got approximated rotation matrix as it shown here (http://www.learnopencv.com/head-pose-estimation-using-opencv-and-dlib/)

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.

Calculating roll from yaw, pitch, and up vector

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.

Given start point, angles in each rotational axis and a direction, calculate end point

I have a start point in 3D coordinates, e.g. (0,0,0).
I have the direction I am pointing, represented by three angles - one for each angle of rotation (rotation in X, rotation in Y, rotation in Z) (for the sake of the example let's assume I'm one of those old logo turtles with a pen) and the distance I will travel in the direction I am pointing.
How would I go about calculating the end point coordinates?
I know for a 2D system it would be simple:
new_x = old_x + cos(angle) * distance
new_y = old_y + sin(angle) * distance
but I can't work out how to apply this to 3 dimensions
I suppose another way of thinking about this would be trying to find a point on the surface of a sphere, knowing the direction you're pointing and the sphere's radius.
First of all, for positioning a point in 3D you only need two angles (just like you only needed one in 2D)
Secondly, for various reasons (slow cos&sin, gimbal lock, ...) you might want to store the direction as a vector in the first place and avoid angles alltogether.
Anyway, Assuming direction is initially z aligned, then rotated around x axis followed by rotation around y axis.
x=x0 + distance * cos (angleZ) * sin (angleY)
Y=y0 + distance * sin (Anglez)
Z=z0 + distance * cos (angleZ) * cos (angleY)
Based in the three angles you have to construct the 3x3 rotation matrix. Then each column of the matrix represents the local x, y and z directions. If you have a local direction you want to move by, then multiply the 3x3 rotation with the direction vector to get the result in global coordinates.
I made a little intro to 3D coordinate transformations that I think will answer your question.
3D Coordinates
First, it is strange to have three angles to represent the direction -- two would be enough. Second, the result depends on the order in which you turn about the respective axes. Rotations about different axes do not commute.
Possibly you are simply looking for the conversion between spherical and Cartesian coordinates.

Resources