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.
| 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. |
| 136 | FCOORD 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 | } |
no test coverage detected