Find a point that is perpendicular to line and write it in javascript

1.2k Views Asked by At

Hi and sorry if my post is not the best but is my first time in something like this I have seen this post,

I have two directional points. Point A going to point B. Each point has an X and Y coordinate.

What I am trying to do is find a point C, with distance d. The two constraints are that C has to be perpendicular to where B ends AND BC is always 90 degrees anti-clockwise relative to AB.

Essentially what I am asking is what are the steps to solve for C using those two constraints.

enter image description here

the user quasi answered in this post whit this form and anser

If A,B are represented as complex numbers a,b, then C is represented by the complex number c, where c is given by

c=b+(di)b−a/|b−a|

I would like know if someone can tell me the way to put that expresion in javascript, whit cordinates x,y or longitude and latitude

Thans you

1

There are 1 best solutions below

1
On BEST ANSWER

Given $A(x_A,y_A)$ and $B(x_B,y_B)$, the required point $C(x_C,y_C)$ is given by: \begin{align}%$c=b-id\frac{a-b}{|a-b|}$ x_C&=x_B+d\frac{y_A-y_B}{\sqrt{(x_A-x_B)^2+(y_A-y_B)^2}}& y_C&=y_B-d\frac{x_A-x_B}{\sqrt{(x_A-x_B)^2+(y_A-y_B)^2}}& \end{align} To get it in javascript:

C={
   x:B.x+d*(A.y-B.y)/Math.sqrt(Math.pow(A.x-B.x,2)+Math.pow(A.y-B.y,2)),
   y:B.y-d*(A.x-B.x)/Math.sqrt(Math.pow(A.x-B.x,2)+Math.pow(A.y-B.y,2))
}