【问题标题】:Rotate stl file in matplotlib 3d在 matplotlib 3d 中旋转 stl 文件
【发布时间】:2020-04-17 18:07:12
【问题描述】:

我正在使用 numpy-stl 在绘图中打开 stl 文件。它是打开的 stl 文件。但我有一个问题。我想像这样在图中旋转 stl 文件:

代码在这里:

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()

【问题讨论】:

  • 您的箭头有点模棱两可,但无论如何,这应该是找到正确的旋转矩阵 (en.wikipedia.org/wiki/Rotation_matrix) 并将网格中的每个点乘以该矩阵以获得新点的问题.例如,如果您想绕 z 轴旋转,请将每个点的 x 和 y 坐标相乘,如 wiki 文章中的示例所示。

标签: python matplotlib stl numpy-stl


【解决方案1】:

我解决了这个问题。如果您对 numpy-stl 旋转问题或其他问题有疑问,可以毫不犹豫地问我。 这是我的解决方案:

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

代码:

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))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-12-18
    • 1970-01-01
    • 2017-08-28
    • 2018-10-03
    • 2013-08-23
    相关资源
    最近更新 更多