[Math] Calculate 2d position of a point, at a fixed offset off the start of a vector

geometry

I'm creating piece of software that does some basic drawing, but I'm not that well skilled in geometry 🙂

I have two inputs, Position A, position B and a distance D. And i'm looking for the position of the point with offset D from A at an angle of 90 degrees from the vector:

Example of question

So, the question is: how to calculate the point in the bottom right?
Note: ofcource, is should work in any X,Y direction and in both positive and negative coordinates.

Best Answer

On the basis of your input there will be two solutions to this (assuming the vectors are in a 2D plane).

If the points are A is ($x_a$, $y_a$), B is ($x_b$, $y_b$) and D is ($x_d$, $y_d$) then the direction vectors AB and AD are at right angles so their dot-product is zero. i.e. ($x_b$ - $x_a$).($x_d$ - $x_a$) + ($y_b$ - $y_a$).($y_d$ - $y_a$) = 0. Plug in the numbers and you get a linear relation in $x_d$ and $y_d$ (unless A = B which you should check for first), and you can then express $y_d$ in terms of $x_d$ and substitue in the length equation described below.

Now set the length of AD by resolving AD.AD (the dot-product) = $L^2$ where L is the required length.

Related Question