Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2e54be2

Browse files
Speed up calculations for default tilt=0
1 parent f3846da commit 2e54be2

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def rotation_about_vector(v, angle):
5555
"""
5656
Produce a rotation matrix for an angle in radians about a vector.
5757
"""
58-
v /= np.linalg.norm(v)
58+
v = v/np.linalg.norm(v)
5959
s = np.sin(angle)
6060
c = np.cos(angle)
6161
t = 1-c
@@ -73,15 +73,16 @@ def view_transformation(E, R, V, tilt):
7373
n = n/np.linalg.norm(n)
7474
u = np.cross(V, n)
7575
u = u/np.linalg.norm(u)
76-
v = np.cross(n, u)
77-
v = v/np.linalg.norm(v)
76+
v = np.cross(n, u) # Will be a unit vector
7877

79-
Rtilt = rotation_about_vector(n, tilt)
80-
u = np.dot(Rtilt, u)
81-
v = np.dot(Rtilt, v)
78+
# Save some computation for the default tilt=0
79+
if tilt != 0:
80+
Rtilt = rotation_about_vector(n, tilt)
81+
u = np.dot(Rtilt, u)
82+
v = np.dot(Rtilt, v)
8283

83-
Mr = np.diag([1.] * 4)
84-
Mt = np.diag([1.] * 4)
84+
Mr = np.eye(4)
85+
Mt = np.eye(4)
8586
Mr[:3, :3] = [u, v, n]
8687
Mt[:3, -1] = -E
8788

0 commit comments

Comments
 (0)