How to get angles from given position in $3D$?

148 Views Asked by At

I am struggling with a problem in the $3D$ coordinate system. I have a point given by its coordinates (I also know the distance from the origin, so I don't have to bother with counting that) and I need to make a line segment from the origin to this point by rotating the line segment. How can I get angles to rotate it?

I suppose I need only two angles. I was trying to use some arctangent formula, but I am not able to finish it.

The best I could do was

$angle_1 = \arctan(\frac{x}{diag_{xy}})$; $angle_2 = \arctan(\frac{y}{x})$

but that doesn't work.

2

There are 2 best solutions below

0
On BEST ANSWER

I was given this advice (originally from: https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Transformations#rotate):

$length = $norm$([x,y,z])$; // radial distance

$b = \arccos(\frac{z}{length})$; // inclination angle

$c = atan2(y,x)$; // azimuthal angle

the b and c is actually the angles I was looking for.

x,y,z are coordinates of given point.

where norm() is euclidian norm of vector https://en.wikibooks.org/wiki/OpenSCAD_User_Manual/Mathematical_Functions#norm.

And atan2 is the arctangent function with two arguments https://en.wikipedia.org/wiki/Atan2.

13
On

Let $(x_0,y_0,z_0)$ be the coordinates of point $A.$

Using a +45° rotation around $x$ axis gives point A_1 with the following coordinates:

$$\begin{cases}x_1&=&x_0\\y_1&=&y_0 \cos(45°) - z_0 \sin(45°)\\z_1&=&y_0 \sin(45°) + z_0 \cos(45°)\end{cases}$$

then the +45° rotation around $z$ axis of point $A_1$ gives point $A_2$:

$$\begin{cases}x_2&=&x_1 \cos(45°) - y_1 \sin(45°)\\y_2&=&x_1 \sin(45°) + y_1 \cos(45°)\\z_2&=&z_1\end{cases}.$$

Remark: $\cos(45°)=\sin(45°)=\dfrac{\sqrt{2}}{2}$.