Cutting Up Curved Things (With Math)

https://news.ycombinator.com/rss Hits: 3
Summary

Your GPU doesn't know what a cylinder is. It knows triangles! That's it. Three points, maybe a color. The entire vocabulary of graphics hardware fits on an index card. 12 triangles. That's all a cube is. So before any curved surface can be rendered, someone has to chop it into triangles. Lots of them! Arranged just right so the illusion holds. That's tessellation. Triangles all the way down A triangle mesh is just two arrays: vertices: [x₀, y₀, z₀, x₁, y₁, z₁, x₂, y₂, z₂, ...] indices: [0, 1, 2, 0, 2, 3, ...] Vertices are points in space, and indices say which three points form each triangle. That's the entire data structure! Every 3D model you've ever seen - every game character, every CAD render, every Pixar frame - is just these two arrays, fed to a GPU that draws triangles really, really fast. The translation problem In vcad's kernel, a cylinder isn't triangles. It's a mathematical function: fn point_on_cylinder(u: f64, v: f64) -> Point3 { Point3::new( radius * u.cos(), radius * u.sin(), v ) } Give me an angle u and a height v, and I'll give you the exact point. Infinite precision! No facets. Beautiful for math, but useless for rendering. The tessellator's job is to sample this function enough times to build a convincing mesh. Sampling a surface How do you turn a smooth surface into triangles? You sample it! Lay down a grid in parameter space, the flat (u, v) domain. Evaluate the surface at each grid point to get 3D coordinates, then connect adjacent points into triangles. More samples = smoother result = more triangles = slower everything. 32 segments around a circle is plenty for most CAD. 64 if you're zooming in. 128 if you're patient! The easy case: flat faces Planar faces don't need sampling because the vertices are already there in the topology. You just need to connect them! For convex polygons, fan triangulation works perfectly: Pick one vertex, draw triangles to every other pair, and you're done! A square becomes 2 triangles, a hexagon becomes 4, and an...

First seen: 2026-01-29 23:35

Last seen: 2026-01-30 01:35