2

好的,我有一个绘制对象轨迹的基本脚本。我有基本的运动方程来求解物体相对于时间的位置。该图本身是对象轨迹的 3D 表示。

我已经成功设置了轴限制,现在我想确保我没有看到任何超出轴限制的轨迹值。现在,轨迹低于 xy 平面并继续向下,在 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()
4

1 回答 1

0

如果您的对象超出了您的轴的限制;这是因为方程式告诉它这样做。在绘制结果之前,您必须限制结果并进行过滤。就像是:

x = equation1()
if( x > someLimit )
  handle error / object bounces by inverting the direction perhaps
plot(x)
于 2012-10-16T21:55:07.567 回答