Skip to content

Commit 3e90025

Browse files
eric-wiesertimhoffm
authored andcommitted
BUG: Fix face orientations of bar3d (#12259)
* STY: Add trailing commas This makes the next commit easier to follow * 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 9b01a03 commit 3e90025

File tree

3 files changed

+15
-10
lines changed

3 files changed

+15
-10
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,11 +1736,14 @@ def _generate_normals(self, polygons):
17361736
Generate normals for polygons by using the first three points.
17371737
This normal of course might not make sense for polygons with
17381738
more than three points not lying in a plane.
1739+
1740+
Normals point towards the viewer for a face with its vertices in
1741+
counterclockwise order, following the right hand rule.
17391742
'''
17401743

17411744
normals = []
17421745
for verts in polygons:
1743-
v1 = np.array(verts[0]) - np.array(verts[1])
1746+
v1 = np.array(verts[1]) - np.array(verts[0])
17441747
v2 = np.array(verts[2]) - np.array(verts[0])
17451748
normals.append(np.cross(v1, v2))
17461749
return normals
@@ -2452,48 +2455,50 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
24522455
maxz = np.max(z + dz)
24532456

24542457
# shape (6, 4, 3)
2458+
# All faces are oriented facing outwards - when viewed from the
2459+
# outside, their vertices are in a counterclockwise ordering.
24552460
cuboid = np.array([
24562461
# -z
24572462
(
24582463
(0, 0, 0),
2459-
(1, 0, 0),
2464+
(0, 1, 0),
24602465
(1, 1, 0),
2461-
(0, 1, 0)
2466+
(1, 0, 0),
24622467
),
24632468
# +z
24642469
(
24652470
(0, 0, 1),
24662471
(1, 0, 1),
24672472
(1, 1, 1),
2468-
(0, 1, 1)
2473+
(0, 1, 1),
24692474
),
24702475
# -y
24712476
(
24722477
(0, 0, 0),
24732478
(1, 0, 0),
24742479
(1, 0, 1),
2475-
(0, 0, 1)
2480+
(0, 0, 1),
24762481
),
24772482
# +y
24782483
(
24792484
(0, 1, 0),
2480-
(1, 1, 0),
2485+
(0, 1, 1),
24812486
(1, 1, 1),
2482-
(0, 1, 1)
2487+
(1, 1, 0),
24832488
),
24842489
# -x
24852490
(
24862491
(0, 0, 0),
2487-
(0, 1, 0),
2492+
(0, 0, 1),
24882493
(0, 1, 1),
2489-
(0, 0, 1)
2494+
(0, 1, 0),
24902495
),
24912496
# +x
24922497
(
24932498
(1, 0, 0),
24942499
(1, 1, 0),
24952500
(1, 1, 1),
2496-
(1, 0, 1)
2501+
(1, 0, 1),
24972502
),
24982503
])
24992504

0 commit comments

Comments
 (0)