pythonmatplotlibnumpy-stl

Rotate stl file in matplotlib 3d


I'm using numpy-stl for open stl file in plot. It is open stl file. But i have a problem. I want to rotate stl file in plot like this image:

enter image description here

Code is here:

from stl import mesh
from mpl_toolkits import mplot3d
from matplotlib import pyplot
from math import sin,cos,pi
import numpy as np

# Create a new plot
figure = pyplot.figure()
axes = mplot3d.Axes3D(figure)

m1 = mesh.Mesh.from_file('filea.stl')
axes.add_collection3d(mplot3d.art3d.Poly3DCollection(m1.vectors))

# Auto scale to the mesh size
scale = m1.points.flatten()
axes.auto_scale_xyz(scale-10, scale+10, scale)

# Show the plot to the screen
pyplot.show()

Solution

  • I solved this problem. If you have question about numpy-stl rotation problem or another problems, you can ask me without hesitation. Here is my solution:

    self.m1 = mesh.Mesh.from_file('assets/file.stl')
    self.m1.rotate([x-axis, y-axis, z-axis], math.radians(angle))
    

    code:

    self.m1.rotate([1, 0, 0], math.radians(angleinxaxis))
    self.m1.rotate([0, 1, 0], math.radians(angleinyaxis))
    self.m1.rotate([0, 0, 1], math.radians(angleinzaxis))