www.xbdev.net
xbdev - software development
Saturday February 22, 2025
Home | Contact | Support | The Maths of 3D You can't have 3D without a little maths... | The Maths of 3D You can't have 3D without a little maths...
     
 

The Maths of 3D

You can't have 3D without a little maths...

 


Fun quote from the Matrix movies - have you seen them? You can
Fun quote from the Matrix movies - have you seen them? You can't introduce matrices without mentioning Neo and the matrix! Matrices are difficult to accept - but you have to let it all go - fear, doubt and disbelief - free your mind - accept the matrix. Are you ready to learn about the 'Matrix'?


Matrices and Vectors (by bkenwright@xbdev.net)


Matrices and vectors are vital in 3D graphics because they handle all the complex calculations needed to transform, move, and manipulate objects within a 3D space. Without them, it would be nearly impossible to achieve the precision and efficiency required to render realistic scenes and animations.

Matrices and vectors let us group together data and operations - e.g., 3d direction consisting of an x, y and z value - which we can represent as a single vector variable called vr - similary, we want to perform a rotation around the x-axis - we can represent this calculation (e.g., angle and axis values) using a single matrix variable called Mrx.

Let's say we want to perform the operation - we can do by saying: v = vr * Mrx.

A beautiful things about matrices and vectors with languages like C/C# which supports operator overloading - lets you write code that is very similar to the mathematical syntax (very readable).


Just Numbers


In a nutshell, aa matrix (and vectors) are just arrays of numbers. We put the numbers into a structured array to streamline the calculations. These calculations can be far and wide - but in computer graphics they usually involve trasnforms.

• Matrix - 1, 2, 3, .. dimensional array (typically represents transform operation)
• Vector - 1 dimensional array (typically for the positional or directional data)


To Write Your Own or Not Write Your Own - That's the Question


When using matrices and vectors - should you use an off the shelf solution or write your own? It really depends what you want to do!

• Write your own easily - gives you lots of freedom and customizability (great learning tool)
• GLM Library - Free, open source and easily accessable - OpenGL Mathematics (GLM) is a header only C++ mathematics library
• glMatrix - If you're working with JavaScript - free and robust vector and matrix library (common algorithms)

Very important to understand this - using a pre-built library is NOT a solution for ignorance - you still need to know that the matrices and doing and why - especially when things don't work.



From the film
From the film 'dumb and dumber to' - Lloyd as a homeless man - to illustrate that you need to know what any pre-written matrix and vector libraries function so you can use them correctly.



Essentials


• Create vectors and points
• Different matrix sizes (2x2, 3x3, 4x4)
• Basic transforms (rotation, translation, scaling)
• Homogeneous coordinates (transforming to and from them e.g., vec3 to vec4 and back vec4 to vec3)
• These transforms in modern graphics pipelines (GPU hardware is optimized and built around matrix operations)















 
Advert (Support Website)

 
 Visitor:
Copyright (c) 2002-2025 xbdev.net - All rights reserved.
Designated articles, tutorials and software are the property of their respective owners.