1

I have 2 values that are in radians, c[1] and c[3]. I need to turn the radians into degrees and I haven't the faintest idea what to do to these numbers to get degrees out of them. I have been searching the internet far and wide and I cant find anything that I can actually understand. I have tried devising my own way to do it but I'm sure I'm not even close. I have tried the following:

    z = (((c[1] * 180) + 180) + ((c[3] * 180) + 180))
    z = (((c[1] * math.pi) / 180) + ((c[3] * math.pi) / 180) / 2)
    z = (c[1] * (90/math.pi) - (c[3] * (90/math.pi)))
    z = math.atan2(c[3], c[1])
    z = (math.degrees(c[1]) + math.degrees(c[3])) * 2
    z = c[1]
    z = (math.asin(c[3]) / math.acos(c[1]))

How do I get a value in degrees from 2 radians?

5
  • 1
    Perhaps you should explain what you're really trying to do. Commented Aug 16, 2014 at 1:57
  • 1
    You can convert one value from radians to degrees with math.degrees(rads). How you would convert two radian values into one degree value is totally unclear to me, though... Or do you just want to convert each one of them?
    – hlt
    Commented Aug 16, 2014 at 2:07
  • I used ReadProcessMemory to read the players coordinates and heading in a game. I want to create a map that will show you your current location and heading. The values I get from the game are in radians, and I need to rotate a surface in pygame according to the player's orientation. c[1] is -1 to 0 to the west, 0 to 1 to the east, and c[3] is -1 to 0 to the south, and 0 to 1 to the north. If the player rotates 360 degrees, neither c[1] or c[3] can tell you which way you are facing by themselves. Commented Aug 16, 2014 at 2:22
  • You said c[1] is -1 to 0 to the west. Does this mean that when heading is directly towards north, c[1] is -1? Also, c[1] is 0 to 1 to the east. Does this mean that when heading is directly north, c[1] is 0? The answers to previous 2 question cannot both be yes at the same time. Can you clarify your previous comment? If you can clarify the question, I can help you.
    – sfroid
    Commented Aug 16, 2014 at 2:58
  • Wichid Nixin, are you trying to add the two values together and them change them into degrees? or just both, but seperately?
    – W1ll1amvl
    Commented Aug 16, 2014 at 4:11

3 Answers 3

1

After going through your comment, I don't think that you are getting two angles in radians for c[1] and c[3]. Rather, you are getting direction cosines. If you were getting angles in radians, the value would range from -pi to pi. Rather, the value goes from -1 to 1 (i.e. cos(-pi) to cos(pi)).

You can change the value first to an angle in radians and then to degrees if that is what you want. Just as a caveat, the cosine of angles is symmetric ... So for:

In [12]: zip(angles, (cos(angles)))
Out[12]:
[(-3.1415926535897931, -1.0),
 (-2.8108986900540254, -0.94581724170063464),
 (-2.4802047265182576, -0.78914050939639346),
 (-2.1495107629824899, -0.5469481581224267),
 (-1.8188167994467224, -0.24548548714079912),
 (-1.4881228359109546, 0.082579345472332394),
 (-1.1574288723751871, 0.40169542465296937),
 (-0.82673490883941936, 0.67728157162574099),
 (-0.49604094530365161, 0.87947375120648907),
 (-0.16534698176788387, 0.98636130340272232),
 (0.16534698176788387, 0.98636130340272232),
 (0.49604094530365161, 0.87947375120648907),
 (0.82673490883941891, 0.67728157162574132),
 (1.1574288723751867, 0.40169542465296976),
 (1.4881228359109544, 0.082579345472332616),
 (1.8188167994467221, -0.2454854871407989),
 (2.1495107629824899, -0.5469481581224267),
 (2.4802047265182576, -0.78914050939639346),
 (2.8108986900540254, -0.94581724170063464),
 (3.1415926535897931, -1.0)]

But,

In [11]: zip(angles, arccos(cos(angles)))
Out[11]:
[(-3.1415926535897931, 3.1415926535897931),
 (-2.8108986900540254, 2.8108986900540254),
 (-2.4802047265182576, 2.4802047265182576),
 (-2.1495107629824899, 2.1495107629824899),
 (-1.8188167994467224, 1.8188167994467224),
 (-1.4881228359109546, 1.4881228359109546),
 (-1.1574288723751871, 1.1574288723751871),
 (-0.82673490883941936, 0.82673490883941936),
 (-0.49604094530365161, 0.49604094530365156),
 (-0.16534698176788387, 0.16534698176788418),
 (0.16534698176788387, 0.16534698176788418),
 (0.49604094530365161, 0.49604094530365156),
 (0.82673490883941891, 0.82673490883941891),
 (1.1574288723751867, 1.1574288723751867),
 (1.4881228359109544, 1.4881228359109544),
 (1.8188167994467221, 1.8188167994467221),
 (2.1495107629824899, 2.1495107629824899),
 (2.4802047265182576, 2.4802047265182576),
 (2.8108986900540254, 2.8108986900540254),
 (3.1415926535897931, 3.1415926535897931)]

