Check if two segments (or vectors) are parallel

To check if two segments S_A and S_B are parallel, compute the vector define by each segment and check if the cross product of the vectors is a null vector


First compute vectors \vec{V_A} and \vec{V_B} :



Now compute the cross product :

 \vec{C} = \vec{V_A} \times \vec{V_B}

\vec{V} is null if S_A is null or S_B is null or S_A and S_B are parallel.

C++ source code

* \brief rOc_segment::isParallel check if current segment and S are parallel
* A null segment is necessarily considered as parallel
* \param S is the segment to check with the current one
* \return true the segments are parallel or at least one of the segment is null
* false the segments are non null and not parallel
bool rOc_segment::isParallel(rOc_segment S)
// Extract main vector
rOc_vector VA=this->vector();
rOc_vector VB=S.vector();

// If the dot product is a null vector, segments are parallel (or at least one is null)
return VA.cross(VB).isNull();