math confusion

I know i’ve been feeling a little ill lately, but this is unbelievable,
So here’s my code

import direct.directbase.DirectStart
import math

angle = 45
print angle
print math.tan(angle)

opdivadj = 1
print opdivadj
print math.atan(opdivadj)

sqme = 3
print sqme
print 3^2


Here’s the output

Now, why isn’t the tangent of 45 = 1?
And why isn’t the atan of 1 = 45?
My brain hurts…

Additionally, 3^2 seems to yield 1 instead of 9…

Am I missing some really fundamentals about python, or is this something in panda?

Python is 2.6.2
Panda is 1.6.2

Looks like ppython is maybe 32 bit (2.6.1)
This is on a macbook os 10.6.2, 64 bit.
I guess that could be it…
Everything else (tuts and prior code) runs using system python, however…


^ isn’t power in Python. Maybe it’s a bit-wise operator? (3^2 is 3 AND 2?) You need to use math.pow(x,y) to do powers.

Also, I am reasonably sure the math functions in Python work in radians, not degrees.


FenrirWolf and ynjh_jo are abslutely correct. python uses radians by default. whenever you’r in doubt what a function takes as input simply use pythons help() call.
for example

import math 

would give this result

Help on built-in function tan in module math:

    Return the tangent of x (measured in radians)

^ means bitwise-XOR

Panda also has it, rad2Deg and deg2Rad.

much better,