wolph / numpy-stl

Simple library to make working with STL files (and 3D objects in general) fast and easy.
http://numpy-stl.readthedocs.org/
BSD 3-Clause "New" or "Revised" License
605 stars 103 forks source link

Z-height #202

Closed agen49 closed 1 year ago

agen49 commented 1 year ago

Hello,

Thanks to everyone who made this library available to public.

1) Is there an option to rotate an stll object using x, y, and z angles? If yes, how?

2) Is there an option to find the Z-height of an stl object at a specific orientation? If yes, how?

Thank you.

P.S. I am new to programming, my background is in environmental engineering.

wolph commented 1 year ago
  1. Yes, take a look at the example of the readme: https://github.com/WoLpH/numpy-stl#modifying-mesh-objects
  2. The easiest method I can think of is by rotating first and doing mesh.z.max() - mesh.z.min()
agen49 commented 1 year ago

Thank you for replying back. I appreciate the time.

  1. I've tried to follow the code but I am kinda lost. Would you please post a code example on this page for ONLY the lines of codes that any user can use to rotate their parts?

  2. I am getting an error "module 'stl.mesh' has no attribute 'z'".

wolph commented 1 year ago

from stl import mesh

your_mesh = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')

# Rotate 90 degrees over the Y axis
your_mesh.rotate([0.0, 0.5, 0.0], math.radians(90))

z_height = your_mesh.z.max() - your_mesh.z.min()
agen49 commented 1 year ago

Thank you very much. Honestly, I didn't expect it to be that simple, I thought I need to copy all the code under "modifying mech objects" and tweak it. Thank you for clarifying that, very kind of you. I've seen you posted a citation for your code on another post, I'll make sure to use that. Have a good day/night.

agen49 commented 9 months ago

Thank you, when I do double rotation, The Z-height value I get from Numpy-stl is different than the one I get from slicing software, may I ask why? Am I doing something wrong?

Rotate # degrees over the Y axis

your_mesh.rotate([0.0, 1.0, 0.0], math.radians(15))

Rotate # degrees over the X axis

your_mesh.rotate([1.0, 0.0, 0.0], math.radians(15))

And I commute the Z-height using:

z_height = your_mesh.z.max() - your_mesh.z.min() z_height

On Sep 14, 2022, at 7:05 AM, Rick van Hattem @.***> wrote:

from stl import mesh

your_mesh = mesh.Mesh.from_file('tests/stl_binary/HalfDonut.stl')

Rotate 90 degrees over the Y axis

your_mesh.rotate([0.0, 0.5, 0.0], math.radians(90))

z_height = your_mesh.z.max() - your_mesh.z.min() — Reply to this email directly, view it on GitHub https://github.com/WoLpH/numpy-stl/issues/202#issuecomment-1246603534, or unsubscribe https://github.com/notifications/unsubscribe-auth/A3ADPAPK5BAK5LIYRG554YLV6GWQVANCNFSM6AAAAAAQKZ46UQ. You are receiving this because you authored the thread.