long double BaseOfPerpendicularIsInsideSegment(Pnt p, Pnt a, Pnt b) { Pnt normal = Pnt((b - a).y, - (b - a).x); normal = normal * (1 / normal.len()); long double l = distanceFromPointToLine(p, a, b); return pointIsOnSegment(p + normal * l, a, b) || pointIsOnSegment(p - normal * l, a, b); }