1 Vector Mathematics

This guide discusses vector math including vector representation, vector operation, and line and plane equations.

A vector indicates a quantity, such as velocity or force, that has direction and length. Vectors in 3D coordinate systems are represented with an ordered set of three real numbers and look like:

1.1 Vector representation

In this document, lower case bold letters with arrow on top will notate vectors. Vector components are also enclosed in angle brackets. Upper case letters will notate points. Point coordinates will always be enclosed by parentheses.

Using a coordinate system and any set of anchor points in that system, we can represent or visualize these vectors using a line-segment representation. An arrowhead shows the vector direction.

For example, if we have a vector that has a direction parallel to the x-axis of a given 3D coordinate system and a length of 5 units, we can write the vector as follows:

To represent that vector, we need an anchor point in the coordinate system. For example, all of the arrows in the following figure are equal representations of the same vector despite the fact that they are anchored at different locations.

Figure (1): Vector representation in the 3-D coordinate system.

Given a 3D vector , all vector components , , are real numbers. Also all line segments from a point to point are equivalent representations of vector .

So, how do we define the end points of a line segment that represents a given vector?
Let us define an anchor point (A) so that:

And a vector:

The tip point of the vector is calculated by adding the corresponding components from anchor point and vector :

Figure (2): The relationship between a vector, the vector anchor point, and the point coinciding with the vector tip location.

Position vector

One special vector representation uses the as the vector anchor point.
The position vector is represented with a line segment between two points, the origin and the tip point B, so that:

Figure (1): Vector representation in the 3-D coordinate system.

A position vector for a given vector is a special line segment representation from the origin point to point .

Vectors vs. points

Do not confuse vectors and points. They are very different concepts. Vectors, as we mentioned, represent a quantity that has direction and length, while points indicate a location. For example, the North direction is a vector, while the North Pole is a location (point).
If we have a vector and a point that have the same components, such as:

We can draw the vector and the point as follows:

Figure (4): A vector defines a direction and length. A point defines a location.

Vector length

As mentioned before, vectors have length. We will use to notate the length of a given vector . For example:

In general, the length of a vector is calculated as follows:

Figure (5): Vector length.

Unit vector

A unit vector is a vector with a length equal to one unit. Unit vectors are commonly used to compare the directions of vectors.

A unit vector is a vector whose length is equal to one unit.

To calculate a unit vector, we need to find the length of the given vector, and then divide the vector components by the length. For example:

If of , then:

In general:

The unit vector of

Figure (6): Unit vector equals one-unit length of the vector.

1.2 Vector operations

Vector scalar operation

Vector scalar operation involves multiplying a vector by a number. For example:

Figure (7): Vector scalar operation

In general, given vector , and a real number

Vector addition

Vector addition takes two vectors and produces a third vector. We add vectors by adding their components.

Vectors are added by adding their components.

For example, if we have two vectors:

Figure (8): Vector addition.

In general, vector addition of the two vectors a and b is calculated as follows:

Vector addition is useful for finding the average direction of two or more vectors. In this case, we usually use same-length vectors. Here is an example that shows the difference between using same-length vectors and different-length vectors on the resulting vector addition:

Figure (9): Adding various length vectors (left). Adding same length vectors (right) to get the average direction.

Input vectors are not likely to be same length. In order to find the average direction, you need to use the unit vector of input vectors. As mentioned before, the unit vector is a vector of that has a length equal to 1.

Vector subtraction

Vector subtraction takes two vectors and produces a third vector. We subtract two vectors by subtracting corresponding components. For example, if we have two vectors and and we subtract from , then:

If we subtract from , we get a different result:

Note that the vector has the same length as the vector , but goes in the opposite direction.

Figure (10): Vector subtraction.

In general, if we have two vectors, and , then is a vector that is calculated as follows:

Vector subtraction is commonly used to find vectors between points. So if we need to find a vector that goes from the tip point of the position vector to the tip point of the position vector , then we use vector subtraction as shown in Figure (11).

Figure (11): Use vector subtraction to find a vector between two points.

Vector properties

There are eight properties of vectors. If a, b, and c are vectors, and s and t are numbers, then:

Vector dot product

The dot product takes two vectors and produces a number.
For example, if we have the two vectors a and b so that:

Then the dot product is the sum of multiplying the components as follows:

In general, given the two vectors a and b:

We always get a positive number for the dot product between two vectors when they go in the same general direction. A negative dot product between two vectors means that the two vectors go in the opposite general direction.

Figure (12): When the two vectors go in the same direction (left), the result is a positive dot product. When the two vectors go in the opposite direction (right), the result is a negative dot product.

When calculating the dot product of two unit vectors, the result is always between 1 and +1. For example:

In addition, the dot product of a vector with itself is equal to that vector’s length to the power of two. For example:

Calculating the square length of vector :

Vector dot product, lengths, and angles

There is a relationship between the dot product of two vectors and the angle between them.

The dot product of two non-zero unit vectors equals the cosine of the angle between them.

In general:

, or

Where:

is the angle included between the vectors.

If vectors a and b are unit vectors, we can simply say:

And since the cosine of a 90-degree angle is equal to 0, we can say:

Vectors and are orthogonal if, and only if, .

For example, if we calculate the dot product of the two orthogonal vectors, World xaxis and yaxis, the result will equal zero.

