2
$\begingroup$

I have a vector V= and several line segments Seg1, Seg2, Seg3, Seg4.

I want to know how to rotate each of the line segments so that the X axis is parallel to my given vector.

How can I do this?

Note: I am aware that I can get the angle of rotation by taking the inner product of my vector and the x-unit vector (i.e. V DOT X) but I am unaware of what to do after this.

  • 0
    It is the average direction vector.2011-04-26

1 Answers 1

1

If the spherical coordinate representation of your vector $V$ is $\langle\rho,\phi,\theta\rangle$, where $\rho=|V|$, $\phi$ is the angle between $V$ and the positive $z$ axis, and $\theta$ is the angle between the positive $x$ axis and the projection of $V$ onto the $xy$ plane, then rotating the coordinate system by $\phi$ about the $y$ axis, then by $\theta$ about the $z$ axis should be sufficient. (This can be prefixed with an arbitrary rotation about the $x$ axis and still satisfy your criteria.) Using the rotation matrices from Wikipedia, \begin{bmatrix} x'\\ y'\\ z' \end{bmatrix}=\begin{bmatrix} \cos\theta & -\sin\theta & 0\\ \sin\theta & \cos\theta & 0\\ 0 & 0 & 1 \end{bmatrix}\begin{bmatrix} \cos\phi & 0 & \sin\phi\\ 0 & 1 & 0\\ -\sin\phi & 0 & \cos\phi \end{bmatrix}\begin{bmatrix} x\\ y\\ z \end{bmatrix}

  • 0
    Well, this is being programmed up in c++, which restricts its atan function to only between that range. I'm just trying to make sure that I get the equations for rotation correct...2011-04-29