Geometry in Programming

2026-12-03 @matyo91

Choose a coordinate frame

A trail marker is the origin. East and north are the positive axes. The point (2, 1) records a displacement of two metres east and one metre north.

01 | Darkwood Code Calendar @matyo91

Track a quarter turn

Rotate anticlockwise around the origin. The east unit vector moves north and the north unit vector moves west. This gives (x, y) → (−y, x). A point at (2, 1) becomes (−1, 2).

02 | Darkwood Code Calendar @matyo91

Compare a reflection

Reflect across the vertical axis using (x, y) → (−x, y). The distance to the axis stays the same. A turn and a reflection can produce different results when their order changes.

03 | Darkwood Code Calendar @matyo91

Index negative positions

Divide by the cell width and take the floor. With four-metre cells, −0.2 belongs to index −1. A bounding-box lookup checks nearby cells before it tests individual points.

04 | Darkwood Code Calendar @matyo91

Keep track of resolution

Flow separates rotation, bucketing and reporting. The count next to each mean tells you how many readings it represents. A large cell can hide detail and a small cell can leave holes.

05 | Darkwood Code Calendar @matyo91

Choose units with care

A game can use screen pixels and a downward-pointing vertical axis. A map can use longitude and latitude. For distances, document a suitable projected coordinate system or the metric used.

06 | Darkwood Code Calendar @matyo91