Check if a given coordinate lies in path of a ray (coordinate geometry)

1k Views Asked by At

enter image description here

As shown in the image I have two known coordinate pair A and B and few other known coordinate pairs (RED blob) on the graph.

I need to know if any of the other given coordinates fall in line of the ray created by coordinates A and B.

I need some mathematical formula or any appropriate way to know this.

I need to implement the same in code.

Please help!

4

There are 4 best solutions below

2
On BEST ANSWER

Suppose your third, unknown point is $C$. If $C-A=n(B-A)$, C is in the ray, where n represents an arbitrary real.

So, an even better way to think of that is to find the slope $\frac{x_b-x_a}{y_b-y_a}$ and see if it is equivalent to the slope $\frac{x_c-x_a}{y_c-y_a}$

0
On

Substitute the coördinates $(x\mid y)\quad$ into $\begin{vmatrix} x&y&1\\ 11&10&1\\ 37&16&1 \end{vmatrix}\quad$.

If the result is 0, then $(x\mid y)\quad$ is in the ray.

0
On

Find the equation of the line in parametric vector form, so that at $t = 0$ we have Point A and at $t = 1$, we have Point B: $$ \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} 11 \\ 10 \end{bmatrix}(1 - t) + \begin{bmatrix} 37 \\ 16 \end{bmatrix}t $$

Then to check if some point $(x_0, y_0)$ lies on the ray, simply plug it into the system of equations and see if it is possible to consistently solve for some $t \geq 0$. For example, $(89, 28)$ lies on the ray, since: $$ 89 = 11(1 - t) + 37t = 26t + 11 \implies 26t = 78 \implies t = 3 \geq 0 \\ 28 = 10(1 - t) + 16t = 6t + 10 \implies 6t = 18 \implies t = 3 \geq 0 $$

2
On

Let the red dot have co-ordinates $(x_r,y_r) $

Then collinearity is established by

$$ \frac{ y_b-y_a}{x_b-x_a} =\frac{ y_b-y_r}{x_b-x_r }.$$