Obtaining the area of a mesh section
omaralvarez opened this issue · comments
I am trying to get the area of the intersection of a mesh with a plane. Right now I am using the following code to get the section:
slice = mesh.section(
plane_normal=n,
plane_origin=p,
)
Is it possible to get instead of the outline of the section a filled polygon? Is it possible to get a mesh from a Path3D?
Hey, I think you want slice.polygons_full[0].area
or sum(p.area for p in slice.polygons_full)
Amazing, I will test it out and see if it works!! Thanks a lot!
I'm getting the following error:
AttributeError: 'Path3D' object has no attribute 'polygons_full'
Ah you have to move it to a plane from 3D:
In [14]: m = trimesh.creation.box()
In [15]: s = m.section(plane_origin=m.center_mass, plane_normal=[0,0,1])
In [17]: sum(p.area for p in s.to_planar()[0].polygons_full)
Out[17]: 1.0
Works like a charm, just for refererence I ended up with:
slice = mesh.section(
plane_normal=n,
plane_origin=p,
)
if slice is not None:
area = sum(p.area for p in slice.to_planar()[0].polygons_full)
else:
area = 0.0
If plane does not intersect you get None and it errors out.
Thanks a lot for the help!