Finding 3rd point coordinates of rectangular triangle

301 Views Asked by At

I have to calculate coordinates of 3rd point of rotated image in programming language.

This are images, so coordinates are always positive, where left top corner is 0,0

In first scenario I have coordinates of 2 points A,B, length a and b and always 90' on point A . I need to find coordinates of C[Cx,Cy] no matter which way triangle is rotated PIC.1 & PIC.2. enter image description here

In second scenario I have coordinates of A, Alpha angle, length a and b, always 90' on B side. PIC.3 Same thing - I need to know point C coordinates, no mater how I will rotate triangle. enter image description here

How I do it now. I'm 'adding' two triangles and calculate them using angle & Pitagoras. This way I get X1,X2,X3,X4 which I can sum/subtract. Problem with this method is I have to determine triangle position - pattern is different depending on its position. See PIC.4. enter image description here

I will be glad if you guys can provide me easy copy/paste formula to calculate Cx and Cy no matter which direction triangle is facing.

1

There are 1 best solutions below

1
On

The point A has coordinates $(A_x, A_y)$ and point B has coordinates $(B_x, B_y)$ so the line through A and B is given by $y= \frac{B_y- A_y}{B_x- A_x}(x- A_x)+ A_y$. The line through A perpendicular to that is given by $y= \frac{B_x- A_x}{A_y- B_y}(x- A_x)+ A_y$. Also the circle with center $(A_x, A_y)$ with radius b is given by $(x- A_x)^2+ (y- A_y)^2= b^2$. The point C, which lies on that perpendicular at distance d from A, lies on the intersection of that line and circle. Solve the two equations $y= \frac{B_x- A_x}{A_y- B_y}(x- A_x)+ A_y$ and $(x- A_x)^2+ (y- A_y)^2= b^2$. An obvious start is to replace "y" in $(x- A_x)^2+ (y- A_y)^2= b^2$ with $y= \frac{B_x- A_x}{A_y- B_y}(x- A_x)+ A_y$ and then solve the single equation $(x- A_x)^2+ (\frac{B_x- A_x}{A_y- B_y}(x- A_x))^2= b$ for x.

There will be two solutions- one on either side of the line through A and B.