[SOLVED] How to get the angel of a right triangle rectangle giving as an input (a & b) cathetus?

float a
float b
angle = atan2(a,b) ?

SOLUTION by makeshiftwings & lordofduct

float a = 2f;       //  cathetus maggiore
float b = 2f;      //  smaller cathetus
float angle;      // result in  degree

angle = Mathf.Atan( b / a);       // result from 0 to 1.570796...
angle = angle * Mathf.Rad2Deg;   // convert it to degree

print(angle.ToString());      // 45°
1 Like

You have it backwards… SOHCAHTOA says Tangent = Opposite / Adjacent.
angle = atan2(b,a)

3 Likes

SOH…
Sine: sin(θ) = Opposite / Hypotenuse
…CAH…
Cosine: cos(θ) = Adjacent / Hypotenuse
…TOA
Tangent: tan(θ) = Opposite / Adjacent

So:

tan(theta) = (b/a)
theta = atan(b/a)

atan2(b,a) would also technically work… because a right triangle guarantees that you’d have angles less than 90. But is technically overkill since it also calculate direction, and would result in odd values if you say passed in negative side lengths.

4 Likes