<p>Build a matrix with one of the vectors a=(1,0,1) now you need another vector to define the matrix vector say b=(1, 0, 0) take the cross product of a  and b lets call this c. Then take the cross product of a and c for a rectified b'. Normalize a, b' and c.</p>

<p>Your matrix T is now [a b' c] plus any affine part you deem neccesery.  Then do T<sup>-1</sup> * Rx(Angle) * T. where Rx(a) is a function that returns a rotation matrix around the x axis with a angle of a.</p>

CC BY-SA 3.0
2016-05-06T20:15:31.890Z
This is a quick answer over the phone, spelling corrections and tex formulas welcome.
joojaa
CC BY-SA 3.0
2016-05-06T20:14:27.637Z
2016-05-06T20:14:27.637Z
joojaa
<p>There is a direct formula for the rotation matrix for an arbitrary axis and angle. Given a unit vector $a = (a_x, a_y, a_z)$ and angle $\theta$, the matrix can be constructed as follows (derivation from <a href="https://en.wikipedia.org/wiki/Rodrigues&#39;_rotation_formula#Matrix_notation" rel="noreferrer">Wikipedia</a>):</p>

<p>First build a matrix $C$ from the components of $a$ according to the following formula:</p>

<p>$$ C =
\begin{bmatrix}
  0 &amp; -a_z &amp; a_y \\
  a_z &amp; 0 &amp; -a_x \\
  -a_y &amp; a_x &amp; 0
\end{bmatrix} $$</p>

<p>Then you can construct the rotation matrix from $C$ as follows:</p>

<p>$$ R_a(\theta) = I + C \sin \theta + C^2 (1 - \cos \theta) $$</p>

<p>where $I$ is the 3&times;3 identity matrix. This assumes you're using a column-vector convention; if you're using row vectors instead, transpose $C$.</p>

<p>By the way, this formula has a neat geometric interpretation. The matrix $C$ has the effect of calculating cross products with $a$. In other words, for any vector $v$, $Cv = a \times v$. If you imagine rotating some vector $v$ about $a$, the tip of $v$ traces out a circle perpendicular to $a$; $Cv$ is a vector tangent to that circle, and $C^2 v$ (which equals $a \times (a \times v)$) is a vector normal to the circle. So with those two vectors, you have a basis for the plane of the circle; then you can apply a variation of the usual sine/cosine formula for points on a circle.</p>

CC BY-SA 3.0
2016-05-07T06:05:53.883Z
And the neat geometric interpretation is what I used. Personally I prefer to build the matrixes with a few number of atomic operations because then I only need to remember 3 rules of construction.
joojaa
CC BY-SA 3.0
2016-05-06T21:01:50.843Z
2016-05-06T21:01:50.843Z
Nathan Reed
<p>I am using matrix for performing 3D rotations. I know that in 3D space the matrix product order is important - changing the order of the matrices can effect the rotate result.</p>

<p>So I am interesting about how can I create a rotate matrix that perform rotation (clockwise) around some vector, say $(1, 0, 1)$.</p>

<p>I thought that $R_{(1,0,1)}(\theta) = R_X(\theta) \cdot R_Z(\theta)$ but it seems wrong because if I tries to rotate the $(1, 0, 1)$ with $45^{\circ}$ it moves out from $(1, 0, 1)$ but it should stay in place.</p>

<p>So how can I build such a rotation matrix as product of 3D trasformation matrices?</p>

<3d><transformations><matrix>
3D rotation matrix around vector
nrofis
# 3D rotation matrix around vector

(Asked by: username_0 on 2016-05-06)

I am using matrix for performing 3D rotations. I know that in 3D space the matrix product order is important - changing the order of the matrices can effect the rotate result.

So I am interesting about how can I create a rotate matrix that perform rotation (clockwise) around some vector, say $(1, 0, 1)$.

I thought that $R\_{(1,0,1)}(\theta) = R\_X(\theta) \cdot R\_Z(\theta)$ but it seems wrong because if I tries to rotate the $(1, 0, 1)$ with $45^{\circ}$ it moves out from $(1, 0, 1)$ but it should stay in place.

So how can I build such a rotation matrix as product of 3D trasformation matrices?

**Tags:** 3d, transformations, matrix


---

## 2 answers

### Answer by username_2 on 2016-05-06. Score: 5 | Accepted answer

There is a direct formula for the rotation matrix for an arbitrary axis and angle. Given a unit vector $a = (a\_x, a\_y, a\_z)$ and angle $\theta$, the matrix can be constructed as follows (derivation from [Wikipedia](https://en.wikipedia.org/wiki/Rodrigues'_rotation_formula#Matrix_notation)):

First build a matrix $C$ from the components of $a$ according to the following formula:

$$ C =
\begin{bmatrix}
0 & -a\_z & a\_y \\
a\_z & 0 & -a\_x \\
-a\_y & a\_x & 0
\end{bmatrix} $$

Then you can construct the rotation matrix from $C$ as follows:

$$ R\_a(\theta) = I + C \sin \theta + C^2 (1 - \cos \theta) $$

where $I$ is the 3×3 identity matrix. This assumes you're using a column-vector convention; if you're using row vectors instead, transpose $C$.

By the way, this formula has a neat geometric interpretation. The matrix $C$ has the effect of calculating cross products with $a$. In other words, for any vector $v$, $Cv = a \times v$. If you imagine rotating some vector $v$ about $a$, the tip of $v$ traces out a circle perpendicular to $a$; $Cv$ is a vector tangent to that circle, and $C^2 v$ (which equals $a \times (a \times v)$) is a vector normal to the circle. So with those two vectors, you have a basis for the plane of the circle; then you can apply a variation of the usual sine/cosine formula for points on a circle.

> **Comments:**
> **username_1**: And the neat geometric interpretation is what I used. Personally I prefer to build the matrixes with a few number of atomic operations because then I only need to remember 3 rules of construction.  

---

### Answer by username_1 on 2016-05-06. Score: 1

Build a matrix with one of the vectors a=(1,0,1) now you need another vector to define the matrix vector say b=(1, 0, 0) take the cross product of a and b lets call this c. Then take the cross product of a and c for a rectified b'. Normalize a, b' and c.

Your matrix T is now [a b' c] plus any affine part you deem neccesery. Then do T-1 \* Rx(Angle) \* T. where Rx(a) is a function that returns a rotation matrix around the x axis with a angle of a.

> **Comments:**
> **username_1**: This is a quick answer over the phone, spelling corrections and tex formulas welcome.  

---

