Radians vs. Degrees
Chris Liechti
cliechti at gmx.net
Mon Jul 15 13:33:04 EDT 2002
Jef <plungermonkey at cox.net> wrote in news:3D33016C.8030804 at cox.net:
> I'm new to this NG so please bear with me :-) I'm writing an addon
> for the Quake2 editor named QuArK and could use some advice from the
> math/coding gurus out there.
welcome
> My problem is that I'm trying to create a torus (donut) and the C
> code I'm looking at uses DTOR to convert degrees to radians and I see no
> mention of it (DTOR) in Python. My question is whether I need this in
> Python or does Python automatically convert to radians during
> calculations?
no. all math/trigonometric functions expect radians.
some conversion functions are easily written:
>>> import math
>>> def toDEG(rad):
... return 180.0*rad/math.pi
...
>>> def toRAD(deg):
... return math.pi*deg/180.0
...
>>> math.sin(toRAD(90))
1.0
>Also, do the FOR loops work the same as in C++ (e.g.
> FOR(x=0, x<360, x++))? If not, any suggestions on how to do this?
no. "for" works a little bit differnt in python: it iterates over a list
and takes one element after an other. if you want to count, you can use the
range() function to create a list of numbers.
for c in range(360):
...
or maybe you want to convert directly to radians:
for c in map(toRAD, range(360)):
...
(map applies the function (1st arg) to each element in a list (2nd arg))
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list