# Given two points A,B construct a right triangle so that AB is the hypotenuse and one of the acute angles is $\alpha$ I want to construct Pythagoras trees but my math is rusty so that I need to simplify the calculations. The tree is constructed counter-clockwise.

My approach:

Let A, B be $$(x_0, y_0)$$, $$(x_1, y_1)$$.

Hypotenuse $$\lambda = \sqrt{(x_1 - x_0)^2 + (y_1 - y_0)^2}$$

Let the desired acute angle be $$\alpha$$.

If AB is parallel to x-axis, the other vertex $$P$$:

$$(x_2, y_2) = (x_0 + \lambda \cdot cos(a) \cdot cos(a), y_0 + \lambda \cdot cos(a) \cdot sin(a))$$

Rotate $$P$$ around $$A$$.

Equation of rotation:

\begin{align} x_r = cos(\beta) \cdot (x_p - x_c) - sin(\beta) \cdot (y_p - y_c) + x_c \\ y_r = sin(\beta) \cdot (x_p - x_c) + cos(\beta) \cdot (y_p - y_c) + y_c \end{align}

Where $$(x_c, y_c)$$ is center of rotation, $$(x_p, y_p)$$ is point being rotated, and $$\beta$$ is rotation angle.

Substitute trigonometric functions and insert values:

\begin{align} x_3 = \frac{x_1 - x_0} {\lambda} \cdot (x_2 - x_0) - \frac{y_1 - y_0} {\lambda} \cdot (y_2 - y_0) + x_0 \\ y_3 = \frac{y_1 - y_0} {\lambda} \cdot (x_2 - x_0) + \frac{x_1 - x_0} {\lambda} \cdot (y_2 - y_0) + y_0 \end{align}

How to simplify the calculations, so that given the angle $$\alpha$$ and points A, B the other vertex can be directly calculated?

## Update

Upon closer inspection of the equations, I found that $$x_0$$, $$y_0$$ and $$\lambda$$ terms can be eliminated:

\begin{align} x_2 = (x_1 - x_0) \cdot cos(\alpha)^2 - (y_1 - y_0) \cdot cos(\alpha) \cdot sin(\alpha) + x_0 \\ y_2 = (y_1 - y_0) \cdot cos(\alpha)^2 + (x_1 - x_0) \cdot cos(\alpha) \cdot sin(\alpha) + y_0 \end{align}

Can they be simplified further?

## I did it again  • I know how to calculate the vertices of regular polygons, as evident in the scripts present in my other questions, in case of squares, I just rotate one end of a segment around the other 90 degrees (counter-clockwise) to get the third vertex, then add (x2-x1, y2-y1) to (x3, y3) to get the fourth. As these calculations are as simple as I can make them, I don't think I need to mention them in the question body. I just don't know how to calculate the triangular vertex at the right angle efficiently. Jun 1, 2022 at 13:54

Addendum added to react to the comment question of the original poster

The computations can be simplified by temporarily assuming that one endpoint of the hypotenuse has Cartesian coordinates $$(0,0)$$ and the other endpoint has Cartesian coordinates

$$\displaystyle (R,0) ~: R = \sqrt{A^2 + B^2} = \sqrt{(x_1 - x_0)^2 + (y_1 - y_0)^2}.$$

Then, at this stage, all that is missing is the Cartesian Coordinate of the $$3$$rd vertex. The easy way is to construe the line segment going from the origin to the 3rd vertex as a vector of length $$R\cos(\alpha)$$ and direction $$(\alpha)$$

Here, I am making the standard assumption that the positive directions of angles are in a counter-clockwise direction.

If you then take scratch paper, and draw the corresponding diagram, you will see that the Cartesian coordinates of the $$3$$rd vertex are therefore

$$\left[R\cos^2(\alpha), ~~R\cos(\alpha)\sin(\alpha)\right]. \tag1$$

All that remains it to rotate and then shift the diagram, and compute the resulting affect on the Cartesian coordinates of the $$3$$rd vertex, which is currently shown in (1) above.

Under the initial temporary assumption, the slope of the line $$\left(\overline{AB}\right)$$ is $$0$$.

The actual slope needs to be

$$M = \frac{y_1 - y_0}{x1 - x_0}.$$

So,

• If $$M > 0$$, then let $$\theta = \arctan(M).$$

• If $$M < 0$$, then let $$\theta = (\pi) - \arctan(-M) \implies$$
$$\pi/2 < \theta < \pi.$$

An easy way of then performing the rotation is to repeat the procedure that was initially used to compute the Cartesian coordinates shown in (1) above. Instead of construing the pertinent leg of the triangle to be a vector of magnitude $$R\cos(\alpha)$$ and direction $$(\alpha)$$, simply construe the pertinent leg of the triangle to be a vector of magnitude $$R\cos(\alpha)$$ and direction $$(\alpha + \theta)$$.

Then, the rotational affect is to alter the Cartesian coordinates, shown in (1) above. Instead, they become

$$(P,Q) = \left[R\cos(\alpha)\cos(\alpha + \theta), ~~R\cos(\alpha)\sin(\alpha + \theta)\right]. \tag2$$

So, in (2) above, $$(P,Q)$$ represents the Cartesian coordinate of the $$3$$rd vertex, after the rotational adjustment, but before the shift adjustment.

The shift adjustment is straightforward. Assuming that $$(0,0)$$ is shifted to $$(x_0, y_0)$$, you have that

$$(P,Q) ~~\text{is shifted to}~~ (P + x_0, Q + y_0).$$

The OP (i.e. original poster) indicated a flaw in my response. What happens if $$(x_1 - x_0)$$ equals $$0$$. In that case, the attempt to compute of $$M$$ will fail, so the strategy used to determine $$(\theta)$$ will fail.
That situation represents a vertical hypotenuse, which represents a rotation of $$(\pi/2)$$. So, in that case, set $$(\theta)$$ to $$(\pi/2)$$.
• Your answer is good, but upon further consideration, both $y_1 - y_0$ and $x_1 - x_0$ can be zero, and then you have division by zero... Jun 2, 2022 at 3:25
• @ΞένηΓήινος I agree that I overlooked what happens when $(x_1 - x_0) = 0.$ See the Addendum that I just added to the end of my answer. Notice however, that you can not have that $(y_1 - y_0)$ and $(x_1 - x_0)$ are both equal to zero. This is because then, you would have that the points $(x_1,y_1)$ and $(x_0,y_0)$ are the same point, and then you have a hypotenuse of length $(0)$, which is nonsensical. Jun 2, 2022 at 7:06