Back to the blog
Game dev / DEVELOPMENT NOTES

Tiny.js: 2D physics in JavaScript

A small physics library for exploring polygon collisions with the separating axis theorem.

Tiny.js is a 2D physics library I wrote in JavaScript to explore collision detection. It uses the separating axis theorem, usually shortened to SAT.

A geometric idea you can see

SAT looks for an axis on which the projections of two convex polygons do not overlap. Finding that separation lets us rule out a collision.

The demo turns the idea into a scene with moving objects. Watch how the bodies behave, then follow the implementation in the source code.

Explore the project

Start with collision detection and follow the data through the simulation. Changing a shape or its position is a useful way to see what each step calculates.

Source code

Explore the project on GitHub

Written by Sergio Soriano

Development, curiosity, and shared projects.

About Sergio Soriano