Coordinate transformation I have some problems with a geometrical calculation.
I want to know the coordinates of the point $P_2$ in my coordinate system $A \ (x,y,z)$ as shown in the following figure.

Point $P_1$ (in $A \ (x,y,z)$) is easy to calculate by using spherical coordinates:
$x_1=l_1 \cdot \sin(\theta_1) \cos(\varphi_1)$
$y_1=l_1 \cdot \sin(\theta_1) \sin(\varphi_1)$
$z_1=l_1 \cdot \cos(\theta_1) $
Similarly, $P_2$ can be calculated in the coordinate system $B \ (x’,y’,z’)$:
$x_2'=l_2 \cdot \sin(\theta_2) \cos(\varphi_2)$, etc.
But somehow I am too stupid to see how I have to calculate the coordinates of $P_2$ with reference to the coordinate system $A \ (x,y,z)$. I assume that I have to use some rotation matrix and translation. But I am unsure how I have to use them and if this is the right approach. All I know is that the origin of the coordinate system $B \ (x’,y’,z’)$  is at $P_1$ and that the $z’$-axis has the same direction as the vector of $OP_1$ in $A \ (x,y,z)$. Describing the position of the $x’$-axis is difficult: For $\theta_1=\pi/2 \ \ x’$ is parallel to $z$ and for $\theta_1=0 \ \ x’$ is tilted around $z$ with respect to the $x$-axis with the angle $\varphi_1$. Naturally, the $y'$-axis is perpendicular to the $x'$- and $z'$-axes.  
I hope that these are enough details to solve the problem. Unfortunately, not for me ;-)
Therefore, I would be very happy about every support!
 A: I hope I got it!
I think, first I have to rotate around my $z$-axis with $\varphi_1$ and then I have to rotate around my new $y$-axis (which is now $y’$) with $\theta_1$. And at the end I have to add a constant (the point $P_1$)  to take into account that the base of the new coordinate system is at $P_1$.
Altogether, I think I have to calculate:
$\left(\begin{array}[c]{1} x \\ y \\ z \end{array}\right) = \left(\begin{array}[ccc]{3} \cos(\varphi_1) & -\sin(\varphi_1) & 0 \\ \sin(\varphi_1) & \cos(\varphi_1) & 0 \\ 0 & 0 & 1 \end{array}\right) \left(\begin{array}[ccc]{3} \cos(\theta_1) & 0 & -\sin(\theta_1) \\ 0 & 1 & 0 \\ \sin(\theta_1) & 0 & \cos(\theta_1)  \end{array}\right) \left(\begin{array}[c]{1} x' \\ y' \\ z' \end{array}\right)+\left(\begin{array}[c]{1} l_1\sin(\theta_1)\cos(\varphi_1)\\ l_1\sin(\theta_1)\sin(\varphi_1) \\ l_1\cos(\theta_1)\end{array}\right)$
I hope this is correct (I am always unsure which rotation matrix I have to use first). 
I would be happy if somebody could confirm or correct me!
I tested my and similar approaches, and unfortunately I had to recognize that I was wrong. 
It is really difficult to calculate $P_2$ in $A \ (x,y,z)$ because the direction of $x’$ etc. depends on $\theta_1$ and $\varphi_1$ and it seems that a distinction of cases has to be done. But event with that approach I was not able to come to a result.
Does anybody here have an idea??
