简体   繁体   中英

How to find the X coordinate of a point on a line given another point of the line and the 2 points on a perpendicular line?

I'm writing a python app to select rectangular areas, when the user has set 2 points (the length of the rectangle), the third and 4th points are constrained in forming a rectangle, where the width of the rectangle is given by the Y difference of the mouse cursor and the last point.

Here's a quick picture to explain, I'm looking for the X coordinate of the point C.

在此输入图像描述

I know :

  • A(2,3)
  • B(5,5)
  • angle = 90 degrees
  • the Y coordinate of C is 7.

I'm not sure how to tackle this... using vectors ? I'm using numpy in my project.

This is more of a math issue than a numpy issue.

The slope of (AB) is (y_a - y_b)/ (a - b) . So the slope of any perpendicular to (AB) is p=(ba)/(y_a-y_b) (opposite of the inverse of the original slope).

From here it is easy to determine the equation of the perpendicular to (AB) passing through B : y-y_b=p*(x-x_b) . And substitute y_c to y to find x_c

There is an issue (division by zero) if (AB) is horizontal (0 slope). In that case, x_c is just x_b (all of the points on (BC) have same x coordinate)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM