Calculate a point at a distance perpendicular to a vector offset (2D)

To calculate a point at a distance perpendicular to a vector offset

Point perpendicular to offset

First the point on the vector P' at the required offset needs to be calculated. This easy to do:

P' = A + (B-A) * offset

P'_x = A_x + (B_x - A_x) * offset
P'_y = A_y + (B_y - A_y) * offset

The vector to move the point P’ on is perpendicular to \overline{AB}. This vector can be calculated using a 90 degree rotation matrix:

\begin{bmatrix}  cos \alpha   & -sin \alpha \\   sin \alpha  & cos \alpha \\ \end{bmatrix}   = \begin{bmatrix}  cos 90  & -sin 90 \\   sin 90  & cos 90\\ \end{bmatrix} = \begin{bmatrix}  0  & -1 \\   1  &  0 \\   \end{bmatrix}

The matrix shows in the the first row x'= -y and the second row shows y'= x

You can safely ignore the stuff above if you are only interested in getting the job done. The final formula is:

\begin{pmatrix}x'\\y' \end{pmatrix}= \begin{pmatrix}-y\\x \end{pmatrix}

We will call the vector (\overline{P'P}) vector C.

C =\begin{pmatrix}- (B_y - A_y)\\   B_x - A_x \end{pmatrix}

Vector C needs to be normalized (divided by it’s length / magnitude).

\hat{C} =\dfrac{C}{\left \|C \right \|}

The resulting formula becomes:

P = (A + (B-A) * offset) + \hat {C} * distance

A positive distance will get the point above the vector, a negative below the vector.

Lastest update in March 2022, inital post in October 2011

Write a comment

I appreciate comments, suggestions, compliments etc. Unfortunately I have no time to reply to them. Useful input will be used for sure!