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}

Leave a Reply

Your email address will not be published. Required fields are marked *