The "something" you're stuck on is the angle the triangle has rotated, 
measured in radians.  If the concept of radians is not familiar, then 
here's a quick review:

There are 2*pi radians in a complete circle (about 6.28)
There are 360 degrees in a complete circle
1 radian is approximately 57 degrees

Going by radians, 0.0*pi is pointing to the right, 0.5*pi is pointing 
down, 1.0*pi is pointing to the left, and 1.5*pi is pointing straight up.

Keep in mind that python has a math function radians(x), which converts 
"x" degrees to radians.  If you use that, you can use degrees instead 
and convert on the fly.  (i.e. something to the effect of: 
math.cos(math.radians(degrees)) would give you the change in vector[0]).
If you would rather use radians, keep in mind that the python math 
module also has the pi constant, which is pretty self explanatory...

Hope that helps you...

Jonathon



Michael Shulman wrote:
> Hello, I have what should be a basic math question, but I keep messing 
> it up.
> 
> How do I code an equation so that when I have an object facing an 
> arbitrary vector, pressing a key will make it move forwards in that 
> direction?
> (I understand all the key-based setup, it's just the equation for moving 
> in the arbitrary vector direction that's got me stuck)
> 
> right now i can make something move up and down, or left and right, but 
> if I want to rotate a triangle, then move it so that the 'tip' always 
> points in the direction it's going to move, I get stuck.
> 
> the thing I have which doesn't work is something like
> _____________________
> vector = [0 0 0]
> 
> def specialKey(key,x,y):
>     if key  == 'up':
>        vector[0] = vector[0] + 1
> _______________________
> which I assume should be more like
> --------------------------------
> vector = [0 0 0]
> 
> def specialKey(key,x,y):
>     if key  == 'up':
>        vector[0] =  vector[0] * math.cos(something???)+ 1
>        vector[2] =  vector[2] * math.sin(something??)+1
> ----------------------------------
> Any help would be greatly appreciated!
> 
> ty, Mike
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to