I am trying to write an algorithm to solve this problem:
P1, P2 and P3 are given. I am looking for P4 and h.
The line between P3 and P4 should be parallel to the line between P1 and P2.
P4 should be perpendicular to the line between P1 and P2 at P2.
P1, P2 and P3 can be anywhere on the plane.
The distance h
can get calculated as shown in the wikipedia
For the coordinates of P4, first let's get the equation on line P1P2:
y-y1 x-x1
----- = ----- ==> (y2-y1) x + (x1-x2) y + x1 (y1-y2) +y1 (x2-x1) = 0 ==> Ax+By+C = 0
y2-y1 x2-x1
(A,B)
is the vector defining the perpendicular to the direction of the line. This can be easily seen if you draw the components A=(y2-y1), B=-(x2-x1)
.
Let's calculate its unitary values:
U = A / sqrt(A^2 + B^2)
, V = B / sqrt(A^2 + B^2)
Notice the other perpendicular vector is (-A, -B)
or (-U,-V)
.
Adding 'h' times this perpendidular vector to P2 you get P4:
P4x= P2x + h U
P4y= P2y + h V