LHEEA / meshmagick

A command line tool and a python package to manipulate hydrodynamics meshes
GNU General Public License v3.0
48 stars 27 forks source link

fix hydrostatics bug for submerged body #24

Closed akeeste closed 3 years ago

akeeste commented 3 years ago

@frongere

I'd like to submit a fix for a bug that prevents the meshmagick hydrostatics module being used with completely submerged bodies. This resolves issues #7 and #19.

Essentially, if a body is fully submerged the code tries to create two clipped meshes above and below the water plane. However, if the body if fully submerged, the upper mesh is empty and cannot be initialized properly because it has no vertices or faces.

This PR changes the hydrostatics.py function to include a 'submerged' boolean property. If the body is submerged (mesh.axis_aligned_bbox[5] < 0) then the clipped_mesh is equivalent to the original mesh, and some calculations are skipped to avoid division by zero.

Thanks, Adam