MCPcopy Create free account
hub / github.com/cinder/Cinder / DistanceFromLineSqrd

Function DistanceFromLineSqrd

blocks/Clipper/src/clipper.cpp:4328–4342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4326//------------------------------------------------------------------------------
4327
4328double DistanceFromLineSqrd(
4329 const IntPoint& pt, const IntPoint& ln1, const IntPoint& ln2)
4330{
4331 //The equation of a line in general form (Ax + By + C = 0)
4332 //given 2 points (x�,y�) & (x�,y�) is ...
4333 //(y� - y�)x + (x� - x�)y + (y� - y�)x� - (x� - x�)y� = 0
4334 //A = (y� - y�); B = (x� - x�); C = (y� - y�)x� - (x� - x�)y�
4335 //perpendicular distance of point (x�,y�) = (Ax� + By� + C)/Sqrt(A� + B�)
4336 //see http://en.wikipedia.org/wiki/Perpendicular_distance
4337 double A = double(ln1.Y - ln2.Y);
4338 double B = double(ln2.X - ln1.X);
4339 double C = A * ln1.X + B * ln1.Y;
4340 C = A * pt.X + B * pt.Y - C;
4341 return (C * C) / (A * A + B * B);
4342}
4343//---------------------------------------------------------------------------
4344
4345bool SlopesNearCollinear(const IntPoint& pt1,

Callers 1

SlopesNearCollinearFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected