Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 915
vasili111 Avatar asked Feb 15 '23 06:02

vasili111


1 Answers

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.

like image 94
mathematician1975 Avatar answered Mar 24 '23 13:03

mathematician1975