Here, i have a parametric equation.
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()
So i have this parametric equation that creates this graph.
I have defined my velocity and acceleration parametric equations above in my code.
What i am wanting to do is to plot the acceleration and velocity vectors in my position graph above at defined points. (Id est, t = pi/2, 3pi/2, 2pi)
Something like this:
Plotting a 3d cube, a sphere and a vector in Matplotlib
but i want to do something more straight forward since i have to define each point t into two equations.
Is such a thing possible? I can only find vector fields and what not.
Thank you.
Edit Question
# t = pi/4
t_val_start_pi4 = np.pi/4
vel_start_pi4 = [rx(t_val_start_pi4), ry(t_val_start_pi4), t_val_start_pi4]
vel_end_pi4 = [rx(t_val_start_pi4 ) + vx(t_val_start_pi4 ), ry(t_val_start_pi4 )+vy(t_val_start_pi4 ), t_val_start_pi4 ]
vel_vecs_pi4 = (t_val_start_pi4 , vel_end_pi4)
vel_arrow_pi4 = Arrow3D(vel_vecs_pi4[0],vel_vecs_pi4[1], vel_vecs_pi4[2], mutation_scale=20, lw=1, arrowstyle="-|>", color="b")
axes.add_artist(vel_arrow_pi4)
It'll give me an error saying Tuple out of index
ax.arrow(0, 0, 0.5, 0.5, head_width=0.05, head_length=0.1, fc='k', ec='k')
– iron2man