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

Skip to content

Commit 05c60cc

Browse files
committed
BUG: Fix face orientations of bar3d
Fixes #12138, which is caused by these incorrect orientations. This also corrects _generate_normals to use a counterclockwise convention
1 parent 304859e commit 05c60cc

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1733,11 +1733,14 @@ def _generate_normals(self, polygons):
17331733
Generate normals for polygons by using the first three points.
17341734
This normal of course might not make sense for polygons with
17351735
more than three points not lying in a plane.
1736+
1737+
Normals point towards the viewer for a face with its vertices in
1738+
counterclockwise order, following the right hand rule.
17361739
'''
17371740

17381741
normals = []
17391742
for verts in polygons:
1740-
v1 = np.array(verts[0]) - np.array(verts[1])
1743+
v1 = np.array(verts[1]) - np.array(verts[0])
17411744
v2 = np.array(verts[2]) - np.array(verts[0])
17421745
normals.append(np.cross(v1, v2))
17431746
return normals
@@ -2449,13 +2452,15 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
24492452
maxz = np.max(z + dz)
24502453

24512454
# shape (6, 4, 3)
2455+
# All faces are oriented facing outwards - when viewed from the
2456+
# outside, their vertices are in a counterclockwise ordering.
24522457
cuboid = np.array([
24532458
# -z
24542459
(
24552460
(0, 0, 0),
2456-
(1, 0, 0),
2457-
(1, 1, 0),
24582461
(0, 1, 0),
2462+
(1, 1, 0),
2463+
(1, 0, 0),
24592464
),
24602465
# +z
24612466
(
@@ -2474,16 +2479,16 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
24742479
# +y
24752480
(
24762481
(0, 1, 0),
2477-
(1, 1, 0),
2478-
(1, 1, 1),
24792482
(0, 1, 1),
2483+
(1, 1, 1),
2484+
(1, 1, 0),
24802485
),
24812486
# -x
24822487
(
24832488
(0, 0, 0),
2484-
(0, 1, 0),
2485-
(0, 1, 1),
24862489
(0, 0, 1),
2490+
(0, 1, 1),
2491+
(0, 1, 0),
24872492
),
24882493
# +x
24892494
(

0 commit comments

Comments
 (0)