pytrebuchet.projectile module

Module defining the Projectile class for trebuchet simulations.

class pytrebuchet.projectile.Projectile(*, mass: float | None = 3.0, density: float | None = None, diameter: float = 0.2, drag_coefficient: float | Callable[[float | ndarray[tuple[Any, ...], dtype[floating]]], float | ndarray[tuple[Any, ...], dtype[floating]]] | None = None)

Bases: object

Represent a spherical projectile launched by the trebuchet.

__init__(*, mass: float | None = 3.0, density: float | None = None, diameter: float = 0.2, drag_coefficient: float | Callable[[float | ndarray[tuple[Any, ...], dtype[floating]]], float | ndarray[tuple[Any, ...], dtype[floating]]] | None = None) None

Initialize a Projectile instance.

It assumes a spherical shape for drag calculations.

Parameters:
  • mass – mass of the projectile (kg). If None, mass is calculated from density and diameter.

  • density – density of the projectile (kg/m^3). If mass is given, density should be None.

  • diameter – diameter of the projectile (m)

  • drag_coefficient

    drag coefficient (dimensionless)

    • float: constant drag coefficient

    • callable: function that takes Reynolds number as input and returns a drag coefficient. The function should be vectorized to handle numpy arrays.

    • None: use default drag coefficient function for smooth spheres calculated using the Clift-Grace-Weber correlation.

drag_coefficient: Callable[[float | ndarray[tuple[Any, ...], dtype[floating]]], float | ndarray[tuple[Any, ...], dtype[floating]]]
classmethod default() Projectile

Create a Projectile instance with default parameters.

Returns:

Projectile instance with default mass, diameter, and drag coefficient

property radius: float

Get the radius of the spherical projectile.

Returns:

radius (m)

property volume: float

Get the volume of the spherical projectile.

Returns:

volume (m^3)

property density: float

Get the density of the spherical projectile.

Returns:

density (kg/m^3)

property effective_area: float

Get the effective cross-sectional area of the spherical projectile.

Returns:

effective area (m^2)