Untitled


Mathematics

These are my notes on mathematics. These notes originated as I was trying to recover my lost (or rusty) maths knowledge so I could apply it to game development and building a better understanding of how 3D spaces work.

Pythagoras' Theorem

This is a foundation of geometry, dealing with the relationship between the sides of a right-angle triangle.

A right-angle triangle

In this triangle, we express the sidea as a, b, and c. We find that the square of a added to the square of b equals the square of c.

Formulae for deriving the hypotenuse

We can rearrange this formula as:

Rearranged formulae

Understanding the length of c is useful to us, as typically in a 2D, tile-based space, we can easily discover the X,Y coordinates of objects.

2D game space example

So, as an example:

import math

def distance_between_objects(p1x, p1y, p2y, p2y):
    """
    This calculates the distance between two points in a 2D space.
    """

    distance_x = p1x - p2x
    distance_y = p1y - p2y

    return math.sqrt(distance_x**2 + distance_y**2)

Vectors

A vector is a representation of a direction in a system. Consider the following:

A simple vector

In this system, we assume that a vector is a description of a point in relation to the origin at 0,0. The point is both a description of it's position in space, and the direction relative to the origin.

We describe vectors in a standard way; with a small arrow above the variable name, and listing it's paramaters in a vertical column:

A vector representation

But how do we calculate the length of the vector? It's back to Pythagoras' theorem:

Deriving the magnitude of a vector

You'll notice that we introduce a new piece of notation here. The vector with two vertical bars on either side is to represent the length or magnitude of the vector (the terms are interchangable):

Vector magnitude symbol

TODO: Adding vectors, 7:32, https://www.youtube.com/watch?v=DPfxjQ6sqrc&t=154s