1

I'm reading the Billboarding section in the book Real-Time Rendering and the author explains that in order to rotate a quadrilateral (i.e the billboard) to a certain orientation, the rotation matrix will be

M = (r, u, n)

Where r, u, n are the calculated (normalized) direction vectors.

From the book: enter image description here

I've learned that in order to rotate stuff one must use a matrix that includes lots of dirty sin() and cos() calculations. How come this M matrix uses plain direction vectors?

McLovin
  • 3,295
  • 7
  • 32
  • 67

2 Answers2

3

Sine and cosine are used only when you want to convert from an angle representation to a vector representation. But let's first analyze what makes a matrix a rotation matrix.

Rotation matrices are ortho-normal and have determinant +1. That means that their column vectors are of unit length and that they are perpendicular to each other. One nice property of ortho-normal matrices is that you can invert them by transposing them. But that's just a nice feature.

If we have the 2D rotation matrix

M = /  cos a   sin a \
    \ -sin a   cos a /

, we see that this is the case. The first column vector is (cos a, -sin a). From the Pythagorean theorem, we get that this vector has unit length. Furthermore, it is perpendicular to the second column vector (their dot product is zero).

So far, so good. This matrix is a rotation matrix. But can we interpret the column vectors? Indeed, we can. The first column vector is the image of the vector (1, 0) (i.e. the right vector). The second column vector is the image of the vector (0, 1) (i.e. the up vector).

So you see that using sine and cosine are just another way to calculate the direction vectors. Doing so automatically ensures that they have unit length and that they are orthogonal to each other. But this is just one way. You can also calculate the direction vectors using the cross product or any other scheme. The critical point is that the rotation matrix properties are fulfilled.

Nico Schertler
  • 32,049
  • 4
  • 39
  • 70
  • Will the column vectors always be images of `(1,0,0)` , `(0,1,0)` , `(0,0,1)` respectively? – McLovin Dec 15 '15 at 17:10
  • Also, if a matrix is orthogonal and is not an identity matrix, then it must be a rotation matrix? – McLovin Dec 15 '15 at 17:12
  • 2
    @Pilpel Yes to your first question. No to your second. Firstly, the matrix must also be ortho-*normal*. Secondly, it has to have determinant +1. It could also have determinant -1 (which would also include reflection). But if these requirements are met, then yes. It must be a rotation matrix. Note that also the identity matrix is a rotation matrix (with a zero angle). – Nico Schertler Dec 15 '15 at 17:22
  • @Pilpel Note that the mathematical definition of *orthogonal matrix* means that its rows/columns are *orthonormal*. Just a matter of terminology, but can be confusing. – Andras Deak -- Слава Україні Dec 15 '15 at 17:58
  • 1
    @Pilpel indeed. Orthogonal matrices have the property `M*M^T=I` where `^T` is transpose and `I` is the unit matrix. These are a special case of (complex) unitary matrices, for which `M*M^+=I` where `^+` denotes the adjoint (conjugate transpose) of the matrix. And as Nico said, the determinant of an orthogonal matrix is either +1 or -1; the former are proper rotations and the latter are reflections. – Andras Deak -- Слава Україні Dec 15 '15 at 18:06
2

You need those dirty trigonometric functions if your transformation is given with angles. However, if instead you know the image of the Cartesian unit vectors, you can construct the matrix easily.

If the image of [1; 0; 0] is r, [0; 1; 0] is u and [0; 0; 1] is n, then the effect of the matrix will be

M * [1; 0; 0] == 1*r + 0*u +0*n == r
M * [0; 1; 0] == 0*r + 1*u +0*n == u
M * [0; 0; 1] == 0*r + 0*u +1*n == n

which is exactly the transformation you need, if your matrix is M=[r u n].

Note that this will in general give you an affine transformation, it will only be a rigid rotation if your vectors are orthonormal.

  • Can you explain the "image of" concept? I'm not familiar with this term. I also didn't quite get your calculation paragraph. – McLovin Dec 15 '15 at 16:48
  • 1
    @Pilpel I meant [image](https://en.wikipedia.org/wiki/Image_%28mathematics%29#Image_of_an_element) as in `f(x)` is the image of `x`, if your function is `f(x)=M*x` with your matrix `M` and column vector `x`. If you're familiar with how a matrix is multiplied by a row vector: acting `M` on `[1; 0; 0]` will return the first column of `M`, `[0; 1; 0]` will give the second column of `M`, and `[0; 0; 1]` will give the third column of `M`. This is what I tried to explain above,sorry it didn't work out.In other words:the columns of a matrix tell you what it transforms the Cartesian unit vectors into. – Andras Deak -- Слава Україні Dec 15 '15 at 16:50