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

有帮助吗?

解决方案

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top