fformiwla
Examples of geometry calculations for computer graphics.
Vectors
Normalize / unit vector
Dot product as projection
2D cross product
Angle between two vectors
Rotate a point around a pivot
Lines & points
Distance between two points
Line midpoint
Point along a line (lerp)
Closest point on a line segment
Perpendicular distance from a point to a line
Line-segment intersection
Reflect a point across a line
Reflect a line off another line
Circles
Circumference point
Circles collision distance
Point-in-circle (hit test)
Circle ↔ circle intersection
Circle ↔ line intersection
Tangent lines from an external point
Circumcircle of three points
Reflect a line off a circle
Triangle incircle
Incircle & circumcircle together
Apollonius problem (3-circle tangent)
Triangles
Point-in-triangle (barycentric)
Triangle signed area & winding
Polygons
Point-in-polygon (ray casting)
Polygon area & centroid (shoelace)
Axis-aligned bounding box
Convex hull (gift wrap)
Polygon collision (SAT)
Random sampling
Uniform random point in a circle
Uniform random point in an annulus
Uniform random point in a triangle
Distance fields
SDF of a circle
SDF of a box
SDF smooth min (blob union)