It is currently Sat Mar 23, 2019 12:51 am

Reply to topic  [ 2 posts ] 
 Functions that use lists 
Author Message
One Eyed Hopeful

Joined: Mon Jan 29, 2018 4:41 pm
Posts: 13
Reply with quote
Hello again! I'm currently working on my next wii remote mouse script, one that negates the roll of the wiimote, and I've found that thinking of the accelerations in terms of vectors work out really well. For example, the acceleration vector is set up as the following:
accl = [wiimote[0].acceleration.x, wiimote[0].acceleration.y, wiimote[0].acceleration.z]

The problem is, I need a function that takes in a vector (list of 3 numbers/variables), and spits out another vector, in the same form of a list of 3 numbers/variables, like this:
def unitVect(v):
   if math.sqrt(sum(n**2 for n in v)) != 0:
      return v/(math.sqrt(sum(n**2 for n in v)))
      return 0

Which, (in theory,) if given a vector v = [x,y,z], should spit out a different vector unitVect(v) = [a,b,c]

I know this code doesn't work because v here is a list and not a number, but is there a way to treat lists like this in python?

Sat Apr 21, 2018 4:25 pm
One Eyed Hopeful

Joined: Thu Oct 03, 2013 7:10 am
Posts: 47
Reply with quote
like that?

def fct(x): return x/s

if Keyboard.getPressed(Key.S):
   s = math.sqrt(sum(n**2 for n in v))
   if s != 0:
      a = map(fct, v)
      a = [0,0,0]

if starting:
   v = [1,2,3]
   a = [0,0,0]
   s = 0.0[0])[1])[2])

Sun Apr 22, 2018 12:44 am
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 4 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group
Designed by STSoftware.