Hull Module

The Hull module provides functionality for loading, transforming, and exporting hull geometries from STL and VTK files.

Hull Class

class pynavaltoolbox.hull.Hull(file_path: str, ap: float | None = None, fp: float | None = None)[source]

Bases: object

Represents a hull geometry with loading, transformation, and export capabilities.

polydata

The VTK polydata representing the hull mesh.

Type:

vtk.vtkPolyData

file_path

Path to the original file.

Type:

str

__init__(file_path: str, ap: float | None = None, fp: float | None = None)[source]

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:
property ap: float

Returns the Aft Perpendicular position.

property fp: float

Returns the Forward Perpendicular position.

get_bounds() Tuple[float, float, float, float, float, float][source]

Returns the bounding box of the hull.

Returns:

Tuple of (xmin, xmax, ymin, ymax, zmin, zmax).

transform(translation: Tuple[float, float, float] = (0, 0, 0), rotation: Tuple[float, float, float] = (0, 0, 0), pivot: Tuple[float, float, float] = (0, 0, 0)) None[source]

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.

scale(factor: float | None = None, factors: Tuple[float, float, float] | None = None, target_bounds: Tuple[float, float, float, float, float, float] | None = None) None[source]

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.

simplify(target_reduction: float = 0.5) None[source]

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.

export(file_path: str) None[source]

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")