當前位置: 首頁>>代碼示例>>Python>>正文


Python Vector.get方法代碼示例

本文整理匯總了Python中Vector.get方法的典型用法代碼示例。如果您正苦於以下問題:Python Vector.get方法的具體用法?Python Vector.get怎麽用?Python Vector.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Vector的用法示例。


在下文中一共展示了Vector.get方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Drone

# 需要導入模塊: import Vector [as 別名]
# 或者: from Vector import get [as 別名]
class Drone():

    def __init__(self, dt):
        self.dt = dt
        self.rotorspeed = Vector(0.0, 0.0)
        self.pos = Vector(0,0)
        self.speed = Vector(0.0,0.0)
        self.acc = Vector(0.0, 0.0)
        
        self.posPrev = Vector(0.0, 0.0)
        self.speedPrev = Vector(0.0, 0.0)
        
        self.control = None
    
    def setRotorSpeed(self, value):
        if value.coords[0] < -30:
            self.rotorspeed.coords[0] = -30
        elif value.coords[0] > 30:
            self.rotorspeed.coords[0] = 30
        else:
            self.rotorspeed.coords[0] = value.coords[0]
            
        if value.coords[1] < 0:
            self.rotorspeed.coords[1] = 0
        elif value.coords[1] > 30:
            self.rotorspeed.coords[1] = 30
        else:
            self.rotorspeed.coords[1] = value.coords[1]
            
    
    def setControl(self, control):
        self.control = control

    def refreshPos(self):
        newpos = self.calc()
        self.posPrev = self.pos
        self.pos = newpos
        #not here
        self.speedPrev = self.speed
        self.speed = (self.pos - self.posPrev)/self.dt
        self.acc = (self.speed - self.speedPrev) / self.dt

    def calc(self):
        if self.pos.get() == (0,0) and self.rotorspeed.get() == (0,0):
            return self.pos
        else:
            m = 1.0
            g = 10.0
            dt = self.dt  #???        
            """
             m*ddx = F
            """            
            Fall = self.rotorspeed + Vector(0, -m*g)
            
            newpos = Fall * dt**2 / m + self.pos * 2 - self.posPrev
            
            if newpos.coords[1] < 0:
                self.speed.set(0,0)
                return Vector(newpos.coords[0], 0)
            elif newpos.coords[0] < 0:
                self.speed.set(0,0)
                return Vector(0, newpos.coords[1])
            elif newpos.coords[1] > 500:
                self.speed.set(0,0)
                return Vector(newpos.coords[0], 500)
            elif newpos.coords[0] > 1000:
                self.speed.set(0,0)
                return Vector(1000, newpos.coords[1])
            else:
                return newpos
開發者ID:ricsirke,項目名稱:Drone-Simulation,代碼行數:72,代碼來源:Drone.py

示例2: Tk

# 需要導入模塊: import Vector [as 別名]
# 或者: from Vector import get [as 別名]
    plotShift += 1

# GUI
root = Tk()

draw_button = Button(root, text="Plot!", command = main)
draw_button.grid(row=0, column=0)

# init figure
fig = plt.figure()
canvas = Tk.Canvas(fig, master=root)
canvas.get_tk_widget().grid(row=0,column=1)

root.mainloop()"""





from Vector import *
a = Vector(2,1,2)
b = Vector(3,2,3)

c = a + b

print a.get()
print "b"
print b.get()
print "c"
print  c.get()
開發者ID:ricsirke,項目名稱:Drone-Simulation,代碼行數:32,代碼來源:tests.py


注:本文中的Vector.get方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。