Lesson goal: LEGO 3D Studio: Solid Geometry & Discrete Coordinates

Previous: Frogger: Periodic Traffic & Relative Velocity | Home | Next: Flappy Bird: Flight Timing & Kinematics

In 1958, Danish carpenter and inventor Godtfred Kirk Christiansen patented the modern LEGO brick with its revolutionary cylindrical stud-and-tube coupling system.

Beyond being the world's most beloved building toy, LEGO bricks are a magnificent tool for exploring solid geometry, discrete 3D coordinate grids, and spatial algorithms!

1. The Discrete Integer Grid: $(x, y, z)$

In conventional 3D computer graphics, positioning objects often requires complex floating-point numbers. In our 3D LEGO Studio, coordinates are completely discrete integers:
  • $x$ (Horizontal stud index): Steps left and right along the baseplate ($-16 \dots +16$).
  • $z$ (Depth stud index): Steps forward and backward along the baseplate ($-16 \dots +16$).
  • $y$ (Vertical layer index): Integer tier count ($y = 0$ rests directly on the baseplate, $y = 1$ is layer 1, $y = 2$ is layer 2, etc.).


2. Brick Proportions & Interlocking Overhangs

LEGO bricks follow precise mathematical ratios:
  • Stud Pitch: The horizontal center-to-center spacing between studs is $10\text{ units}$.
  • Brick Height: One standard brick is $12\text{ units}$ tall—a classic $6:5$ height-to-width aspect ratio!
  • Plates: A LEGO plate is exactly $\frac{1}{3}$ the height of a brick ($4\text{ units}$).
  • Interlocking Strength: When a brick on layer $y = 1$ spans across two adjacent bricks on layer $y = 0$, it distributes shear forces across both pillars, producing exceptional structural stability!


3. Solid Geometry & The Sum of Squares $\sum k^2$

Consider building a stepped pyramid where each tier $k$ (from $k = 1$ at the apex to $k = N$ at the base) is a square grid of $k \times k$ bricks.

The total number of bricks in the pyramid is given by the famous Sum of Squares formula: $$V(N) = \sum_{k=1}^N k^2 = 1^2 + 2^2 + 3^2 + \dots + N^2 = \frac{N(N + 1)(2N + 1)}{6}$$ For a 4-tier pyramid ($N = 4$): $$V(4) = 1 + 4 + 9 + 16 = \frac{4 \times 5 \times 9}{6} = 30\text{ bricks}$$

Controlling the LEGO Studio with Lua

  • lego_init(size): Creates a green baseplate of $size \times size$ studs (default 32).
  • brick(x, y, z, width, length, color): Places a brick at grid position $(x, y, z)$ with stud dimensions $(width \times length)$ and given color.
  • plate(x, y, z, width, length, color): Places a thin plate ($\frac{1}{3}$ brick height).
  • lego_clear(): Clears all placed bricks.
  • Color Palette: "red", "blue", "yellow", "green", "white", "black", "orange", "cyan", "gold", "gray", "darkgray", "sand_yellow".
lego_init(32)
brick(-6, 0, -2, 2, 4, "red")

for y = 0, 9 do

  brick(0, y, 0, 2, 4, "blue")
end
Move the mouse over a dotted box for more information.

  • Interactive 3D Orbit Controls: Left-click and drag to rotate the model, right-click to pan, and scroll the mouse wheel to zoom in and inspect studs!
  • Preset Camera Views: Use the viewport buttons to snap instantly to Isometric, Top, or Front angles.
  • Live Telemetry HUD: Real-time tally of total bricks placed, total studs (volume), and maximum layer height.
  • 📥 Export to LDraw (.ldr): Click Export .ldr to download your coded model and open it in official digital CAD programs like BrickLink Studio or LeoCAD!

Now you try. Can you add more bricks, change colors, or build a tower?

Type your code here:


See your results here: