Radians vs. Degrees
Mike C. Fletcher
mcfletch at rogers.com
Mon Jul 15 13:25:19 EDT 2002
DegToRad:
Is just a simple multiplication. Your C code is likely doing a
macro-expansion (something Python doesn't do) from DTOR( x ) ->
x*degtorad. Here's the factor you're using for the multiplication...
import math
degtorad = math.pi/180
Auto-conversion between radians and degrees isn't possible, as they are
untyped numbers, and both range over infinite values. (Should 360.0 be
1 full rotation, or 57.3 rotations?)
For loops in Python:
for x in range( 360):
rad = x * degtorad
do_whatever( rad )
For serious 3D work, you'd likely use the Numeric Python extensions and
just use a float-range:
for rad in arange( 0,2*math.pi, math.pi/180.0):
do_whatever( rad )
but I don't recall if Quark provides the Numeric extensions, so you
should probably stick with the range(360) loop above.
HTH,
Mike
Jef wrote:
> Hi All,
>
> 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.
>
> 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? 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?
>
> TIA
>
> -Jef
>
--
_______________________________________
Mike C. Fletcher
http://members.rogers.com/mcfletch/
More information about the Python-list
mailing list