I tried to search on the internet but I didn't find yet an answer to my problem.
I have 3 points in 3D space. I want to define an index which tells me how close I am to be collinear. I don't want to use a test like:
1) Create a line between 2 points
2) Check if the third point is on this line
This because in my case the points are moving points and I want to know if I am close to be collinear.
I need to implement this at each time step in an algorithm (in Matlab for example).
From what I searched on the internet I think a solution might be the following.
I have three vectors $a$, $b$, $c$. I could use the $||(a-b)\times(b-c)||$
This will be zero if the points lay on a line.
Is that enough?
I hope I was clear. Thank you for your time.
That'll work OK, in the sense that the farther that $b$ is from the line $ac$, the larger that number will be.
But there's a problem: if you picked different points $a'$ and $c'$ on your line, the measure would change. Probably best to divide by $\| c - a \|$ to "normalize" the value, and make it independent of the choice of $a$ and $c$ (as long as they're distinct, and as long as they're far enough apart to not get you into the realm of roundoff errors, etc.).
From the point of view of speed, computing the squared norm may make more sense.
As an alternative, you can compute the point $b'$ on the line $ac$ that's closest to $b$, and then compute the squared length of $b - b'$.
TO find $b'$, write it as $a + s(c-a)$, and then insist that $(b - b') \cdot (c - a) = 0$. This gives \begin{align} (b - (a + s (c - a)) ) \cdot (c - a) =0. \end{align} Letting $d$ denote $c - a$, we get \begin{align} (b - (a + s d) ) \cdot d &=0 \\ ((b - a) - s d ) \cdot d &=0 \\ (b - a) \cdot d &= s d \cdot d \\ \frac{(b - a) \cdot d}{d \cdot d} &= s \end{align} From this you can compute $b'$, $b - b'$, and the squared length of $b - b'$.