lineDistance
75mm Returns the signed distance between point p and the line containing points a and b. Positive value on left side and negative on right as seen from a towards b. a==b gives nan. P is supposed to be Point<T> or Point3D<T> where T is e.g. double or long long. It uses products in intermediate steps so watch out for overflow if using int or long long. Using Point3D will always give a non-negative distance. For Point3D, call .dist on the result of the cross product. 15mm
4 lines tested
Needs: "Point.h"
content/geometry/lineDistance.h — Ulf Lundstrom, source: Basic math
template<class P>
double lineDist(P a, P b, P p) {
return (double)(b-a).cross(p-a)/(b-a).dist();
}