# Rotating a line segment in 3D to a prescribed orientation

I have a general line segment with endpoints $(x_1,y_1,z_1)$ and $(x_2,y_2,z_2)$ referenced to a 3D Cartesian coordinate frame E. I wish to rotate this coordinate fram E to a new coordinate system F such that the new $x$-axis is parallel to this line segment.

Basically, I am looking for three unique Euler angles $(\alpha,\beta,\gamma)$, using the usual $z-y'-z''$ convention, in terms of the coordinates for the two endpoints in the original coordinate frame. Therefore, in the new coordinate frame, I will have three equations to satisfy: 1. $y_1''' = y_2'''$, 2. $z_1''' = z_2'''$, and 3. $(x_2'''- x_1''')^2 = (x_2 - x_1)^2 + (y_2 - y_1)^2 + (z_2 - z_1)^2$

• Is the use of Euler angles prescribed for the problem, or would you consider any representation of the rotation (e.g. quaternions)? – Muphrid Jan 9 '13 at 20:40
• Presumably, you want the rotation to be with the origin as the center? – Thomas Andrews Jan 9 '13 at 20:43
• Euler angles are prescribed. Is there a way to go from another representation of the rotation to Euler angles? – user56726 Jan 9 '13 at 20:44
• The origin of the original and transformed coordinate system must be the same. – user56726 Jan 9 '13 at 20:45

## 1 Answer

It's probably easier to think about this logically, then, rather than directly in terms of spinors/quaternions. Here's what you can do: you're rotating the $\hat x$ vector onto the vector $\hat \ell$. This can be done in a two-step process: rotate $\hat x$ onto $\hat \ell$'s projection onto the xy-plane. This puts $\hat \ell$ on the $zx'$ plane, and only one more rotation is required--rotation about $y'$--to line up $\hat x''$ with $\hat \ell$.

• Thanks, that's exactly what I've been trying to do for the past several hours, but something is wrong with my computation for arbitrary end points. – user56726 Jan 9 '13 at 21:48
• The computation should not care about the end points, only about the direction of the line itself. – Muphrid Jan 9 '13 at 22:11
• Yes, thanks. The problem is now solved and was a numerical issue with my algorithm instead of a problem with the underlying math. I am using the method you proposed and it works great. – user56726 Jan 10 '13 at 22:25