[Tutor] move forward in arbitrary direction

2006-10-28 Thread Michael Shulman
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] move forward in arbitrary direction

2006-10-28 Thread Jonathon Sisson
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


Re: [Tutor] move forward in arbitrary direction

2006-10-28 Thread R. Alan Monroe
 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.


http://freespace.virgin.net/hugo.elias/routines/rotate.htm


Alan

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] move forward in arbitrary direction

2006-10-28 Thread Luke Paireepinart
Going by radians, 0.0*pi is pointing to the right, 0.5*pi is pointingdown, 1.0*pi
 is pointing to the left, and 1.5*pi is pointing straight up.uh, wouldn't pi/2 be pointing up?Don't you set 0 radians to be the positive-x axis and then go counter-clockwise?Or does it not matter?
It seems like it would.Thanks,-Luke
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] move forward in arbitrary direction

2006-10-28 Thread Jonathon Sisson
Hrmmm...I do believe you are right, Luke.  My bad...it's been a bit 
since I actually used this stuff (about 12 years ago in college...heh). 
  And yes, it would matter, unless you swapped the key functionality 
around...but let's keep it simple, yes?

Good thing I'm not programming this project...haha.

Doh?
Jonathon


Luke Paireepinart wrote:
 
 
 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.
 
 
 uh, wouldn't pi/2 be pointing up?
 Don't you set 0 radians to be the positive-x axis and then go 
 counter-clockwise?
 Or does it not matter?
 It seems like it would.
 Thanks,
 -Luke
 
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor