Identifying projection between 2 points

59 Views Asked by At

Apologies in advance for misusing mathematics terms..

I have two points, A and B in 2D.

I have a user who is traveling between these 2 points (now a vector?).

These points are arbitrarily far apart.

I want to calculate 2 projections(?) at half way between these 2 points 100m away from the original line, one projection at 90 degrees and the other at 180 degrees.

Better explained as a picture here

In the above image, I have points A and B, while I want to calculate points C and D.

Can somebody help me with this math calculation (I will be implementing in python if that helps with a familiar syntax)?

1

There are 1 best solutions below

0
On BEST ANSWER

$A=(x_1, y_1)$ and $B=(x_2, y_2)$. The midpoint between $A$ and $B$ is $$M = \frac{1}{2}(A+B) = \frac{1}{2}(x_1+x_2, \, y_1+y_2).$$ The vector $\overrightarrow{AB} = B-A = (x_2-x_1, \, y_2-y_1)$ and an orthogonal to that vector is $\overrightarrow{N} = (y_1-y_2, \, x_2-x_1)$ (observe the first coordinate is $y_1-y_2$ and not $y_2-y_1$! The order is important!). An orthogonal to $\overrightarrow{AB}$ vector of length one is then $\overrightarrow{n} = \frac{1}{|\overrightarrow{N}|} \overrightarrow{N} $ and thus the line through the midpoint $M$ orthogonal to $AB$ is given by equation $$X = M + t\overrightarrow{n} =X = M + t\frac{\overrightarrow{N}}{|\overrightarrow{N}|} ,$$ which in coordinate notations look like this $$x = \frac{1}{2}(x_1+x_2) + \frac{t(y_1-y_2)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}$$ $$y = \frac{1}{2}(y_1+y_2) + \frac{t(x_2-y_1)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}.$$ Point $C = (C_1,C_2)$ is obtained for $t=100$ and point $D=(D_1,D_2)$ is obtained for $t=-100$. In other words

$$C_1 = \frac{1}{2}(x_1+x_2) + \frac{100(y_1-y_2)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}$$ $$C_2 = \frac{1}{2}(y_1+y_2) + \frac{100(x_2-y_1)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}$$ and

$$D_1 = \frac{1}{2}(x_1+x_2) - \frac{100(y_1-y_2)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}$$ $$D_2 = \frac{1}{2}(y_1+y_2) - \frac{100(x_2-y_1)}{\sqrt{(x_2-x_1)^2+(y_2-y_1)^2}}.$$ (Again, observe that the expression right after 100 is $y_1-y_2$ and not $y_2-y_1$! The order is important!) So when you write it as programming language code, simply get the input data $A=(x_1,y_1)$ and $B=(x_2,y_2)$ as well as the number $100$ and then write as an output the explicit algebraic expressions I wrote above.