vasili111
vasili111

Reputation: 6940

How can I calculate coordinates of the perpendicular line?

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)?

picture

Upvotes: 5

Views: 3033

Answers (1)

mathematician1975
mathematician1975

Reputation: 21351

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.

Upvotes: 8

Related Questions