2 This file is part of the pyquaternion python module
5 Website: https://github.com/KieranWynn/pyquaternion
6 Documentation: http://kieranwynn.github.io/pyquaternion/
9 License: The MIT License (MIT)
11 Copyright (c) 2015 Kieran Wynn
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
31 demo.py - Demo of pyquaternion using matplotlib
37 from pyquaternion
import Quaternion
42 from matplotlib
import pyplot
as plt
43 from matplotlib
import animation
44 from mpl_toolkits.mplot3d
import Axes3D
47 q1 = Quaternion.random()
48 q2 = Quaternion.random()
50 for q
in Quaternion.intermediates(q1, q2, 20, include_endpoints=
True):
54 q2 = Quaternion.random()
60 ax = fig.add_axes([0, 0, 1, 1], projection=
'3d')
67 colors = [
'r',
'g',
'b']
70 lines = sum([ax.plot([], [], [], c=c)
73 startpoints = np.array([[0, 0, 0], [0, 0, 0], [0, 0, 0]])
74 endpoints = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]])
89 line.set_3d_properties([])
98 q = next(quaternion_generator)
101 for line, start, end
in zip(lines, startpoints, endpoints):
103 start = q.rotate(start)
106 line.set_data([start[0], end[0]], [start[1], end[1]])
107 line.set_3d_properties([start[2], end[2]])
117 anim = animation.FuncAnimation(fig, animate, init_func=init,
118 frames=500, interval=30, blit=
False)