MCPcopy Create free account
hub / github.com/creatale/node-dv / nearest_pt_on_line

Method nearest_pt_on_line

deps/tesseract/ccstruct/points.cpp:136–145  ·  view source on GitHub ↗

Returns the point on the given line nearest to this, ie the point such that the vector point->this is perpendicular to the line. The line is defined as a line_point and a dir_vector for its direction.

Source from the content-addressed store, hash-verified

134// that the vector point->this is perpendicular to the line.
135// The line is defined as a line_point and a dir_vector for its direction.
136FCOORD FCOORD::nearest_pt_on_line(const FCOORD& line_point,
137 const FCOORD& dir_vector) const {
138 FCOORD point_vector(*this - line_point);
139 // The dot product (%) is |dir_vector||point_vector|cos theta, so dividing by
140 // the square of the length of dir_vector gives us the fraction of dir_vector
141 // to add to line1 to get the appropriate point, so
142 // result = line1 + lambda dir_vector.
143 double lambda = point_vector % dir_vector / dir_vector.sqlength();
144 return line_point + (dir_vector * lambda);
145}

Callers 1

ExtractFeaturesFromRunFunction · 0.80

Calls 1

sqlengthMethod · 0.80

Tested by

no test coverage detected