我正在编写一个 Python 程序来为沿 3D 曲线的切线设置动画。但是,我的切线没有移动。我认为问题是
line.set_data(np.array(Tangent[:,0]).T,np.array(Tangent[:,1]).T)
在,animate(i)但我想不通。任何帮助将不胜感激。以下是代码。
from mpl_toolkits import mplot3d
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
import matplotlib
matplotlib.use( 'tkagg' )
plt.style.use('seaborn-pastel')
fig = plt.figure()
ax = plt.axes(projection='3d')
ax = plt.axes(projection='3d')
# Data for a three-dimensional line
zline = np.linspace(0, 15, 1000)
xline = np.sin(zline)
yline = np.cos(zline)
ax.plot3D(xline, yline, zline, 'red')
def curve(t):
return [np.sin(t),np.cos(t),t]
def vector_T(t):
T = [np.cos(t),-np.sin(t),1]
return T/np.linalg.norm(T)
len = 2
def tangent_line(t):
P = np.add(curve(t),len*vector_T(t)) …Run Code Online (Sandbox Code Playgroud)