tags:

views:

274

answers:

3

Good Day,

It has been quite some time since I've had to compute the theta of an angle. But given a right angle:


  |
  |
b |
  -----------------
        a

I'm trying to compute theta (the slope of the angle). My understanding of trigonometry (as rusty as it is) is that theta = arctan(b/a). So if b = 50 and a = 1811. Then using the windows calculator, 50 / 1811 = 0.027609055770292655991165102153506. Therefore the arctan(b/a) = 1.5814806205083755492980816356377. If my math is correct, how do I translate this value into the slope of the angle? It should be around 30-40 degrees, right?

A: 

If you use a C dialect then there a useful function for just this purpose

atan2(y, x);
neoneye
It seems worth pointing out that the reason this 2-argument function is nice is because a single argument (atan(r)) cannot distinguish between all possible angles, so you will see only 2 quadrants of 4 in the outputs of this function. The 2-arg version notes what quadrant the x-y coords are in and adjusts the result appropriately.
Mikeb
A: 

You've already got the answer: 1.58... deg. Are you asking the right question?

belwood
That's radians.
CannibalSmith
Clarification: Wolfram alpha shows arctan(50/1811) as1.5814806205083... degrees(http://www.wolframalpha.com/input?i=arctan%2850%2F1811%29)Have I done something incorrectly?
belwood
+1  A: 
atan2(y, x)

will return you the angle in radians (and successfully cope with the cases where x and/or y are 0).

To convert to degrees apply the following formula:

double degrees = radians * (180 / PI)

Where PI is 3.141592... or math.pi in c#

ChrisF