-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcube_matlib.py
53 lines (44 loc) · 1.5 KB
/
cube_matlib.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
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation
A = np.array([-0.5,-0.5,-0.5])
B = np.array([0.5,-0.5,-0.5])
C = np.array([0.5,0.5,-0.5])
D = np.array([-0.5,0.5,-0.5])
E = np.array([-0.5,-0.5,0.5])
F = np.array([0.5,-0.5,0.5])
G = np.array([0.5,0.5,0.5])
H = np.array([-0.5,0.5,0.5])
load = np.array([A,B,C,D,E,F,G,H])
print(load)
fig = plt.figure()
ax = plt.axes(xlim =(-1,1),ylim =(-1,1))
# Declared to allow for x and y axis only
projection = np.array([ [1,0,0], [0,1,0] ])
plt.title("Render 3D Cube in 2D Space")
for x in load:
for angle in range(360):
rotationY = np.array([ [np.cos(angle),0,np.sin(angle)],
[0,1,0],
[-np.sin(angle),0,np.cos(angle)] ])
rotationX = np.array([ [1,0,0],
[0,np.cos(angle),-np.sin(angle)],
[0,np.sin(angle),np.cos(angle)] ])
# Drawing each points
rotated = np.dot(rotationY,x)
rotated = np.dot(rotationX,rotated)
projected2d = np.dot(projection,rotated)
#projected2d = np.dot(projection,x) -With no rotations
ax.plot(projected2d[0],projected2d[1],c = "blue",marker = "o")[0]
plt.grid()
#plt.draw()
plt.show()
# rotationZ = np.array([ [np.cos(angle),-np.sin(angle),0],
# [np.sin(angle),np.cos(angle),0],
# [0,0,1] ])
# rotationY = np.array([ [np.cos(angle),0,np.sin(angle)],
# [0,1,0],
# [-np.sin(angle),0,np.cos(angle)] ])
# rotationX = np.array([ [1,0,0],
# [0,np.cos(angle),-np.sin(angle)],
# [0,np.sin(angle),np.cos(angle)] ])