-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathqvis.py
70 lines (54 loc) · 2.19 KB
/
qvis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
Copyright (C) 2020 Benjamin Bokser
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits import mplot3d
from matplotlib.lines import Line2D
import matplotlib.animation as animation
from pyquaternion import Quaternion
# -------------------------quaternion-visualizer-animation--------------------------------- #
# Matplotlib animation code based on Kieran Wynn's pyquaternion module
# Set up figure & 3D axis for animation
fig = plt.figure()
ax = fig.add_axes([0, 0, 1, 1], projection='3d')
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
# use a different color for each axis
colors = ['r', 'g', 'b']
# set up lines and points
lines = sum([ax.plot([], [], [], c=c)
for c in colors], [])
startpoints = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
endpoints = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
# prepare the axes limits
ax.set_xlim((-8, 8))
ax.set_ylim((-8, 8))
ax.set_zlim((-8, 8))
ax.view_init(30, 0) # set point-of-view: specified by (altitude degrees, azimuth degrees)
# q_e = np.array([0., 0., 0., 0.])
def animate(q_e):
# animation function. This will be called sequentially with the frame number
q_in = Quaternion(q_e[0], q_e[1], q_e[2], q_e[3])
for line, start, end in zip(lines, startpoints, endpoints):
# end *= 5
start = q_in.rotate(start)
end = q_in.rotate(end)
line.set_data([start[0], end[0]], [start[1], end[1]])
line.set_3d_properties([start[2], end[2]])
# pt.set_data(x[-1:], y[-1:])
# pt.set_3d_properties(z[-1:])
fig.canvas.draw()
plt.pause(0.0001)
return lines