\brief Project a point onto the line. * * If the direction vector has zero norm, the start point is returned. * * \param point The point to project. * \return The projected point on the line. */
| 203 | * \return The projected point on the line. |
| 204 | */ |
| 205 | itk::Point<TCoordRep, NPointDimension> Project(const itk::Point<TCoordRep, NPointDimension> &point) const |
| 206 | { |
| 207 | if (m_Direction.GetNorm() == 0) |
| 208 | return this->m_Point; |
| 209 | |
| 210 | itk::Vector<TCoordRep, NPointDimension> diff; |
| 211 | diff = point - this->m_Point; |
| 212 | |
| 213 | itk::Vector<TCoordRep, NPointDimension> normalizedDirection = m_Direction; |
| 214 | normalizedDirection.Normalize(); |
| 215 | |
| 216 | normalizedDirection *= dot_product(diff.GetVnlVector(), normalizedDirection.GetVnlVector()); |
| 217 | |
| 218 | return this->m_Point + normalizedDirection; |
| 219 | } |
| 220 | |
| 221 | /** \brief Test if a point is part of the line segment. |
| 222 | * |
no test coverage detected