Vector2d PointLineProjection(Vector2d P, Vector2d A, Vector2d B) { Vector2d abNorm = (B - A); abNorm.Normalize(); Vector2d ap = P - A; double apLen = ap.Length(); double angleCos = Vector2d::DotProduct(ap, abNorm) / apLen; double projLen = apLen * angleCos; return A + (abNorm * projLen); }
static double GetAngleRad(const Vector2d &a, const Vector2d &b) { return acos(DotProduct(a, b) / (a.Length() * b.Length())); }