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 :
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.