Closed NicoAraujo80 closed 4 years ago
I created a new versions 4 days ago that fixed this, I think you might be using the older version :) https://github.com/WoLpH/numpy-stl/issues/122
Your right. I had seen that issue and had uninstalled the package and reinstalled it with pip, but the problem still persisted. I thought it wasn't fully fixed.
As far as I can see it's working properly. Generating half a cube with sides size 1 I get 3 as expected:
from stl import mesh
import numpy
# Create 3 faces of a cube
data = numpy.zeros(6, dtype=mesh.Mesh.dtype)
# Top of the cube
data['vectors'][0] = numpy.array([[0, 1, 1],
[1, 0, 1],
[0, 0, 1]])
data['vectors'][1] = numpy.array([[1, 0, 1],
[0, 1, 1],
[1, 1, 1]])
# Front face
data['vectors'][2] = numpy.array([[1, 0, 0],
[1, 0, 1],
[1, 1, 0]])
data['vectors'][3] = numpy.array([[1, 1, 1],
[1, 0, 1],
[1, 1, 0]])
# Left face
data['vectors'][4] = numpy.array([[0, 0, 0],
[1, 0, 0],
[1, 0, 1]])
data['vectors'][5] = numpy.array([[0, 0, 0],
[0, 0, 1],
[1, 0, 1]])
half_cube = mesh.Mesh(data.copy())
print(half_cube.areas.sum())
# returns 3
Yea it works now because I manually changed the files. I don't know much about pip but it doesn't seem to be installing the commit from 4 days ago which solved this problem.
you're right, looks like something went wrong with the release
I'll create a new release
On Tue, 31 Mar 2020, 21:03 NicoAraujo80, notifications@github.com wrote:
Yea it works now because I manually changed the files. I don't know much about pip but it doesn't seem to be installing the commit from 4 days ago which solved this problem.
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/WoLpH/numpy-stl/issues/124#issuecomment-606814313, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACCB2ZDLTMQZWUO65XSYOLRKI5A3ANCNFSM4LXIQWTQ .
Thanks for letting me know the release failed :)
No problem, glad I could help
When calculating the area in base.py file
def update_areas(self):
areas = .5 * numpy.sqrt((self.normals ** 2).sum(axis=1))
self.areas = areas.reshape((areas.size, 1))
self.normals all have magnitudes of one causing areas to be equal to half the amount of triangles in the stl fileThe code I used to test this after seeing that a calculation I was making was off was:
from stl import mesh
stlObject = mesh.Mesh.from_file('40mmcube.stl')
stlObject.update_areas()
area = stlObject.areas.sum()
with the area coming back as 6. There are 12 normals 4 pointing in the x, y, and z axis all with a magnitude of 1. I'm assuming that for the area to be calculated properly the normals have a magnitude equal to the area of that triangle. Though I was not able to track down where the normals get calculated.