Learning MAXScript > Vector Arithmetic >

# Vector Arithmetic

This topic is a quick review for readers who need a reminder about vector arithmetic. If you’re familiar with vectors and vector calculations, you can skip this topic. If this topic is difficult to follow, you might consult a more basic reference on mathematics.

A vector expresses a length and a direction in a particular space. The vector is expressed as a point; for example, [5, 5, 7]. The length is the distance from the origin to that point, and the direction is similarly from the origin to (and through) the point.

In 3ds Max, vectors have three values and describe positions in three-dimensional space. They can also represent percent scaling in X, Y, and Z; and—more abstractly—describe locations in RGB color space.

Unit Vectors and Basic Vectors

A unit vector has a length of one. Unit vectors are often used to express direction only. The three basic vectors are unit vectors that describe the three axes (X, Y, and Z) of 3D space.

Basic vectors and the XYZ axes

Adding and Subtracting Vectors

Adding two vectors creates a new vector that combines the length and direction of the original two. Vector addition is commutative: V+W = W+V.

Adding two vectors

Subtracting two vectors gives the vector between the two points.

Subtracting two vectors

Scalar Multipliation and Division

Multiplying a vector by a scalar changes the vector’s length, as does dividing the vector by a scalar.

Vector Length and Direction

The length of a vector is obtained from the Pythagorean theorem.

In MAXScript, the length() function returns this value.

The direction of the vector is the vector divided by its length; this gives you a unit vector with the same direction.

The distance between two points is the length of the vector between them.

Subtracting vectors to obtain a distance