Linear Algebra and Vector Math


Image 1: 3DS Max's right handed viewport coordinate system.

All transformations done for 3D graphics uses linear algebra and vector math. This section is a quick review of some vector math that you might find useful:

Vectors and Points

A point describes a position in 3D space and is represented by an x,y and z value.

A vector in 3D space describes a motion and is also represented by an x,y and z value.

Suppose you have two points in A and B. If you took the positions of A and subtracted from B, you will get a vector that tells you how to move from A to B, (a direction and how far to go).

All the 3D transform functions you use essentially apply vector math to your object(s) in some manner.

Translation

To translate(move) an object to a new position, you can represent the movement as a vector. The move function adds the vector representing the movement to the position (a point) to get a new point.

For example:

let \(A\) be the point (1,1,1). Let \(B\) be the point (2,1,3) then: \(\vec v = B-A = (1,0,2)\) is the vector that will translate from A to B. That is if we added \(\vec v\) to \(A\) we would end up at B.

Scaling

To scale an mesh we multiply each vertex of the mesh by a scalar value (a single number). Any number larger than 1 will make the object bigger. Any number smaller than 1 will make the object smaller.

Rotation

To rotate an object, we use the rotate function passing it the object to rotate and any one of a number of possible rotation delta objects. Valid rotation delta object types are:

  • Eulerangles
  • Angleaxis
  • Quaternion

Eg, using a eulerangles rotation delta:

rot_obj = eulerangles x y z

Eulerangles objects are the simplest rotation representation. x y z can be any degree angle values. An eulerangles object as we see above will rotate an object first on the world x axis, second on the world y axis, then finally on the world z axis. Positive values will rotate in a counterclockwise direction around an axis if you imagine the axis arrow pointing out of the clock face.

Eg, assuming mybox is a box object:

rotate mybox (eulerangles 45 30 60)

The above code segment would rotate mybox 45 degrees on the x axis first, 30 degrees on the y axis second, then finally 60 degrees on the z axis.

Please see the maxscript documentation on node transformations for more information.

Quaternion objects offer powerful rotational attributes that may be useful for LSystems though they are more complex and their implementation in MAXScript has some caveats. We explore Quaternions in their own section.