# M - Raytracing Reference

## Matrix

A matrix is a rectangular array of numbers. An m x n matrix has m rows and n columns (note that some people think of it as m columns and n rows). For example, a 3x4 matrix might be

Matrices may be added to, subtracted from or multiplied by other matrices. The matrix product A * B exists when the number of columns of A and the number of rows of B are equal. It is calculated on a row * column basis. For example,

Matrices may also be multiplied by scalars. More information on matrix operations is easily available in a high school mathematics textbook or on the Net.

The immense usefulness of matrices in graphics software is due to the fact that a matrix can represent a simple transformation such as rotation, translation or scaling. For example, the matrix representing a translation by tx, ty and tz units in the x, y and z directions respectively in 3-D space looks like

A composite transformation may be formed by multiplying matrices. For example, the matrix product A * B * C corresponds to the sequence (note the order): perform transformation C, then B, then A. If A was a translation matrix, B was a scaling matrix and C was a rotation matrix, then the sequence would be "rotate-scale-translate". This gives a compact and convenient way of specifying complex transformations: a sequence of 1000 transformations takes up exactly the same space a a single one.

A 4x4 matrix may be used to transform a position vector (x, y, z) to a new position (x', y', z') by matrix multiplication as follows:

This gives the transformed vector in "homogenous coordinates" as (xh, yh, zh, h). This is converted to standard vector form by dividing by h. Therefore we have

(x', y', z') = (xh / h, yh / h, zh / h).

The "inverse" of a square matrix A is another square matrix inv(A) such that A * inv(A) = inv(A) * A = I, where I is the identity matrix (main diagonal elements are 1, rest are 0) of the same size as A. The inverse of a transformation matrix represents the inverse transformation. For example, if A is a matrix to rotate a point around the x-axis by 90 degrees, then inv(A) is a matrix to rotate a point around the x-axis by 90 degrees in the opposite direction.

## Mesh

A mesh is a collection of polygons (usually triangles or quadrilaterals). Meshes are most useful when these polygons share edges, forming a continuous sheet. Meshes can approximate just about any surface. This makes them very convenient for rendering difficult shapes like spline patches. At low enough resolutions and with fake curve smoothing techniques like Phong shading, a mesh representation can be indistinguishable from the real curved surface (see picture). Most 3-D programs store a mesh of many polygons in such a way that it takes up less memory than an equal number of independent polygons.

## Model

A model is a way of representing an object using methods other than the original. Models need not be scale replicas of material objects. Physicists use mathematical models of real-world phenomena. Computers use models of data structures and relationships, learning systems may be modelled with neural nets. Models may be static or procedural. In most cases, they are simple, manageable and analysable versions of the originals. Geometrical models, used in graphics, are often modelled with equations. When simple equations are not available, mesh or volumetric models may be used.