Check Vector3 points on one line using a Matrix

96 Views Asked by At

I know that for 3 Vector2 points (say points a, b, c) the determinant of the following matrix M is zero if they are one one line:

    | ax  ay  1 |
M = | bx  by  1 |
    | cx  cy  1 |

But how can I check this for 3 Vector3 points. I wrongly assumed it would be like this:

    | ax  ay  az |
M = | bx  by  bz |
    | cx  cy  cz |

Is there a similar way to determine that 3 points (Vector3) are on one line in 3D using a matrix and the determinant?

1

There are 1 best solutions below

0
On

3 Points A B and C are in one line (collinear) in 3D if:

→    →    →
AB × AC = 0

AB = A.sub( B );
AC = A.sub( C );

vector = AB.cross( BC );

collinear = vector.x === 0 && vector.y === 0 && vector.z === 0

collinear is true for points in one line, false if not in one line.

To keep into account any rounding errors or inaccuracies in the vectors it can be necessary to set a precision and use the absolute values:

precision = 0.0001; // set some presision
collinear = |vector.x| < precision && |vector.y| < precision && |vector.z| < precision

Different syntax:

precision = 0.0001; // set some presision
collinear = abs(vector.x) < precision && abs(vector.y) < precision && abs(vector.z) < precision;

Another way is to calculate the surface area of a triangle using those three points A, B and C. They are collinear when the surface is equal to zero:

area = 0.5 * ( Ax * ( By - Cy ) + Bx * ( Cy - Ay ) + Cx * ( Ay - By ) )

collinear = ( area === 0 )

Or

precision = 0.0001
collinear = | area | < precision