Considérons trois points
,
et
. Un moyen efficace de savoir si les trois points sont alignés est de calculer le produit vectoriel de
et
. Si
retourne un vecteur nul, soit les trois points sont alignés, soit deux points ou plus sont coincidents.
Code source C++
/*!
* \brief rOc_segment::isPointAligned check if a point is aligned with the segment
* \param P point to test
* \return ROC_SEGMENT_INTERSEC_NONE if the point doesn’t lay with the segment
* ROC_SEGMENT_INTERSEC_EXTREMITY_P1 if the point is merged with P1
* ROC_SEGMENT_INTERSEC_EXTREMITY_P2 if the point is merged with P2
* ROC_SEGMENT_INTERSEC_CROSS if the point belongs to the segment (extremity no included)
*/
bool rOc_segment::isPointAligned(rOc_point P)
{
// Compute vectors AB and AC
rOc_vector AB=this->vector();
rOc_vector AC(this->point1(),P);
// Check if the cross product is a null vector
if (AB.cross(AC).isNull()) return true;
return false;
}