Reputation: 1003
I have a triangle, knowing lenghts of two sides (see picture) and need to know an angle shown in the picture (red are known, the blue angle is what I need to count)
I found out, that Math.Tan gets me the angle expressed in radians, so when I tried to do this:
alpha = Math.Tan((CA/AB));
I always get 0 as a result. My question is - how can i get this angle, knowing only these two sides?
Upvotes: 1
Views: 6250
Reputation: 610
The angle that you are looking for is arctanjant not tanjant.
So you should use the arctanjant function of .Net library. The following line gives what you need.
double alpha = Math.Atan ((double)CA/AB) * 180 / PI;
where PI is 3.14 as you know.
Upvotes: 2
Reputation: 4094
Try:
double alpha = Math.Atan2(CA, AB)
Make sure the result, alpha
, and other variable are double
Upvotes: 6
Reputation: 203820
My psychic debugging tells me that CA
and AB
are both integers, either int
or long
. The result will therefore also be an integer type, truncating any decimal value as needed. Convert at least one of the values to a floating point type to get a floating point result:
alpha = Math.Tan((CA/(double)AB));
Upvotes: 4