Spaces

This will be a series on geometry (broadly speaking), applied to and demonstrated through web graphics. The code samples will be in TypeScript/React/THREE.js/react-three-fiber, but the concepts are completely general and applicable to many other areas (machine learning, modelling, optimization, …)

Geometry

For starters, what do I mean by geometry? Well, 2d and 3d geometry are particularly relevant to us because we live in 3d space. 2d shapes appear on screens and flat surfaces, while the objects around us have 3d shapes.

But geometry also comes from more abstract sources. Consider the following situations:

  • in physics, the kinetic energy EE of an object is related to its mass mm and its speed vv by the formula

    E=12mv2;E = \frac12mv^2;
  • again in physics: say an object starts from rest, and has constant acceleration aa (e.g. a=9.8 m/s2a=9.8\text{ m/s}^2 for gravity). The distance ss it travels after time tt is given by

    s=12at2;s = \frac12at^2;
  • in geometry: we consider the set of points (x,y,z)(x,y,z) in 3d space which satisfy the condition

    z=12xy2.z = \frac12xy^2.

Here's what that looks like:

These are all different physical situations. But mathematically, they're all equivalent: all that matters is the relations between the numbers, not what the numbers represent.

Understanding the geometry of the above shape is equivalent to understanding any (and all) of the more concrete situations.

For instance, an object of mass 4 kg4\text{ kg} and velocity 3 m/s3\text{ m/s} corresponds to the point (4,3,18).(4,3,18).

Complex problems may involve more than three dimensions; search algorithms routinely calculate in thousands or millions of dimensions. It's harder to visualize these problems. But we can use our physical intuition from 2d and 3d space to develop formulas that make sense in any number of dimensions. For example, in just a few posts we'll see how to talk about lines in any-dimensional space.

Even "spatial" geometry in 2d and 3d space naturally leads us to consider higher dimensions. As a simple example, a point in 6-dimensional space is equivalent to two points in 3d space, or three points in 2d space:

[1324.101][14.13021][12034.11]\begin{bmatrix*}[r] 1\\-3\\2\\4.1\\0\\1 \end{bmatrix*} \leftrightarrow \begin{bmatrix*}[r] 1&4.1\\-3&0\\2&1 \end{bmatrix*} \leftrightarrow \begin{bmatrix*}[r] 1 & 2 & 0\\ -3 & 4.1 & 1\\ \end{bmatrix*}

Spaces

This brings us to our first definition.

Subsets of Rn\mathbf R^n

The above "definition" is extremely vague. Let me be more precise:

(\in means "in" or "is an element of"). For example, (0,0)(0,0) is a point in R2,\R^2, and (3,0,1)(3,0,1) is a point in R3.\R^3. I might also write these vertically, e.g.

[00]or[301].\vec00 \quad\text{or}\quad \vecc301.

Rn\R^n is one of the most important examples of a space. Any subset of Rn\R^n is a space, and you could well take that as the precise definition. For example, the blue shape above is a subset (I could also say subspace) of R3.\R^3.

Actually, the term space doesn't have a precise definition in math (neither does number). There are a lot of technical concepts that have space in their name, which do have precise definitions, depending on what aspect of geometry we're focusing on or what tools we're using:

  • affine/vector spaces are used when studying translation and scaling;
  • metric spaces are for studying the concept of distance;
  • inner product spaces incorporate all of the above and also angles;

(We'll learn about these in due time.) But "space" on its own is just a vibe.

Coordinates

Notice the word can in the definition. There are many different ways to represent any given situation, and rarely is there a single best one. For example, 10 cm,10\text{ cm}, 3.94 in,3.94\text{ in}, and 0.33 ft0.33\text{ ft} are three different numbers corresponding to the same concept.

So, there's a space of physical distances. This space "is" the same as R,\R, but it is "equivalent to R\R in many ways". Moreover, notice that "equations" like

  +  =  3×  =  \begin{align*} \line{2em} + \line{1em} &= \line{3em}\\ 3\times\line{1.5em} &= \line{4.5em} \end{align*}

are meaningful, without even needing to assign numbers to the lengths. (Although this may be useful in verifying that the equations are true.)

In this series, I'll try to take a coordinate-free approach where we focus on the intrinsic properties of things. How we describe those spaces numerically will then be a separate step. In particular, a big chunk of geometry is just converting between different coordinate systems.

When we do calculations, they're always going to be with nn-tuples of numbers, and you can write your programs thinking this way. The benefit of the more abstract perspective is similar to the benefit of having types in your code.

Intrinsic / Extrinsic

Space in the mathematical sense means basically the same thing as shape. In everyday language, we tend to think of space as an ambient medium which is populated by shapes. It's very powerful to get rid of that distinction as every shape as a space in its own right, and then one space can embed in another in many different ways.

For instance, the following depicts two circles drawn on a torus in 3d space. We can think of the circles as living in 3d space, occupying some of the same space as the torus. But we can also forget about ambient 3d space and just think about the torus as the ambient space. Furthermore, we can think of both these circles as different embeddings of one "platonic" circle into the torus.

Access source on GitHubSource

Important Examples

Finally, let me introduce notation for some important examples.

  • as we have already seen, Rn\R^n is "nn-dimensional space". For many purposes we are especially interested in the cases R2\R^2 and R3.\R^3.

  • Frequently, we want to put bounds on the numbers we use. An interval consists of all numbers between two numbers aa and b;b; the numbers aa and bb are called the endpoints of the interval. There are different versions depending on whether we want to include the endpoints or not:

    [a,b]:={xRaxb}(a,b):={xRa<x<b}\begin{align*} [a, b] \Defeq \{ x \in \R \mid a\le x\le b \}\\ (a, b) \Defeq \{ x \in \R \mid a < x < b \} \end{align*}

We call [a,b][a, b] a closed interval and (a,b)(a,b) an open interval. There are also variants where we want to include one endpoint but not the other:

[a,b):={xRax<b}(a,b]:={xRa<xb}\begin{align*} [a, b) \Defeq \{ x \in \R \mid a\le x < b \}\\ (a, b] \Defeq \{ x \in \R \mid a < x\le b \} \end{align*}

These are sometimes called half-open intervals but there aren't individual names for them. For example, when describing angles in degrees, we're interested in the interval [0,360).[0,360).

  • In particular, the unit interval

    I:=[0,1]\I \Defeq [0, 1]

consists of all numbers between 0 and 1, inclusive of both. This space comes up a lot when dealing with paths and animation (= paths in time).

  • we write S1\Sone for a circle. This means the edge of a circle, not the points inside; a filled circle is called a disk and denoted by D2.\Dtwo. Below, I've drawn a circle on the left and a disk on the right:

The notation S1S^1 means a one-dimensional sphere. Even though it lives in two-dimensional space, the circle is itself considered one-dimensional since you can only move backwards/forwards along it. The disk, on the other hand, is considered two-dimensional.

The notations extend to higher dimensions: S2\Stwo refers to a (hollow) sphere in R3,\R^3, while D3D^3 refers to a filled-in ball. Once we learn how to make sense of "distance" in higher dimensions, we'll be able to define Sn\S n and DnD^n for all n.n.