Check whether two 2D lines are coincident.

To check whether two 2D lines are coincident, the distance of C and D to AB need to be calculated. For a coincident line both need to be (almost) zero.

The z component of the cross vector can be used for this quite elegantly.

Note: The cross vector is noted as an x e.g. AxB

To check whether the two lines AB and CD are coincident, the z-component of two cross vectors need to be calculated. Both calculate the distance of the points on line CD to AB.

AB x AC is the area of the parallelogram AB AC, dividing it with the length of AB (|AB|) gives the shortest distance of point C to line AB.

AB x AD gives the area of the parallelogram AB AD

After dividing with |AB| this is also the shortest distance of D to line AB. If both distances are small enough the lines are coincident.

dist_{abc} = \overline{AB}_x·\overline{AC}_y -   \overline{AB}_y·\overline{AC}_x
dist_{abd} = \overline{AB}_x·\overline{AD}_y -   \overline{AB}_y·\overline{AD}_x

Lastest update in March 2022, inital post in September 2011

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!