A vector is a mathematical object representing both a direction and a magnitude (length). In 3D rendering, vectors are crucial for describing positions, directions, and various operations related to object transformations (translation, rotation, scale), lighting, and camera movement.
A vector in 3D is represented as 3 components along an axis:
- Position Vectors: Describe points in space relative to the origin (e.g., $\mathbf{p} = (x, y, z)$).
- Direction Vectors: Define only the direction and are often normalized (unit vectors, so length 1).
- View Vector: Determines the direction the camera is facing.
- Up Vector: Helps define the camera's orientation to avoid upside-down views.
Vectors are crucial for describing object positions, orientations, and movements within the 3D scene. Basic transformations include:
- Translation: Moving an object by adding a vector.
- Scaling: Adjusting an object’s size through scalar multiplication of position vectors.
Lighting models use vectors to calculate illumination:
- Diffuse Lighting: Uses the dot product between the light direction and surface normal to compute the brightness of a surface.
- Specular Lighting: Uses reflection vectors to simulate shiny surfaces by calculating how closely the view vector aligns with the reflected light vector.
Magnitude (Length): The length of a vector is calculated using the Pythagoras' Theorem:
Let's say you have a position XY of (3,2), then the magnitude is calculated as follows:
Addition: Adding two vectors results in a new vector that represents moving from the start of the first vector to the end of the second vector:
And it doesn't matter which order we add them, we get the same direction.
Subtraction: Represents the vector pointing from one vector to another:
A scalar is just a number (like 7 or −0.32), so definitely not a vector.
Multiplying a vector by a scalar changes its magnitude without altering its direction:
In the following example the vector in blue is multiplier 2.5x times. It still points in the same direction, but is 2.5x times longer:
Normalization scales a vector to a unit vector (length of 1). Basically you divide the vector by its own lenth and you get a normalized vector:
In the following example we have the vector (3,4) which we divide by it's own length to get a normalized vector.
Application:
- Direction Vectors: In lighting and camera movement, normalized vectors help simplify calculations by keeping the focus on direction only.
Let's say we have the following vector a:
To get the X and Y components of the vector we can use trigonometry:
Then vector a is noted as follows:
-
Angle Calculation: The dot product can determine the angle
$\theta$ between two vectors. -
Lighting: The angle between a light direction and a surface normal determines the brightness in diffuse lighting.
-
Projection: The dot product helps project one vector onto another.
-
Determining View and Visibility: In rendering, the dot product can be used to determine if a surface is facing the camera or away from it. This helps with culling and optimizations.
The dot product between vector A and vector B is equal to the sum of the products of each component which is calculated as follows:
In the following example we have 2 vector where we calculate the dot product:
The dot product provides insight into the relationship between two vectors:
- If
a.b > 0: The angle betweenaandbis less than 90°. This means the vectors are pointing in roughly the same direction. - If
a.b < 0: The angle betweenaandbis greater than 90°. This means the vectors are pointing in roughly opposite directions. - If
a.b == 0: The vectors are orthogonal (perpendicular) to each other, meaning they form a 90° angle.
Let's say we have the following vectors a and b:
Vector a and b are represented as follows:
Now we can calculate the dot product:
Note
In the calculation above we used the trigonometric identity for the cosine of the difference of two angles:

More info about this here.
Therefore we have:
From the above statement we can now easily calculate the angle:
The cross product between two vectors a and b produces a third vector c that is perpendicular to both:
How to calculate the cross product:
- Surface Normals: These are vectors perpendicular to a surface. They are essential for lighting calculations, as they determine how light interacts with the surface.





























