可以繪製場景通過VPython很容易:
from visual import *
import math
def make_grid(unit, n):
nunit = unit * n
f = frame()
for i in xrange(n+1):
if i%5==0:
color = (1,1,1)
else:
color = (0.5, 0.5, 0.5)
curve(pos=[(0,i*unit,0), (nunit, i*unit, 0)],color=color,frame=f)
curve(pos=[(i*unit,0,0), (i*unit, nunit, 0)],color=color,frame=f)
return f
arrow(pos=(0,0,0), axis=(5,0,0), color=(1,0,0), shaftwidth=0.1)
arrow(pos=(0,0,0), axis=(0,5,0), color=(0,1,0), shaftwidth=0.1)
arrow(pos=(0,0,0), axis=(0,0,5), color=(0,0,1), shaftwidth=0.1)
grid_xy = make_grid(0.5, 10)
grid_xz = make_grid(0.5, 10)
grid_xz.rotate(angle=pi/2, axis=(1,0,0), origin=(0,0,0))
grid_yz = make_grid(0.5, 10)
grid_yz.rotate(angle=-pi/2, axis=(0,1,0), origin=(0,0,0))
sphere(radius=0.3)
obj = arrow(pos=(0,0,0), axis=(1,2,3), shaftwidth=0.3)
th = 0
while True:
rate(20)
obj.axis = (3*math.cos(th), 3*math.sin(th), 2)
th += 0.04
如何實時繪製矢量圖? – BDuelz 2012-02-14 18:08:28
我有這個工作。謝謝。 – BDuelz 2012-02-14 19:48:51
但最後,你知道我如何添加一個網格來顯示x,y和z軸嗎? – BDuelz 2012-02-14 19:49:13