user3269550
user3269550

Reputation: 474

find angle from given side of right andgle triangle and vise versa in c#

I have right angle triangle and a adjutant side is known to me now i want to make user enter either angle or opposite side and based on adjutant side and other entered parameter third parameter got calculated i have tried this given way but it is not returning true results for opposite side

oppositeside= Math.Tan(Convert.ToDouble(angle) * Math.PI / 180.0) * adjustantside;

and for angle i have tried following way

angle = Math.Atan(oppositeside * adjustantside)*180/Math.PI;

But it is not working does anyone khow how to do it in right way?

Upvotes: 0

Views: 1264

Answers (1)

Mong Zhu
Mong Zhu

Reputation: 23732

but it is not returning true results for opposite side

Actually it does, but you have to input angle in degrees:

double adjustantside = 0.5;
int angle = 45;
oppositeside= Math.Tan(Convert.ToDouble(angle) * Math.PI / 180.0) * adjustantside;

Output: 0.5

In a unity circle (hypothenuse = length of 1) the adjustantside will be equal to the oppositeside at an angle of 45°.

The tangent is calculated the following way:

enter image description here

taken from wikipedia

So your calculation should look like this:

angle = Math.Atan(oppositeside / adjustantside)*180/Math.PI;

PS. the radiant conversion with * Math.PI / 180.0 is correct: see also wikipedia:

enter image description here

Upvotes: 2

Related Questions