2012-10-16 3 views
2

좋아요, 객체의 궤도를 그릴 기본 스크립트가 있습니다. 나는 시간의 관점에서 물체의 위치를 ​​푸는 동작의 기본 방정식을 가지고있다. 플롯 자체는 물체의 궤적을 3D로 표현한 것입니다.축 범위 밖의 값을 제거 하시겠습니까?

축 한계가 성공적으로 설정되었으므로 이제 축 한계를 벗어나는이 궤적의 값이 표시되지 않도록하고 싶습니다. 바로 지금, 궤도는 x-y 평면 아래로 떨어지고 3D 플롯 바깥쪽으로 계속됩니다 ... 이것을 막을 수있는 방법이 있습니까?

여기에 전체 코드입니다 :

import matplotlib as mpl 
from mpl_toolkits.mplot3d import Axes3D 
import numpy as np 
import matplotlib.pyplot as plt 

mpl.rcParams['legend.fontsize'] = 10 

fig = plt.figure() 
ax = fig.gca(projection='3d') 


### Define Variables ### 
time = (10)  #Time to calculate the equations 
t = np.linspace(0, time, 100) 

g = (9.81)  #Gravity 

vxo = (3)  #initial velocity in the x-direction 
vyo = (1)  #initial velocity in the y-direction 
vzo = (0)  #initial velocity in the z-direction 

xo = (0)  #initial x-position 
yo = (0)  #initial y-position 
zo = (9)  #initial z-position 


### Equations of Motion ### 
x = (xo + (vxo * t)) 
y = (yo + (vyo * t)) 
z = (10 - (.5 * g * (t**2))) 


ax.plot(x, y, z, label=('Trajectory of Soccer Ball ' + str(time))) 
ax.legend() 

### Set axis limits ### 
ax.set_xlim3d(0,10) 
ax.set_ylim3d(0,10) 
ax.set_zlim3d(0,10) 
plt.show() 

답변

0

개체가 축 한계를 넘어가는 경우; 그것은 방정식이 그것을 지시하기 때문입니다. 플롯하기 전에 결과와 필터를 제한해야합니다. 예 :

x = equation1() 
if(x > someLimit) 
    handle error/object bounces by inverting the direction perhaps 
plot(x) 
관련 문제