Get the distance between a point and vector (2D)

Determine the distance of point P and vector through points P1, P2

Distance point – vector

dist = \dfrac{\left | (B_x - A_x) (P_y - A_y) - (B_y - A_y) (P_x - A_x) \right |}{||\overline{AB}||}

This is a ‘2D cross product’ of \overline{AB} and \overline{AP}. Since the cross product is the parallelogram surface of the two vectors, dividing it by the length of \overline{AB} to get the distance.

\left\|\overline{AB}\right\| = \sqrt{(B_x - A_x)^2 + (B_y - A_y)^2}

Lastest update in January 2022, inital post in November 2015

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!