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

Skip to content

Commit fa7784c

Browse files
committed
implemented orthographic projection
1 parent 5faff6e commit fa7784c

6 files changed

Lines changed: 676 additions & 2 deletions

File tree

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ def __init__(self, fig, rect=None, *args, **kwargs):
6363
*elev* Elevation viewing angle (default 30)
6464
*zscale* [%(scale)s]
6565
*sharez* Other axes to share z-limits with
66+
*persp* Perspective projection (default True)
6667
================ =========================================
6768
6869
.. versionadded :: 1.2.1
@@ -78,6 +79,7 @@ def __init__(self, fig, rect=None, *args, **kwargs):
7879
self.initial_elev = kwargs.pop('elev', 30)
7980
zscale = kwargs.pop('zscale', None)
8081
sharez = kwargs.pop('sharez', None)
82+
self.set_persp(kwargs.pop('persp', True))
8183

8284
self.xy_viewLim = unit_bbox()
8385
self.zz_viewLim = unit_bbox()
@@ -959,6 +961,18 @@ def view_init(self, elev=None, azim=None):
959961
else:
960962
self.azim = azim
961963

964+
def set_persp(self, persp):
965+
"""
966+
Set whether the projection should be perspective.
967+
968+
If set to *False*, orthographic projection will be used.
969+
970+
"""
971+
if persp:
972+
self._projection = proj3d.persp_transformation
973+
else:
974+
self._projection = proj3d.ortho_transformation
975+
962976
def get_proj(self):
963977
"""
964978
Create the projection matrix from the current viewing position.
@@ -1001,9 +1015,9 @@ def get_proj(self):
10011015
zfront, zback = -self.dist, self.dist
10021016

10031017
viewM = proj3d.view_transformation(E, R, V)
1004-
perspM = proj3d.persp_transformation(zfront, zback)
1018+
projM = self._projection(zfront, zback)
10051019
M0 = np.dot(viewM, worldM)
1006-
M = np.dot(perspM, M0)
1020+
M = np.dot(projM, M0)
10071021
return M
10081022

10091023
def mouse_init(self, rotate_btn=1, zoom_btn=3):

lib/mpl_toolkits/mplot3d/proj3d.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,15 @@ def persp_transformation(zfront, zback):
124124
[0,0,-1,0]
125125
])
126126

127+
def ortho_transformation(zfront, zback):
128+
a = -(zfront + zback)
129+
b = -(zfront - zback)
130+
return np.array([[2,0,0,0],
131+
[0,2,0,0],
132+
[0,0,-2,0],
133+
[0,0,a,b]
134+
])
135+
127136
def proj_transform_vec(vec, M):
128137
vecw = np.dot(M, vec)
129138
w = vecw[3]
Binary file not shown.
42.2 KB
Loading

0 commit comments

Comments
 (0)