MCPcopy Create free account
hub / github.com/RoboMaster/RoboRTS / PointToLineDistance

Function PointToLineDistance

roborts_common/math/math.h:101–132  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101inline double PointToLineDistance (const double px, const double py,
102 const double x0, const double y0,
103 const double x1, const double y1) {
104 double A = px - x0;
105 double B = py - y0;
106 double C = x1 - x0;
107 double D = y1 - y0;
108
109 double dot = A * C + B * D;
110 double len_sq = C * C + D * D;
111 double param = dot / len_sq;
112
113 double xx, yy;
114
115 if (param < 0)
116 {
117 xx = x0;
118 yy = y0;
119 }
120 else if (param > 1)
121 {
122 xx = x1;
123 yy = y1;
124 }
125 else
126 {
127 xx = x0 + param * C;
128 yy = y0 + param * D;
129 }
130
131 return PointDistance(px, py, xx, yy);
132}
133
134inline double PointToLineDistance (const geometry::Point2D &point,
135 const geometry::LineSegment2D &line) {

Callers 3

DistancePointToPolygon2DFunction · 0.70

Calls 4

PointDistanceFunction · 0.85
XMethod · 0.80
StartMethod · 0.80
YMethod · 0.80

Tested by

no test coverage detected