Welcome to the Spatial Computing revolution... for A Square.
- π Introduction
- π Project Overview
- π Getting Started
- π My Handwritten Notes
- π The Math of Flatland
- π€ Contributing
- π License
Have you ever wondered: "How would a tech giant build XR glasses for the inhabitants of Edwin Abbott's Flatland?"
Me too.
It raises some fascinating questions. How do you SLAM your way through a universe that only has 3 degrees of freedom? How do you perform robust Visual Odometry when your "image" is nothing more than a 1D strip of pixels?
Flatland XR is a serious interactive tutorial disguised as a geometry joke. It implements a standard Visual-Inertial SLAM (VI-SLAM) stack, but mathematically projected down to a 2D world.
By stripping away the Z-axis - and the accompanying headaches of 3D rotation groups, quaternions, and gimbal locks - we can explore the core algorithms of modern VI-SLAM (MSCKF, Bundle Adjustment, and Factor Graphs) in their purest, most understandable form.
Important
π§ Under Construction
This project is in the early stages of development. You will encounter buggy algorithms, incomplete documentation, and missing features. All help is welcomed, their XR glasses won't be built by themselves... I think.
Below is my vision for the full-stack perception pipeline:
- Simulation: A configurable "World Editor" that creates 2D environments and simulates the glasses moving through them. It generates noisy sensor data (1D Line-Scan Cameras & 2D IMU).
- Frontend: 1D Optical Flow tracking and RANSAC-based geometric verification to reject moving outliers.
- Backend: A choice of state-of-the-art estimators (MSCKF+BA, Factor Graph) to fuse visual and inertial data.
- Visualization: A real-time dashboard using ImGui/ImPlot/ImPlot3D to analyze states, residuals, covariances, etc.
- Food for thought: 2D gaussian splatting? 2D ray tracing? Depth estimation? Lens distortion? Simulate 2D black hole (and visualize the space distortion with ImPlot3D)? Give each habitant an LLM so they can go on with their lives? Use rain measurements for state estimation?
./build.sh --help
# Desktop build
./build.sh --run
# Web build
./build.sh --web --run
You should get something like this:
Have fun playing around!
Caution
Spoilers Ahead!
The section below contains significant plot details. I highly recommend reading the book first so you can experience the dimensional shift and social satire firsthand.
To create these XR glasses, first we need to understand the physics that govern Flatland. Below is my interpretation of Flatland's physics, along with a breakdown of the core concepts presented in each chapter.
The beautiful animation you just witnessed is an SVG generated from my actual handwriting, and it changes color depending if you use light/dark mode.
In Flatland, the pose of a rigid body is defined as
The 1D line-scan camera performs a projective transformation mapping 2D points in the Euclidean plane
Coordinate Frame Convention:
Let
-
$\mathbf{x}_C$ : Forward (optical axis). -
$\mathbf{y}_C$ : Left (parallel to the sensor array).
World-to-Camera Transformation:
Let
The landmark is transformed into the Camera frame via the rigid body transformation:
Projective Model:
The projection from the Euclidean camera frame to the image line is a two-step process involving normalization and intrinsic scaling.
-
Projection to Normalized Coordinates:
First, the point
${}_{C}\mathbf{l} = [{}_C l_x, {}_C l_y]^\top$ is projected onto the normalized image plane (at$x=1$ ) to obtain the homogeneous normalized coordinate$\hat{\mathbf{x}}$ :
- Intrinsic Scaling:
We map the normalized coordinate to the pixel frame using the Intrinsic Matrix
where
-
$f_x$ : Focal length (pixels) -
$c_x$ : Principal point (pixels)
Carrying out the multiplication yields the homogeneous pixel coordinate:
Thus recovering the scalar pixel coordinate
Visibility Constraints:
A landmark is considered a valid measurement candidate if and only if it lies within the sensor's field of view (FOV) and in front of the optical plane:
Alternatively, defined by the image width
Measurement Model:
The observed pixel coordinate
The Inertial Measurement Unit (IMU) consists of a 2-axis accelerometer and a 1-axis gyroscope. It measures specific force and angular velocity expressed in the Body frame
Definitions:
-
${}_{W}\mathbf{g} = [0, -g]^\top$ : Gravity vector in the World frame (pointing "South"). -
${}_{W}\mathbf{a}$ : True kinematic linear acceleration of the body in the World frame. -
$\omega$ : True angular velocity of the body ($\dot{\theta}$ ). -
${}_{W}\mathbf{R}_{B}$ : Rotation of the Body frame with respect to the World frame.
Accelerometer Model: The accelerometer measures the specific force (proper acceleration), which is the kinematic acceleration minus the gravitational acceleration, projected into the Body frame.
Where:
-
$\mathbf{b}_a \in \mathbb{R}^2$ : Accelerometer bias (modeled as a random walk). -
$\boldsymbol{\eta}_a \sim \mathcal{N}(\mathbf{0}, \boldsymbol{\Sigma}_a)$ : Additive Gaussian white noise.
Gyroscope Model: The gyroscope measures the angular rate of the Body frame relative to the World frame. In 2D, the axis of rotation is always orthogonal to the plane (the Z-axis).
Where:
-
$b_\omega \in \mathbb{R}$ : Gyroscope bias (modeled as a random walk). -
$\eta_\omega \sim \mathcal{N}(0, \sigma_\omega^2)$ : Additive Gaussian white noise.
IMU Mechanization (State Propagation):
We assume the acceleration and angular velocity remain constant between discrete time steps
Let the state be defined as orientation
- Orientation Update:
- Velocity Update: First, we reconstruct the world-frame acceleration from the measurement:
- Position Update:
Found a bug in the 2D Jacobian derivation? Want to add a "Fish-eye" 1D lens model? PRs are welcome!
This project is licensed under the MIT LICENSE. Feel free to use this to build your own 2D Metaverse.
