Hull Module
The Hull module provides functionality for loading, transforming, and exporting hull geometries from STL and VTK files.
Hull Class
Bases:
objectRepresents a hull geometry with loading, transformation, and export capabilities.
The VTK polydata representing the hull mesh.
- Type:
vtk.vtkPolyData
Path to the original file.
- Type:
Loads a hull geometry from an STL or VTK file.
- Parameters:
file_path – Path to the STL or VTK file.
ap – Longitudinal position of Aft Perpendicular. If None, uses min x of geometry.
fp – Longitudinal position of Forward Perpendicular. If None, uses max x of geometry.
- Raises:
FileNotFoundError – If the file does not exist.
ValueError – If the file format is not supported.
Returns the Aft Perpendicular position.
Returns the Forward Perpendicular position.
Returns the bounding box of the hull.
- Returns:
Tuple of (xmin, xmax, ymin, ymax, zmin, zmax).
Applies a transformation to the hull geometry.
- Parameters:
translation – (dx, dy, dz) translation vector.
rotation – (rx, ry, rz) rotation angles in degrees around X, Y, Z axes.
pivot – (px, py, pz) point around which rotation occurs.
Scales the hull geometry.
- Parameters:
factor – Uniform scale factor (applied to x, y, z).
factors – Tuple of (sx, sy, sz) for non-uniform scaling.
target_bounds – (xmin, xmax, ymin, ymax, zmin, zmax) to fit the mesh into. Overrides factor and factors if provided.
Simplifies the hull mesh by reducing the number of polygons. Useful for speeding up calculations with minimal loss of accuracy.
- Parameters:
target_reduction – Fraction of polygons to remove (0.0 to 1.0). e.g. 0.5 removes 50% of polygons.
Exports the current hull geometry to a file.
- Parameters:
file_path – Path to save the file. Format determined by extension (.stl or .vtk).
- Raises:
ValueError – If the file format is not supported.
Example Usage
from pynavaltoolbox import Hull
# Load a hull from an STL file
hull = Hull("model.stl")
# Get bounds
bounds = hull.get_bounds()
print(f"Length: {bounds[1] - bounds[0]:.2f} m")
# Apply transformations
hull.transform(
translation=(0, 0, 5),
rotation=(0, 0, 0)
)
# Scale the hull
hull.scale(factor=1.5)
# Simplify for faster calculations
hull.simplify(target_reduction=0.3)
# Export to VTK format
hull.export("output.vtk")