Lines (x1, y1), (x2, y2) and (x3, y3), (x4, y4) are perpendicular. I have coordinates of points (x1, y1), (x2, y2), (x3, y3) and length in pixels of a line (x3, y3), (x4, y4). I need to find coordinates of point (x4, y4). What is the pseudocode for calculating (x4, y4)?
Calculate vector A where
A = (x2 - x1,y2 - y1)
A vector perpendicular to this is given by
B = (y1 - y2, x2 - x1)
find the normalised vector
C = B/|B|
where |B|
is simply the modulus of vector B
calculated using pythagoras
Your point (x4,y4)
will then be given as
(x4,y4) = (x3,y3) + K*C
where K is the length of the line (x3,y3)
to (x4,y4)
(which you say in the question that you know). Depending on the orientation of your points, you may need to set the value of K to
K = -K
in order for the point to be correct to your needs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With