Vectors
Vectors are fundamental tool in 3D mathematics. This article will focus on basic vector arithmetics focused on perspective of a programmer, rather than mathematician.
In mathematics, a vector is typically denoted as lowercase boldface letter, eg. a or v, in component form, eg. (x, y) for 2D vectors, (x, y, z) for 3D vectors, and in few more notations, but in notes provided by MathVision, we'll be sticking to those two forms.
Typically in geometry 2D or 3D vectors are used to represent position or direction of a point. A vector may be described as a container of values - you may think about a vector as a structure containing two or more values, similar to:
vector1 = {
'x': 10,
'y': 20
}
In the above example, x and y values may represent position of a point, which would
make the vector a position vector, or direction (or displacement), which would make
the vector a direction vector. While the structure of both position and direction vectors
is the same, their meaning and usage differs significantly.
A vectors have two main quantities: magnitude (or length) and direction. In a 2D example, the following vector:
vec = {
'x': 5,
'y': 0
}
Has a magnitude of 5 and points in a direction of positive X axis (or in other terms - right). More info about vector calculations may be read at [basic vector arithmetics](mv-note://Math - Vector arithmetics) section of this module.
Scalars
Scalar numbers, or just scalars are simply just single number. They only represent a
magnitude, and have no direction. Scalars are used together with vectors all the time,
for example for scaling the vector, hence the name. There will be more examples of vector
and scalar calculations in later sections of this module.
GLM
As mentioned in earlier notes, MathVision uses GLM as a main mathematics library. GLM provides an object representation of various vectors and matrices. You may read more about GLM usage in GLM official documentation.
A simple Python example usage of GLM:
import glm
v1 = glm.vec3(5, 0, 0)
print(v1)
vec3( 5, 0, 0 )
Vector operations
Just like scalar numbers, you may perform a number of mathematical operations on vectors in order to move them, scale them, find perpendicular vectors etc. Some of the operations and contepts are covered in notes: