# Help calculating a point in 2d space on a rotating right angle triangle

I am trying to solve for a point on a triangle that rotates around a fixed point. For ease of calculation this point is at X: 0 Y: 0

The length and width of the triangle are always fixed, the only thing that changes is the rotation angle. How can I solve for X: ??? and Y: ??? taking into account the rotation angle?

I am trying to place a 2d rendered object in Java so I need to break the formula down to it's base elements so I can put it into code and have the formula spit out X and Y coordinates

The known variables are all listed in the pictures. The angle of the triangle, the length & width. Anything else that is needed to find the ??? must be calculated first I guess.

Please don't just link wiki pages. I have read them. I don't understand them. Hence why I am asking for help walking through the solution.

Thank you!

• Which parameters do you want to give your triangle? For example, do you want to give it the current angle, two sides and the enclosed angle between those two sides? – Imago Dec 21 '15 at 13:58
• Multiply the coordinates with a rotation matrix en.m.wikipedia.org/wiki/Rotation_matrix – David Quinn Dec 21 '15 at 14:25

Imagine the hypotenuse of your triangle is the radius of a circle for which the length can be calculated with the Pythagorean theorem:

$$H = \sqrt{L^2 + W^2} \\$$

Then, instead of calculating the angle between the negative $y$-axis and the hypotenuse as drawn, imagine the initial angle of your hypotenuse is the angle between the $x$-axis and the hypotenuse which can be calculated with the $\tan$ function and its inverse $\arctan$ function:

$$\tan \theta = \frac{\textrm{opposite}}{\textrm{adjacent}} = \frac{L}{W} \\ \theta = \arctan \frac{L}{W} \\$$

Finally, the coordinates can be calculated by multiplying the hypotenuse ($H$) with the appropriate trigonometric function ($\sin$ or $\cos$) applied to the complete angle ($\theta + Angle$) which can then be simplified:

$$X = H \cos(\theta + Angle) = W \cos(Angle) - L \sin(Angle) \\ Y = H \sin(\theta + Angle) = L \cos(Angle) + W \sin(Angle) \\$$

Let's try these equations with the values from your first triangle where $Angle$ is $0$:

$$X = 3 \cos(0) - (-5) \sin(0) = 3 \\ Y = (-5) \cos(0) + 3 \sin(0) = -5 \\$$

Now let's try again with the values from your second triangle where $Angle$ is $35^\circ$ converted to radians:

$$X = 3 \cos(\frac{35 \pi}{180}) - (-5) \sin(\frac{35 \pi}{180}) \approx 5.33 \\ Y = (-5) \cos(\frac{35 \pi}{180}) + 3 \sin(\frac{35 \pi}{180}) \approx -2.38 \\$$

Cr3 is correct but I found a bit smaller way to do it from a different help forums. Thank you all

x′= Width * cos(Angle) - Length * sin(Angle)

y′= Width * sin(Angle) + Length * cos(Angle)

x′=3cos(35)+5sin(35)≈5.33

y′=3sin(35)−5cos(35)≈−2.38

• If it looks like your answer is a bit smaller because it uses degrees ($35^\circ$) whereas my answer uses radians ($\frac{35\pi}{180}$), please note that the Math.cos function in Java expects an angle parameter in radians. – cr3 Dec 23 '15 at 19:19