Geometry

News (August, 31): We are working on Scratchapixel 3.0 at the moment (current version of 2). The idea is to make the project open source by storing the content of the website on GitHub as Markdown files. In practice, that means you and the rest of the community will be able to edit the content of the pages if you want to contribute (typos and bug fixes, rewording sentences). You will also be able to contribute by translating pages to different languages if you want to. Then when we publish the site we will translate the Markdown files to HTML. That means new design as well.

That's what we are busy with right now and why there won't be a lot of updates in the weeks to come. More news about SaP 3.0 soon.

We are looking for native Engxish (yes we know there's a typo here) speakers that will be willing to readproof a few lessons. If you are interested please get in touch on Discord, in the #scratchapixel3-0 channel. Also looking for at least one experienced full dev stack dev that would be willing to give us a hand with the next design.

Feel free to send us your requests, suggestions, etc. (on Discord) to help us improve the website.

And you can also donate). Donations go directly back into the development of the project. The more donation we get the more content you will get and the quicker we will be able to deliver it to you.

3 mns read.

Transpose

The transpose of a matrix \(M\) is another matrix which we write using the following convention: \(M^T\) (with the superscript T). We can describe the process of transposing a matrix in different ways. It can be seen as: reflecting \(M\) over its main diagonal (from left to right, top to bottom) to obtain \(M^T\), writing the rows of \(M\) as the columns of \(M^T\) or reciprocally, writing the columns of \(M\) as the rows of \(M^T\). Computing the transpose of a matrix can be done with the following code:

Matrix44 transpose() const { Matrix44 transpMat; for (uint8_t i = 0; i < 4; ++i) { for (uint8_t j = 0; j < 4; ++j) { transpMat[i][j] = m[j][i]; } } return transpMat; }

The idea is to swap the rows and columns and since this operation can't be done in place we need to assign the result to a new matrix which is returned by the function. Transposing matrices can be useful when you want to convert matrices from a 3D application using row-major matrices to another using a column-major convention (and vice versa).

Inverse

If the multiplying point A by the Matrix M gives point B, multiplying a point B the inverse of the matrix M gives point A. In mathematics, a matrix inversion is usually written using the following notation:

$$M^{-1}$$

From this observation, we can write that:

$$MM^{-1}=I$$

Where I is the identity matrix. Multiplying a matrix by its inverse gives the identity matrix.

We have mentioned in the chapter How Does a Matrix Work, the case of the orthogonal matrix which inverse can easily be obtained from computing its transpose. An orthogonal matrix is a square matrix with real entries whose columns and rows are orthogonal unit vectors. This is an important property which we will be using to learn how to transform normals.

Matrix inversion is an important process in 3D. We know that we can use point- or vector-matrix multiplication to convert points and vectors but it is some times useful to be able to move the transformed points or vectors back into the coordinate system in which they were originally defined into. It is often necessary for instance, to transform the ray direction and origin in object space to test for a primitive-ray intersection. If there is an intersection the resulting hit point is in object space and needs to be converted back into world space to be usable.

The lesson Matrix Inverse in the Mathematics and Physics of Computer Graphics section will teach how to compute the inverse of a matrix (only available in the old version of Scratchapixel for now). Developing even a basic renderer without being able to use matrices and their inverse would be quite limited so we will be providing some code in this lesson for doing so. You can use this code without worrying to much about how it works and read this advanced lesson another time if you don't feel ready yet.

Determinant of a Matrix

This part of the lesson will be written later.