How do I check if a 3D point is between 2 other 3D points?

4k Views Asked by At

How do I check if a 3D point is between 2 other 3D points? For example, if I had an imaginary line between two 3D points, how would I check if a point is on that line?

4

There are 4 best solutions below

0
On BEST ANSWER

You have given the solution in your question already: construct a line passing two points and check if the third point belongs to this line!

You can find the line passing through two points (in any number of dimensions), by setting up a system of equations with one independent variable: all the points on the line are described by $$ p(t) = p_1 + t (p_2 - p_1)$$ for some $t\in \mathbf R$. (Note, in particular, that $p_1 = p(0)$, $p_2 = p(1)$ and $p(1/2)$ is the midpoint between $p_1$ and $p_2$.

The question is now turned into: is there a $t'$ such that a third point $p_3$ is $p(t')$? This amounts to asking whether $$ p_3 = p_1 + t(p_2 - p_1)$$ has a solution $t = t'$. We write out this in three dimensions: $$\begin{cases} x_3 = x_1 + t (x_2 - x_1) \\ y_3 = y_1 + t (y_2 - y_1) \\ z_3 = z_1 + t(z_2 - z_1)\end{cases}$$

We solve for $t$ in each equation $$\begin{cases} t = \frac{x_3 - x_1}{x_2 - x_1} \\ t = \frac{ y_3 - y_1}{y_2 - y_1} \\ t = \frac{z_3 - z_1}{z_2 - z_1}\end{cases}$$

So, the three points are aligned if $$\frac{x_3 - x_1}{x_2 - x_1} = \frac{ y_3 - y_1}{y_2 - y_1} = \frac{z_3 - z_1}{z_2 - z_1}.$$

0
On

If you are familiar with vectors, you could check whether C is aligned with A and B by finding whether the vectors $\vec{AC}$ and $\vec{AB}$ are colinear.

In practice, if you have the coordinates $(x_A, y_A, z_A), (x_B, y_B, z_B), (x_c, y_c, z_C)$, then $\vec{AB} = (x_B-x_A,y_B-y_A,z_B-z_A)$ and $\vec{AC} = (x_c-x_A, y_C-y_A, z_C-z_A)$ are colinear if and only if $$\exists \alpha\in \mathbb{R},\vec{AC} = \alpha \vec{AB} $$

Also, if $\alpha \in [0, 1]$, you can see with a drawing that this means that C is between A and B.

0
On

Hint: You can esily shift every thing, so one of the points are $(0,0,0)$.

0
On

Consider your points $A(a,b,c)$ and $X(x,y,z)$.

Then you have some vector $v = (v_1,v_2,v_3)$ which is given by $X-A$ (component wise) which points from A to X.

Any point lying on the line connecting them is of the form $A+tv$, where $t$ is some real constant (stretching the vector based at $A$ and pointing to $X$)

If you can solve for some $t$ value then your point will be on the same line and if $0\leq t\leq 1$ your point will be between $A$ and $X$.