def lowerlimit(vct, speed): if vct.Length >= speed: pass else: vct.Unitize() vct = PVector.Multiply(vct, speed) return vct
def gettarget_2d(self, eddies): target_2d = PVector(0, 0, 0) for i in xrange(len(eddies)): v = PVector.Subtract(eddies[i].loc, self.loc) v2d = PVector( v.X, v.Y, 0) # 2d planer target, X Y are the most important factors dist2d = v2d.Length # compute the sum of the arraction vector / distance v2d.Unitize() v2d = PVector.Multiply(v2d, float(eddies[i].gravity / pow(dist2d, 1.0))) # add vector to attraction vector collection target_2d = PVector.Add(target_2d, v2d) #Limit the target length target_2d = toplimit(target_2d, self.toplimit) target_2d = lowerlimit(target_2d, self.lowerlimit) self.target = target_2d