代码:
import math
import matplotlib.pyplot as plt
import numpy as np
from scipy.spatial.transform import Rotation as Rot
DT = 0.1 # time tick [s]
SIM_TIME = 20.0 # simulation time [s]
show_animation = True
time = 0.0
x=np.linspace(0,1,SIM_TIME/DT)
i =0
h_y_true = np.array([])
h_x_true = np.array([])
while SIM_TIME >= time:
time += DT
x_true=np.sin(2*np.pi*10*x[i])
h_x_true = np.hstack((h_x_true, x[i]))
h_y_true = np.hstack((h_y_true, x_true))
if show_animation:
plt.cla()
# for stopping simulation with the esc key.
plt.plot(h_x_true, h_y_true, "-b")
plt.plot(x[i], h_y_true[i], "*r")
plt.axis("equal")
plt.grid(True)
plt.pause(0.001)
i=i+1
结果: