Take the 2-minute tour ×
Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. It's 100% free, no registration required.

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.

share|improve this question
    
How is the vector related to the line segments? –  Matt Apr 25 '11 at 23:29
    
It is the average direction vector. –  basil Apr 26 '11 at 14:17

1 Answer 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}$$

share|improve this answer
    
Is my method for finding ϕ correct (i.e. dot product of V with the x unit vector)? How do I go about finding θ? –  basil Apr 26 '11 at 16:13
    
@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})$.) –  Isaac Apr 26 '11 at 16:23
    
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? –  basil Apr 26 '11 at 19:34
    
any help here?? –  basil Apr 28 '11 at 17:02
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. –  J. M. Apr 29 '11 at 16:57

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.