Which means that getting your angles from your direction cosines, you will need to do:

In [13]: def toAng(a): return sign(a)*arccos(a)

which will give you your correct angles:

In [19]: zip(angles, toAng(cos(angles)))
Out[19]:
[(-3.1415926535897931, -3.1415926535897931),
 (-2.8108986900540254, -2.8108986900540254),
 (-2.4802047265182576, -2.4802047265182576),
 (-2.1495107629824899, -2.1495107629824899),
 (-1.8188167994467224, -1.8188167994467224),
 (-1.4881228359109546, 1.4881228359109546),
 (-1.1574288723751871, 1.1574288723751871),
 (-0.82673490883941936, 0.82673490883941936),
 (-0.49604094530365161, 0.49604094530365156),
 (-0.16534698176788387, 0.16534698176788418),
 (0.16534698176788387, 0.16534698176788418),
 (0.49604094530365161, 0.49604094530365156),
 (0.82673490883941891, 0.82673490883941891),
 (1.1574288723751867, 1.1574288723751867),
 (1.4881228359109544, 1.4881228359109544),
 (1.8188167994467221, -1.8188167994467221),
 (2.1495107629824899, -2.1495107629824899),
 (2.4802047265182576, -2.4802047265182576),
 (2.8108986900540254, -2.8108986900540254),
 (3.1415926535897931, -3.1415926535897931)]

Finally, if you need to convert it to degrees, you can just do:

In [20]: def toAng(a): return 180*sign(a)*arccos(a)/pi

In [21]: zip(angles, toAng(cos(angles)))
Out[21]:
[(-3.1415926535897931, -180.0),
 (-2.8108986900540254, -161.05263157894737),
 (-2.4802047265182576, -142.10526315789474),
 (-2.1495107629824899, -123.1578947368421),
 (-1.8188167994467224, -104.21052631578948),
 (-1.4881228359109546, 85.263157894736835),
 (-1.1574288723751871, 66.31578947368422),
 (-0.82673490883941936, 47.368421052631582),
 (-0.49604094530365161, 28.421052631578949),
 (-0.16534698176788387, 9.4736842105263346),
 (0.16534698176788387, 9.4736842105263346),
 (0.49604094530365161, 28.421052631578949),
 (0.82673490883941891, 47.368421052631554),
 (1.1574288723751867, 66.315789473684191),
 (1.4881228359109544, 85.263157894736835),
 (1.8188167994467221, -104.21052631578947),
 (2.1495107629824899, -123.1578947368421),
 (2.4802047265182576, -142.10526315789474),
 (2.8108986900540254, -161.05263157894737),
 (3.1415926535897931, -180.0)]

Which gives you the right angles in degrees ...

Note I am using an environment where sign, pi etc are numpy objects. In your program, you might have ti import them separately.

0

degree to radian conversions are done with the equation (n deg)*(pi/180 deg).

z = (c[1]*(math.pi/180.0) + (c[1]*(math.pi/180)

if it's something you need to do regularly make a function.

def DegtoRad(deg):
    return (deg)*(math.pi/180)

or as a lambda

DegtoRad = lambda x: x*(math.pi/180)

remember though if you havent imported math/math.pi none of this will work. probably better to define pi with an actual literal variable up to your needs of precision.

1
  • 1
    This is wrong, it is a good answer but the wrong way around! the question is changing values from radians into degrees, not vice versa.
    – W1ll1amvl
    Commented Aug 16, 2014 at 4:14
0

This was not so very hard to find online? - was it?

http://www.mathwarehouse.com/trigonometry/radians/convert-degee-to-radians.php

The formula is the opposite of @user2913685 's formula: num*180/pi (an easy mistake)

here is an example in python:

pi = 3.14159265

rad_val = 7

deg_val = rad_val*180/pi

print(deg_val)

which gives the output:

401.07045704986604

This uses pi as 3.14159265, and doesn't use the module math. Obviously you can do the same as in the other answer, but after changing the formula.

Not the answer you're looking for? Browse other questions tagged or ask your own question.