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

Skip to content

Commit 78733ce

Browse files
committed
some 3d speedups
svn path=/trunk/matplotlib/; revision=2521
1 parent 810b3de commit 78733ce

2 files changed

Lines changed: 9 additions & 26 deletions

File tree

lib/matplotlib/axes3d.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ def plot_surface(self, X, Y, Z, *args, **kwargs):
530530
lines = []
531531
shade = []
532532
for box in boxes:
533-
n = proj3d.cross(box[0]-box[1],
533+
n = nx.crossbox[0]-box[1],
534534
box[0]-box[2])
535535
n = n/proj3d.mod(n)*5
536536
shade.append(nx.dot(n,[-1,-1,0.5]))

lib/matplotlib/proj3d.py

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,6 @@
1111
from numerix import linear_algebra
1212
from math import sqrt
1313

14-
def _hide_cross(a,b):
15-
"""
16-
Cross product of two vectors
17-
A x B = <Ay*Bz - Az*By, Az*Bx - Ax*Bz, Ax*By - Ay*Bx>
18-
a x b = [a2b3 - a3b2, a3b1 - a1b3, a1b2 - a2b1]
19-
"""
20-
return nx.array([a[1]*b[2]-a[2]*b[1],a[2]*b[0]-a[0]*b[2],a[0]*b[1] - a[1]*b[0]])
21-
cross = _hide_cross
22-
2314
def line2d(p0,p1):
2415
"""
2516
Return 2D equation of line in the form ax+by+c = 0
@@ -142,21 +133,14 @@ def test_world():
142133

143134
def view_transformation(E, R, V):
144135
n = (E - R)
145-
n = n / mod(n)
146-
u = cross(V,n)
147-
u = u / mod(u)
148-
v = cross(n,u)
149-
Mr = [[u[0],u[1],u[2],0],
150-
[v[0],v[1],v[2],0],
151-
[n[0],n[1],n[2],0],
152-
[0, 0, 0, 1],
153-
]
154-
#
155-
Mt = [[1, 0, 0, -E[0]],
156-
[0, 1, 0, -E[1]],
157-
[0, 0, 1, -E[2]],
158-
[0, 0, 0, 1]]
159-
136+
n /= mod(n)
137+
u = nx.cross(V,n)
138+
u /= mod(u)
139+
v = nx.cross(n,u)
140+
Mr = nx.diag([1.]*4)
141+
Mt = nx.diag([1.]*4)
142+
Mr[:3,:3] = u,v,n
143+
Mt[:3,-1] = -E
160144
return nx.matrixmultiply(Mr,Mt)
161145

162146
def persp_transformation(zfront,zback):
@@ -173,7 +157,6 @@ def proj_transform_vec(vec, M):
173157
w = vecw[3]
174158
# clip here..
175159
txs,tys,tzs = vecw[0]/w,vecw[1]/w,vecw[2]/w
176-
#tis = vecw[0] > 0 and vecw[0] < 1 and vecw[1] > 0 and vecw[1] < 1
177160
return txs,tys,tzs
178161

179162
def proj_transform_vec_clip(vec, M):

0 commit comments

Comments
 (0)