Python绘制某些点的速度和加速度矢量

2024-05-29 03:50:36 发布

您现在位置:Python中文网/ 问答频道 /正文

这里,我有一个参数方程。在

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

t = np.linspace(0,2*np.pi, 40)

# Position Equation
def rx(t):
    return t * np.cos(t)
def ry(t):
    return t * np.sin(t)

# Velocity Vectors
def vx(t):
    return np.cos(t) - t*np.sin(t)
def vy(t):
    return np.sin(t) + t*np.cos(t)

# Acceleration Vectors
def ax(t):
    return -2*np.sin(t) - t*np.cos(t)

def ay(t):
    return 2*np.cos(t) - t*np.sin(t)

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

z = t 
ax1.plot(rx(z), ry(z), z)
plt.xlim(-2*np.pi,2*np.pi)
plt.ylim(-6,6)
#ax1.legend() # no labels
plt.show()

所以我有一个参数方程来创建这个图。在

![enter image description here

我在上面的代码中定义了速度和加速度参数方程。在

我想做的是在我上面的位置图中,在定义的点上绘制加速度和速度向量。(内径est,t=pi/2,3pi/2,2pi)

像这样:

Plotting a 3d cube, a sphere and a vector in Matplotlib

但是我想做更直接的事情,因为我必须把每个点t定义成两个方程。在

这样的事情有可能吗?我只能找到向量场什么的。在

像这样。 enter image description here

谢谢。在

编辑问题

^{pr2}$

它会给我一个错误说Tuple out of index


Tags: import参数return定义defasnppi
1条回答
网友
1楼 · 发布于 2024-05-29 03:50:36

我觉得这很近。。。甚至有与样品图片相匹配的颜色:)

不过,我对极坐标绘图没有太多的经验(主要是在三维t坐标上感到困惑)。在

希望这会有帮助,你可以想出如何扩展它

我获取了您所拥有的,从this answer添加了Arrow3D类,并在{}中的一些示例值上添加了一个简单的for循环。在

#draw a vector
from matplotlib.patches import FancyArrowPatch
from mpl_toolkits.mplot3d import proj3d

class Arrow3D(FancyArrowPatch):
    def __init__(self, xs, ys, zs, *args, **kwargs):
        FancyArrowPatch.__init__(self, (0,0), (0,0), *args, **kwargs)
        self._verts3d = xs, ys, zs

    def draw(self, renderer):
        xs3d, ys3d, zs3d = self._verts3d
        xs, ys, zs = proj3d.proj_transform(xs3d, ys3d, zs3d, renderer.M)
        self.set_positions((xs[0],ys[0]),(xs[1],ys[1]))
        FancyArrowPatch.draw(self, renderer)

^{pr2}$

vectors

相关问题 更多 >

    热门问题