Geometry snippets
Line equation from two points
To obtain a line equation of the form from two points and , set:
Source: https://bobobobo.wordpress.com/2008/01/07/solving-linear-equations-ax-by-c-0/
Distance from point to line segment
// https://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm
static float sdLineSegment(glm::vec2 p, glm::vec2 a, glm::vec2 b)
{
auto pa = p - a;
auto ba = b - a;
auto h = glm::clamp(glm::dot(pa, ba) / glm::dot(ba, ba), 0.f, 1.f);
return glm::length(pa - ba * h);
}