This is a simplified version of a make_pyramid
function.
from stl import mesh
import numpy as np
import matplotlib.pyplot as plt
def plot_mesh(stl_mesh):
fig = plt.figure()
ax = fig.add_subplot(111, projection="3d")
ax.plot_trisurf(vertices[:, 0], vertices[:, 1], vertices[:, 2], antialiased=True, linewidth=0.2)
def make_pyramid(offset=0.0):
side = np.zeros(1, dtype=mesh.Mesh.dtype)
side["vectors"][0] = np.array([[0 + offset, 0, 1],
[1, 0, 0],
[0, 1, 0]])
sides = []
bottom = np.zeros(2, dtype=mesh.Mesh.dtype)
bottom["vectors"][0] = np.array([[0, -1, 0],
[0, 1, 0],
[1, 0, 0]])
bottom["vectors"][1] = np.array([[0, -1, 0],
[0, 1, 0],
[-1, 0, 0]])
sides.append(bottom)
sides.append(side)
return mesh.Mesh(np.concatenate([side.data for side in sides]))
The parameter offset
is there to demonstrate the effect below. Depending on the offset value one triangle is visualized in a way that looks incorrect, not respecting any sound z offset. Note the vertical triangle in the first pair of visualizations below.
m = make_pyramid()
plot_mesh(m)
m.rotate([1, 2, 3], math.radians(37)) # to show from a different viewpoint
plot_mesh(m)
m = make_pyramid(0.5)
plot_mesh(m)
m.rotate([1, 2, 3], math.radians(37))
plot_mesh(m)
What is the problem here? What causes the difference?