3D Math for Game Programming: Vectors – Part 5

Game Programming 3D Math Vectors

We now resume our series on 3D math for game programming from where we left off and talk about Vectors. In the last article of the series we took a look at Nested Coordinate Spaces and learned how to specify them and handle coordinate space transformations.

Today we will be introducing you to vectors and how they are used in 3D Math for game programming. This is a reminder that If you are new to this series you can go over and get started with the introduction to 3D Math for computer graphics here.

What are Vectors

When dissecting Vectors in the concept of 3D Math then we need to distinguish between the two definitions in terms of abstract and purely mathematical definition and the geometric definition. And yes! We know geometry is part of math but work with us now. I am going somewhere with this. For the purposes of 3D math, it is important to understand both implementations.

In mathematical terms, a Vector is a list of numbers or to us programmers, it is an array of numbers. Still in that same mood, as a mathematician, you must be able to distinguish between Vector vs Scalar quantities. A scalar quantity just to mention is an ordinary number. To illustrate, “velocity” and “displacement” are vector quantities, while “speed” and “distance” are scalar quantities.

Read Also  The Mortal Kombat X Walkthrough Gameplay in Pictures

The next term we introduce is “dimension”. Dimension is the value that tells us how many numbers a Vector has. Logic tells us that a Dimension is a number higher than zero. Therefore a single dimension Vector is also a Scalar or 1D Vector. We will mostly be looking at 2D, 3D and 4D Vectors in this series. we will use x and y to refer to the elements in a 2D vector, x, y, and z to refer to elements in a 3D vector, and x, y, z, and w to refer to elements in a 4D vector.

Now for the Geometric Definition of a Vector

2D Vector
A 2D Vector

Geometrically a Vector is a directed line segment that has magnitude and direction. Magnitude is the length of the Vector and is usually non-negative. A direction is a way in which the Vector points in the coordinate space. This illustration is usually done with an arrowhead at the end of the magnitude line.

It is good to note now that Vectors do not have an absolute position but they imply a relative position. For example: “The car is 13 miles east of here”. This statement gives a relative position but not an absolute one.

Read Also  Embedded Vision Summit 2016 Conference
2D Vector Specification
Specifying a 2D Vector

To specify Vectors you need to do so using the axis in the plane in which they are placed. For instance, the 2D Vector here can be specified as [x, y]. The illustration shows where the X and Y come from. The same applies to 3D and 4D Vectors. In this case, it is x units to the right and y units up.

A Vector even though being a single line can also be specified as a series of displacements (straight lines) leading to the same point. You can have a series of different magnitudes and directions. Think of it as you being able to drive home from work. You are not restricted to using a single route but you may have several options. Theoretically flying from one city to another a plane usually flies in a single Vector (Not in the real world but it works for this purposes) while driving to the same destination you will have to complete the trip with a series of Vectors. Now we just mentioned a Point, Therefore:

Vectors vs Points

A “point” specifies a position, and a “vector” specifies a displacement. Remember from previous articles in this series that a point has a location while obviously, a Vector doesn’t have a position.

Read Also  The First KDevelop 5.0.0 Beta

From the illustration above we can say a point is the tip of the arrowhead while a Vector remember is the Line. It is important at this time to note that points are relative positions. They are relative to the Origin of the coordinate system used to specify their coordinates. Take note that Vectors are specified with square brackets like [x,y] while Points are specified using parenthesis (x,y).

For now, we will stop here. In Part 6 of the series, we will start off with the relevant parts of Linear Algebra that we will be using to perform operations on Vectors.