Last active
May 15, 2020 12:16
-
-
Save yangyushi/e0017f303df36ae7c3b145040017de71 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import matplotlib.pyplot as plt | |
from mpl_toolkits.mplot3d import Axes3D | |
fig = plt.figure() | |
ax = fig.add_subplot(111, projection='3d') | |
b1 = np.array([ | |
[1, 0, 0], | |
[0, 1, 0], | |
[0, 0, 1] | |
]) | |
t = 15 / 180 * np.pi | |
b2 = np.array([ | |
[np.cos(t), -np.sin(t), 0], | |
[np.sin(t), np.cos(t), 0], | |
[0, 0, 1] | |
]) | |
v1 = np.array([1, 1, 0]) / 1.414 | |
v2 = np.array([np.sqrt(3)/2, 0.5, 0]).T # v1 in basis 2 | |
v2 = np.linalg.inv(b1) @ b2 @ v2 # transform back to v1 | |
ax.quiver3D(0, 0, 0, *b1, color='k') | |
ax.quiver3D(0, 0, 0, *v1, color='k', alpha=0.5) | |
ax.quiver3D(0, 0, 0, *b2, color='tomato') | |
ax.quiver3D(0, 0, 0, *v2, color='tomato', alpha=0.5) | |
ax.set_xlim(-0.2, 1) | |
ax.set_ylim(-0.2, 1) | |
ax.set_zlim(0, 1) | |
ax.set_xlabel("X") | |
ax.set_ylabel("Y") | |
ax.set_zlabel("Z") | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment