Skip to content

Instantly share code, notes, and snippets.

@IshitaTakeshi
Last active June 11, 2017 04:08
Show Gist options
  • Save IshitaTakeshi/e596ad04a1a0f8bf3ccf5af6be2bd29e to your computer and use it in GitHub Desktop.
Save IshitaTakeshi/e596ad04a1a0f8bf3ccf5af6be2bd29e to your computer and use it in GitHub Desktop.
from itertools import permutations, combinations
import numpy as np
from numpy.linalg import det
from matplotlib.patches import FancyArrowPatch
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import proj3d
from mpl_toolkits.mplot3d import Axes3D
def draw(X, color, alpha=0.2):
a = np.arange(0, 1, 0.01)
S = np.array(np.meshgrid(a, a)).reshape(2, -1)
indices = np.arange(3)
for i in range(3):
k = np.delete(indices, i)
V = surface(X[:, k], S)
ax.plot(V[0], V[1], V[2], alpha=alpha, color=color)
V = V + X[:, [i]]
ax.plot(V[0], V[1], V[2], alpha=alpha, color=color)
def surface(X, S):
return np.dot(X, S)
def mask(X, row, column):
X = np.copy(X)
assert(X.shape[0] == X.shape[1])
indices = np.arange(0, X.shape[0])
c = np.delete(indices, column)
X[row, c] = 0
r = np.delete(indices, row)
X[r, column] = 0
# X[row, column] = pow(-1, row + column + 2) * X[row, column]
return X
X = np.array([
[1, -1, 0],
[1, 0, -1],
[1, 1, 2]
])
X = 2 * X
U, V, W = [mask(X, 2, c) for c in range(3)]
print(X, det(X))
print(U, det(U))
print(V, det(V))
print(W, det(W))
xrange, yrange, zrange = [-3, 3], [-3, 3], [0, 9]
fig = plt.figure()
ax = fig.add_subplot("111", projection='3d')
ax.set_aspect('equal')
ax.set_xlim(xrange)
ax.set_ylim(yrange)
ax.set_zlim(zrange)
draw(X, color="y")
draw(U, color="r")
draw(V, color="g")
draw(W, color="b")
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment