Skip to content

Commit e9b652e

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 b3c9f05 commit e9b652e

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

lib/mpl_toolkits/mplot3d/axes3d.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1717,13 +1717,16 @@ def _generate_normals(self, polygons):
17171717
Generate normals for polygons by using the first three points.
17181718
This normal of course might not make sense for polygons with
17191719
more than three points not lying in a plane.
1720+
1721+
Normals point towards the viewer for a face with its vertices in
1722+
counterclockwise order, following the right hand rule.
17201723
'''
17211724

17221725
normals = []
17231726
for verts in polygons:
1724-
v1 = np.array(verts[0]) - np.array(verts[1])
1725-
v2 = np.array(verts[2]) - np.array(verts[0])
1726-
normals.append(np.cross(v1, v2))
1727+
v1 = np.array(verts[1]) - np.array(verts[0])
1728+
v2 = np.array(verts[0]) - np.array(verts[2])
1729+
normals.append(np.cross(v2, v1))
17271730
return normals
17281731

17291732
def _shade_colors(self, color, normals, lightsource=None):
@@ -2433,13 +2436,15 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
24332436
maxz = np.max(z + dz)
24342437

24352438
# shape (6, 4, 3)
2439+
# All faces are oriented facing outwards - when viewed from the
2440+
# outside, their vertices are in a counterclockwise ordering.
24362441
cuboid = np.array([
24372442
# -z
24382443
(
24392444
(0, 0, 0),
2440-
(1, 0, 0),
2441-
(1, 1, 0),
24422445
(0, 1, 0),
2446+
(1, 1, 0),
2447+
(1, 0, 0),
24432448
),
24442449
# +z
24452450
(
@@ -2458,16 +2463,16 @@ def bar3d(self, x, y, z, dx, dy, dz, color=None,
24582463
# +y
24592464
(
24602465
(0, 1, 0),
2461-
(1, 1, 0),
2462-
(1, 1, 1),
24632466
(0, 1, 1),
2467+
(1, 1, 1),
2468+
(1, 1, 0),
24642469
),
24652470
# -x
24662471
(
24672472
(0, 0, 0),
2468-
(0, 1, 0),
2469-
(0, 1, 1),
24702473
(0, 0, 1),
2474+
(0, 1, 1),
2475+
(0, 1, 0),
24712476
),
24722477
# +x
24732478
(

0 commit comments

Comments
 (0)