Example #1
0
 /// <summary>Finds the lowest distance of point P to a line segment defined by points A and B</summary>        
 public static float distance_from_point_to_segment(crds2 a, crds2 b, crds2 p)
 {
     float l2 = a.dist_squared(b);
     if (l2 < 0.000001f) return a.dist(p); // case : a == b
     float t = crds2.dot(p-a, b-a) / l2;
     if (t < 0f) return a.dist(p);
     if (t > 1f) return b.dist(p);
     crds2 proj =  a.lerp(b, t);
     return proj.dist(p);
 }