Easily Dealing with Any-Dimensional Planes

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

Easily Dealing With Any-Dimensional Planes published on Dec 24 2025 Writing the post from yesterday reminded me of another well-known representation for a geometric primitive, the plane, that makes code pleasing to look at and simple. Planes In general, a "plane" is an n-1 dimensional sub-space of an n-dimensional space that is flat. There's a mathematically rigorous definition of what "flat" really means, but intuitive understanding is sufficient for the purposes of this explanation. To fully specify a plane, we only need two things: the plane's normal vector (which we'll call `n`) and any point within the plane (we'll refer to it as `o`). But we don't actually need to store both the point and the vector in our representation. By definition, the plane's normal vector should be orthogonal to any vector within the plane (their dot product has to be 0). Therefore, if a point `p` belongs to the plane, the following must be true: dot(p - o, n) = 0 Let's for now assume the 3D case and expand the above expression to individual coordinates (everything works exactly the same for N-dimensional case). We'll get: (p_x - o_x) * n_x + (p_y - o_y) * n_y + (p_z - o_z) * n_z = 0 // which can be rewritten as p_x * n_x + p_y * n_y + p_z * n_z - (o_x * n_x + o_y * n_y + o_z * n_z) = 0 // or otherwise: dot(p, n) - dot(o, n) = 0 Turns out that in order to determine whether a point lies on a plane, we actually need just the normal vector and the scalar value `dot(o, n)`. If we recall that the dot product is the length of the projection of one vector onto the other, it's easy to see that `dot(o, n)` is simply the distance from the coordinate space origin to the plane along the direction of the normal vector. This suggests the following representation: template <class ScalarT=float, unsigned N = 3> using hyperplane = vec<ScalarT, N+1> Assuming that your plane's normal vector is already of unit length, it's really easy to make a new plane (if the normal isn't unit length, you'd have to norm...

First seen: 2025-12-30 13:03

Last seen: 2025-12-30 13:03