There is also a relationship between the dot product and the projection length of one vector onto another. For example:

In general, given a vector a and a non-zero vector b, we can calculate the projection length pL of vector a onto vector b using the dot product.

Dot product properties

If , , and are vectors and s is a number, then:

Vector cross product

The cross product takes two vectors and produces a third vector that is orthogonal to both.

Figure (14): Calculating the cross product of two vectors.

For example, if you have two vectors lying on the World xy-plane, then their cross product is a vector perpendicular to the xy-plane going either in the positive or negative World z-axis direction. For example:

The vector is orthogonal to both and .

You will probably never need to calculate a cross product of two vectors by hand, but if you are curious about how it is done, continue reading; otherwise you can safely skip this section. The cross product is defined using determinants. Here is a simple illustration of how to calculate a determinant using the standard basis vectors:

The cross product of the two vectors and is calculated as follows using the above diagram:

Cross product and angle between vectors

There is a relationship between the angle between two vectors and the length of their cross product vector. The smaller the angle (smaller sine); the shorter the cross product vector will be. The order of operands is important in vectors cross product. For example:

Figure (15): The relationship between the sine of the angle between two vectors and the length of their cross product vector.

In Rhino’s right-handed system, the direction of is given by the right-hand rule (where = index finger, = middle finger, and = thumb).

In general, for any pair of 3-D vectors and :

Where:

is the angle included between the position vectors of and

If a and b are unit vectors, then we can simply say that the length of their cross product equals the sine of the angle between them. In other words:

The cross product between two vectors helps us determine if two vectors are parallel. This is because the result is always a zero vector.

Vectors and are parallel if, and only if, .

Cross product properties

If , , and are vectors, and is a number, then:

1.3 Vector equation of line

The vector line equation is used in 3D modeling applications and computer graphics.

Figure (16): Vector equation of a line.

For example, if we know the direction of a line and a point on that line, then we can find any other point on the line using vectors, as in the following:

line direction unit vector
line position point
any point on the line

We know that:

(2)
(1)

From 1 and 2:

(3)

However, we can write (3) as follows:

Therefore:

Which is the same as:

Given a point and a direction on a line, any point on that line can be calculated using the vector equation of a line where is a number.

Another common example is to find the midpoint between two points. The following shows how to find the midpoint using the vector equation of a line:

is the position vector for point
is the position vector for point
is the vector going from

From vector subtraction, we know that:

From the line equation, we know that:

And since we need to find midpoint, then:

Hence we can say:

Figure (17): Find the midpoint between two input points.

In general, you can find any point between and by changing the value between 0 and 1 using the general equation:

Given two points and , any point between the two points is calculated using the equation where t is a number between 0 and 1.

1.4 Vector equation of a plane

One way to define a plane is when you have a point and a vector that is perpendicular to the plane. That vector is usually referred to as normal to the plane. The normal points in the direction above the plane.

One example of how to calculate a plane normal is when we know three non-linear points on the plane.

In Figure (16), given:

= the first point on the plane
= the second point on the plane
= the third point on the plane

And:

= a position vector of point
= a position vector of point
= a position vector of point

We can find the normal vector as follows:

Figure (18): Vectors and planes

We can also derive the scalar equation of the plane using the vector dot product:

If:

Then we can expand the above:

Solving the dot product gives the general scalar equation of a plane:

1.5 Tutorials

All the concepts we reviewed in this chapter have a direct application to solving common geometry problems encountered when modeling. The following are stepbystep tutorials that use the concepts learned in this chapter using Rhinoceros and Grasshopper (GH).

1.5.1 Face direction

Given a point and a surface, how can we determine whether the point is facing the front or back side of that surface?

Input:

a surface

a point

Parameters:

The face direction is defined by the surface normal direction. We will need the following information:

The surface normal direction at a surface location closest to the input point.

A vector direction from the closest point to the input point.

Compare the above two directions, if going the same direction, the point is facing the front side, otherwise it is facing the back.

Solution:

1. Find the closest point location on the surface relative to the input point using the Pull component. This will give us the uv location of the closest point, which we can then use to evaluate the surface and find its normal direction.

2. We can now use the closest point to draw a vector going towards the input point. We can also draw:

3. We can compare the two vectors using the dot product. If the result is positive, the point is in front of the surface. If the result is negative, the point is behind the surface.

The above steps can also be solved using other scripting languages. Using the Grasshopper VB component:

1.5.2 Exploded box

The following tutorial shows how to explode a polysurface. This is what the final exploded box looks like:

Input:

Identify the input, which is a box. We will use the Box parameter in GH:

Parameters:

Think of all the parameters we need to know in order to solve this tutorial.

The center of explosion.

The box faces we are exploding.

The direction in which each face is moving.

Once we have identified the parameters, it is a matter of putting it together in a solution by piecing together the logical steps to reach an answer.

Solution:

1. Find the center of the box using the Box Properties component in GH:

2. Extract the box faces with the Deconstruct Brep component:

3. The direction we move the faces is the tricky part. We need to first find the center of each face, and then define the direction from the center of the box towards the center of each face as follows:

4. Once we have all the parameters scripted, we can use the Move component to move the faces in the appropriate direction. Just make sure to set the vectors to the desired amplitude, and you will be good to go.

The above steps can also be solved using VB script, C# or Python. Following is the solution using these scripting languages.