Vectors Primer

Understanding vectors is a crucial skill for any technical artist. In this article, we will look at the very basics, both as a refresher for those who already know the concepts and an introduction for the uninitiated.

What is a Vector?

You might recall those arrows of a certain length from the highschool algebra, or you might have already tinkered with vectors in a 3D package where they seem to be used to denote points in space. We will only be dealing with 3D vectors, in the form [x, y, z] where x, y and z are single-precision floating point numbers (basically decimals with limited precision – and it's good to always keep that in mind), that describe a position offset in space in the context of the corresponding axes. In MAXScript, they are represented by the Point3 value.

However, it's important not to treat vectors as a list of numbers or coordinates only – especially since they are not really point coordinates per se. And since showing beats telling every time, let's have a look at this, first of all:

What can we say about it? Well, for one, it is defined by two points. And yet, it's not acutally one vector, it doesn't matter that the point labels are the same. Actually, at each frame we see a different vector. It's not the labelling that defines a it, it's the direction and its length. The vectors on the following images are all identical:

Vector v Vector v: Vector[A, B] Vector v Vector v: Vector[A, B] Vector u Vector u: Vector[C, A] Vector u Vector u: Vector[C, A] Vector u_1 Vector u_1: Vector[G, D] Vector u_1 Vector u_1: Vector[G, D] Vector w Vector w: Vector[F, E] Vector w Vector w: Vector[F, E] Point A A = (2, 1) Point A A = (2, 1) Point B B = (1, 2) Point B B = (1, 2) Point C C = (3, 0) Point C C = (3, 0) Point D D = (4, 1) Point D D = (4, 1) Point E E = (5, 2) Point E E = (5, 2) Point G G = (5, 0) Point G G = (5, 0) Point F F = (6, 1) Point F F = (6, 1)

You might have seen the concept described as a directed magnitude and while that's definitely more exact, I want you to think about the 3D vectors we will be using primarily as position offsets.

What does it mean? Different things in different contexts:
  • when used for point positions in world space, a vector describes the position offset from the scene origin,
  • in local space it's a position offset from the center of the object's coordinate system,
  • for a pair of points it's a direction and distance to get from one to the other,
  • and sometimes, like for example with normal vectors, we care mostly only about the direction part.

And as vectors are position-less, i.e. you can move a vector all around and it's still the same vector, let's respect the convention of placing the starting point at the origin:

Segment gSegment g: Segment [B, C]Segment iSegment i: Segment [D, B]Segment jSegment j: Segment [A, E]Segment kSegment k: Segment [A, F]Vector uVector u: Vector[O, B]Vector uVector u: Vector[O, B]Vector vVector v: Vector[O, A]Vector vVector v: Vector[O, A]Point BB = (5, 1)Point BB = (5, 1)B = [5, 1, 0]Point OO = (0, 0)Point OO = (0, 0)Point AA = (1, 2)Point AA = (1, 2)A = [1, 2, 0]5.12.24

Vector Addition

You might remember that adding vectors graphically amounts to sticking a starting point of one vector to the end point of the other one, optionally adding other vectors iteratively, and in the end connecting the starting point of the first one with the end point of the last one. The order is arbitrary and doesn't matter.

That's true and lends itself nicely to the notion of vectors as position offsets in space, but let's have a look at another way to look at it. As I've said before, I will stick to the convention of placing vector starting points at the origin, and I do that for a reason:

The difference from the previous image is that here all the vectors are placed so that they start at the [0,0] point. Instead of putting the other vector in the addition to the end of the first one, let's draw a thin dashed line. As you can see, for both vectors, the end point of the dashed line ends up in the same place, at the end of the diagonal of the parallelogram created by the vectors. This diagonal is the resulting vector.

Try and move the vertex handles around, and you will see that when both the vectors are of the same magnitude (length), their sum is a vector that halves their angle. If one of them is bigger, it drags the resulting vector more towards itself.

When expressed numerically, matching pairs of coordinates are added together:
[1, 0, 5] + [-10, 2, 0] = [-9, 2, 5]
What can you use that for?
  • With more vectors of the same length, the resulting vector will point in their average direction (unless they cancel out each other).
  • When their lengths are different, the result is a weighted average (used in weighted normals where small faces contribute a smaller amount).
You can visualize any 3D vector by creating axis vectors from its components. It is also a nice demonstration of vector addition in 3D space, note that in this case, the resulting vector is also a diagonal of the imaginary bounding box of the three vectors:

Since the axis vectors come handy pretty often, there are predefined MAXScript globals x_axis, y_axis and z_axis that contain the values [1,0,0], [0,1,0] and [0,0,1] respectively.

Vector Subtraction

Vector subtraction follows exactly the same rules, only flipping the vector that's negated. For a pair of vectors, it helps to think about it as the other diagonal of the parallelogram, the one that connects the end points of the two vectors when they share the same starting point (which is true for example for all positions in space measured from the origin point). The direction of the resulting vector depends on whether we are subtracting A from B or B from A.

In the next example, A is the vector that is subtracted from B, and as such becomes the new 'origin' point for the resulting vector. Whenever you find yourself deciding what to subtract from what, ask yourself what you want to treat as the origin – the subtracted position effectively becomes one. Grab the vector handles and see how the result changes:

You can also think of it this way: subtracting [0,0,0] from any position gives you the position difference that needs to be added to the origin [0,0,0] to get to that given position. The line AB is described by points A and B, and if you subtract A from both of them, the first one is suddenly [0,0,0] – and the other one is (B - A) – our new vector.

DISCLAIMER: All scripts and snippets are provided as is under Creative Commons Zero (public domain, no restrictions) license. All the diagrams and presentations on the page are made using GeoGebra and are made available under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike license. The author and this blog cannot be held liable for any loss caused as a result of inaccuracy or error within these web pages.

This Post needs Your Comment!

Return to top