← All Base Form Math projects
BM-12NOT STARTEDBASE FORM · LINEAR ALGEBRAMATHPYTHON

Mini 3D renderer

Load a 3D model file, spin a camera around it and draw the wireframe with rotation, projection and matrix chaining you write yourself.

EST.8 h
REWARD+100 XP
AFTERoriginal

ML-ARENA BENCHMARKS

YOUR NUMBER VS THE INDUSTRY'S
METRICINDUSTRYMINE
projected vertices
GOAL · match within 1e-9
scipy.spatial.transform.Rotation—
no results yet
YOUR RESULTS

Your recorded results appear here.

Brief

Every 3D game draws its world the same way. Each point of a model is moved, turned, and then flattened onto the screen. All of that is matrix multiplication applied to thousands of points at once. In this project you write the whole chain yourself and point it at a real model file.

The chain is model, then world, then camera, then screen. Each step is a matrix, and matrix products compose, so the first three steps collapse into one 4 × 4 matrix. To fit translation into a matrix, each point gets a fourth coordinate w=1w = 1. These are homogeneous coordinates. The last step, perspective, is not a matrix product. You divide by depth:

x′=f xz,y′=f yzx' = f\,\frac{x}{z}, \qquad y' = f\,\frac{y}{z}

Rotations are special matrices. Their columns are orthonormal and their determinant is 1, so R−1=R⊤R^{-1} = R^\top. That makes the camera cheap. The view matrix is the inverse of the camera's pose, and for a pose with rotation RR and position tt that inverse is just R⊤R^\top and −R⊤t-R^\top t. No general inverse needed. You'll still check it against np.linalg.inv.

VISUALFig. 1
z IMAGE PLANE CAMERA P = (y, z) y y′ f z similar triangles: y′ = f · y / z
A pinhole camera from the side. Similar triangles give y′ = f · y / z. Why it's here: The projection step is one division by depth. The picture shows where that division comes from.
HINT · OBJECTIVE 2
Stuck? Hints stay hidden until you ask.
HINT · OBJECTIVE 4
Stuck? Hints stay hidden until you ask.

DATA · any .obj model

Objectives

0 / 6 CLEARED

Read-only. Log in to update progress.

VICTORY CONDITIONS

  1. Projected vertices from your own rotation code match the same pipeline built on `scipy.spatial.transform.Rotation` within 1e-9, for 100 random angle triples. Record the max difference with `python tools/mlarena.py record BM-12 "<max diff>"`.
  2. Your rotation matrices pass RᵀR = I and det R = 1 to 1e-12, and your view matrix matches np.linalg.inv of the camera pose.
  3. The README has a spinning wireframe (GIF or MP4) of a real .obj model.

Side quests

Back-face culling: take the cross product of two edges of each face to get its normal, and hide faces that point away from the camera.
Flat shading: fill each triangle with a brightness set by the dot product of its normal and a light direction. Draw far faces first.

Terms in plain words

Rotation matrix
A 3 × 3 matrix with orthonormal columns and determinant 1. It turns points without stretching them, and its inverse is its transpose.
Homogeneous coordinates
Give each point a fourth coordinate w = 1. Then translation is a matrix product too, and a whole chain of moves becomes one 4 × 4 matrix.
View matrix
The inverse of the camera's pose. It moves the world so that the camera sits at the origin, looking down one axis.
Perspective projection
Divide x and y by the depth z, so things further away look smaller: x′ = f·x / z.
OBJ file
A plain-text 3D model format. Lines starting with v are vertices; lines starting with f list the vertices of a face, counting from 1.