2

I want to plot (filled) polygons that are given by a sequence of points that define the boundary in 3d. Unfortunately these polygons intersect eachother.

Here is a minimal example that shows two squares that intersect, with the issue that they are not plotted correctly. In my actual application these polygons are generated on the fly, so it is also not possible to manually define a triangulation of the polygon. I'm aware that with Poly3DCollection, there is no chance of doing this correctly as the polygons will only be filled after the projection.

Can anyone recommend another method that allows drawing polygons in 3d with correct intersections?

intersection is not computed

import numpy as np
from mpl_toolkits.mplot3d import Axes3D
from mpl_toolkits.mplot3d.art3d import Poly3DCollection
import matplotlib.pyplot as plt
fig = plt.figure()
ax = Axes3D(fig)
verts1 = np.array([
    [0, 0, 0.5],
    [1, 0, 0.5],
    [1, 1, 0.5],
    [0, 1, 0.5]
])
verts2 = verts1[:, [1, 2, 0]]
verts = [verts1, verts2]
ax.add_collection3d(p3c := Poly3DCollection(verts))
p3c.set_facecolor([(1, 0, 0), (0, 1, 0)])
plt.show()
flawr
  • 10,814
  • 3
  • 41
  • 71

0 Answers0