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
    How is the vector related to the line segments?2011-04-25
  • 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
    Is my method for finding ϕ correct (i.e. dot product of V with the x unit vector)? How do I go about finding θ?2011-04-26
  • 0
    @basil: $\phi=\arccos(\frac{V\cdot\langle 0,0,1\rangle}{|V|})$ (that is, use the dot product with the $z$ axis unit vector, since $\phi$ is the angle from the positive $z$ axis); if $V=\langle v_x,v_y,v_z\rangle$, then $\theta$ is determined by $v_x=r\cos\theta$ and $v_y=r\sin\theta$ where $r=\sqrt{v_x^2+v_y^2}$ (which means that $\tan\theta=\frac{v_y}{v_x}$, but beware of using the arctangent function blindly, as it $\theta$ might not be in the interval $(-\frac{\pi}{2},\frac{\pi}{2})$.)2011-04-26
  • 0
    ok that makes sense, so rotation around z is a better method than around x? also, from the above rotation matrices, i would do the cross product between the first two and then take the result and do the cross product with the third to get $x' = x*\cos\phi *(\cos\theta + sin\theta)$, $y' = y *(\cos\theta - \sin\theta)$ and $z' = z *\sin\phi (\cos\theta + \sin\theta)$, does this look correct?2011-04-26
  • 0
    any help here??2011-04-28
  • 1
    @basil: With regards to Isaac's advice of "beware of using the arctangent function blindly", the two-argument arctangent can be helpful in this regard.2011-04-29
  • 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