pytrebuchet.trebuchet module
Module defining the Trebuchet class.
Provides methods for calculating positions, velocities, and accelerations of trebuchet components.
- class pytrebuchet.trebuchet.Arm(length_weight_side: float, length_projectile_side: float, mass: float, inertia: float | None = None, d_pivot_to_cog: float | None = None)
Bases:
objectDataclass representing the trebuchet arm.
- length_weight_side: float
- length_projectile_side: float
- mass: float
- inertia: float | None = None
- d_pivot_to_cog: float | None = None
- property total_length: float
Calculate the total length of the arm.
- Returns:
total length of the arm (m)
- __init__(length_weight_side: float, length_projectile_side: float, mass: float, inertia: float | None = None, d_pivot_to_cog: float | None = None) None
- class pytrebuchet.trebuchet.Weight(mass: float)
Bases:
objectDataclass representing the trebuchet counterweight.
- mass: float
- __init__(mass: float) None
- class pytrebuchet.trebuchet.Pivot(height: float)
Bases:
objectDataclass representing the trebuchet pivot.
- height: float
- __init__(height: float) None
- class pytrebuchet.trebuchet.Sling(length: float)
Bases:
objectDataclass representing a trebuchet sling.
- length: float
- __init__(length: float) None
- class pytrebuchet.trebuchet.Trebuchet(arm: Arm, weight: Weight, pivot: Pivot, sling_projectile: Sling, sling_weight: Sling, release_angle: float = 0.7853981633974483, projectile: Projectile | None = None)
Bases:
ABCClass representing a trebuchet.
The trebuchet’s position is defined by three angles: - angle_arm: angle of the arm w.r.t. the horizontal (radians) - angle_projectile: angle of the projectile sling w.r.t. the horizontal (radians) - angle_weight: angle of the weight sling w.r.t. the horizontal (radians)
- __init__(arm: Arm, weight: Weight, pivot: Pivot, sling_projectile: Sling, sling_weight: Sling, release_angle: float = 0.7853981633974483, projectile: Projectile | None = None) None
Initialize a Trebuchet instance with the given parameters.
- Parameters:
arm – Arm instance
weight – Weight instance
pivot – Pivot instance
projectile – Projectile instance
sling_projectile – Sling instance for the projectile
sling_weight – Sling instance for the weight
release_angle – angle at which the projectile is released (radians)
- init_angle_arm: float
- init_angle_weight: float
- init_angle_projectile: float
- abstractmethod _initialize_angles() None
Calculate the initial angles of the trebuchet based on its configuration.
- abstractmethod classmethod default() Trebuchet
Create a Trebuchet instance with default parameters.
- calculate_arm_cog(angle_arm: float) tuple[float, float]
- calculate_arm_cog(angle_arm: ndarray[tuple[Any, ...], dtype[floating]]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]
Calculate the x and y coordinates of the arm center of gravity.
- calculate_arm_endpoint_projectile(angle_arm: float) tuple[float, float]
- calculate_arm_endpoint_projectile(angle_arm: ndarray[tuple[Any, ...], dtype[floating]]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]
Calculate the x, y coordinates of the projectile arm endpoint.
- Parameters:
angle_arm – angle of the arm (radians)
- Returns:
x, y coordinates of the projectile arm endpoint, respectively
- calculate_arm_endpoint_weight(angle_arm: float) tuple[float, float]
- calculate_arm_endpoint_weight(angle_arm: ndarray[tuple[Any, ...], dtype[floating]]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]
Calculate the x, y coordinates of the weight arm endpoint.
- Parameters:
angle_arm – angle of the arm (radians)
- Returns:
x, y coordinates of the weight arm endpoint, respectively
- calculate_weight_point(angle_arm: float, angle_weight: float) tuple[float, float]
- calculate_weight_point(angle_arm: ndarray[tuple[Any, ...], dtype[floating]], angle_weight: ndarray[tuple[Any, ...], dtype[floating]]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]
Calculate the x, y coordinates of the weight point.
- Parameters:
angle_arm – angle of the arm (radians)
angle_weight – angle of the weight sling (radians)
- Returns:
x, y coordinates of the weight point
- calculate_projectile_point(angle_arm: float, angle_projectile: float) tuple[float, float]
- calculate_projectile_point(angle_arm: ndarray[tuple[Any, ...], dtype[floating]], angle_projectile: ndarray[tuple[Any, ...], dtype[floating]]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]
Calculate the x, y coordinates of the projectile point.
- Parameters:
angle_arm – angle of the arm (radians)
angle_projectile – angle of the projectile (radians)
- Returns:
x, y coordinates of the projectile point
- _abc_impl = <_abc._abc_data object>
- calculate_projectile_velocity(angle_arm: float, angle_projectile: float, angular_velocity_arm: float, angular_velocity_projectile: float) tuple[float, float]
- calculate_projectile_velocity(angle_arm: ndarray[tuple[Any, ...], dtype[floating]], angle_projectile: ndarray[tuple[Any, ...], dtype[floating]], angular_velocity_arm: ndarray[tuple[Any, ...], dtype[floating]], angular_velocity_projectile: ndarray[tuple[Any, ...], dtype[floating]]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]
Calculate the x, y components of the projectile velocity.
- Parameters:
angle_arm – angle of the arm (radians)
angle_projectile – angle of the projectile (radians)
angular_velocity_arm – angular velocity of the arm (radians/s)
angular_velocity_projectile – angular velocity of the projectile sling (radians/s)
- Returns:
x, y components of the projectile velocity
- calculate_projectile_acceleration(angle_arm: float, angle_projectile: float, angular_velocity_arm: float, angular_velocity_projectile: float, angular_acceleration_arm: float, angular_acceleration_projectile: float) tuple[float, float]
- calculate_projectile_acceleration(angle_arm: ndarray[tuple[Any, ...], dtype[floating]], angle_projectile: ndarray[tuple[Any, ...], dtype[floating]], angular_velocity_arm: ndarray[tuple[Any, ...], dtype[floating]], angular_velocity_projectile: ndarray[tuple[Any, ...], dtype[floating]], angular_acceleration_arm: ndarray[tuple[Any, ...], dtype[floating]], angular_acceleration_projectile: ndarray[tuple[Any, ...], dtype[floating]]) tuple[ndarray[tuple[Any, ...], dtype[floating]], ndarray[tuple[Any, ...], dtype[floating]]]
Calculate the x, y components of the projectile acceleration.
- Parameters:
angle_arm – angle of the arm (radians)
angle_projectile – angle of the projectile (radians)
angular_velocity_arm – angular velocity of the arm (radians/s)
angular_velocity_projectile – angular velocity of the projectile sling (radians/s)
angular_acceleration_arm – angular acceleration of the arm (radians/s^2)
angular_acceleration_projectile – angular acceleration of the projectile sling (radians/s^2)
- Returns:
x, y components of the projectile acceleration
- class pytrebuchet.trebuchet.HingedCounterweightTrebuchet(arm: Arm, weight: Weight, pivot: Pivot, sling_projectile: Sling, sling_weight: Sling, release_angle: float = 0.7853981633974483, projectile: Projectile | None = None)
Bases:
TrebuchetClass representing a hinged counterweight trebuchet.
- _abc_impl = <_abc._abc_data object>
- _initialize_angles() None
Calculate the initial angles of the trebuchet.
Calculate:
angle_arm such that the projectile arm end just touches the ground. If the arm is too short to reach the ground, set a default angle of 55 degrees.
angle_weight such that the weight hangs vertically downwards.
angle_projectile such that the projectile just touches the ground. If the sling is too short to reach the ground, set the sling angle such that it hangs vertically downwards.
- classmethod default() HingedCounterweightTrebuchet
Create a hinged counterweight Trebuchet instance with default parameters.
These parameters are taken from https://virtualtrebuchet.com/.
- class pytrebuchet.trebuchet.WhipperTrebuchet(arm: Arm, weight: Weight, pivot: Pivot, projectile: Projectile, sling_projectile: Sling, sling_weight: Sling, release_angle: float, arm_angle: float = 1.0471975511965976, weight_angle: float = 0.17453292519943295)
Bases:
TrebuchetClass representing a whipper trebuchet.
A whipper trebuchet features a hinged counterweight system, but with the counterweight hanger positioned at the top of the throwing arm. When cocked, the arm points forward in the direction of the throw. At the start, the weight and projectile ‘rest’ on the trebuchet arm.
- _abc_impl = <_abc._abc_data object>
- __init__(arm: Arm, weight: Weight, pivot: Pivot, projectile: Projectile, sling_projectile: Sling, sling_weight: Sling, release_angle: float, arm_angle: float = 1.0471975511965976, weight_angle: float = 0.17453292519943295) None
Initialize a WhipperTrebuchet instance with the given parameters.
- Parameters:
arm – Arm instance
weight – Weight instance
pivot – Pivot instance
projectile – Projectile instance
sling_projectile – Sling instance for the projectile
sling_weight – Sling instance for the weight
release_angle – angle at which the projectile is released (radians)
arm_angle – initial angle of the arm as measured from the horizontal (radians).
weight_angle – initial angle of the weight sling as measured from the arm (radians).
- _initialize_angles() None
Calculate the initial angles of the trebuchet.
- Calculate:
-angle_arm based on the specified arm_angle parameter. -angle_projectile such that the projectile rests on the arm. -angle_weight based on the specified weight_angle parameter.
- classmethod default() WhipperTrebuchet
Create a whipper Trebuchet instance with default parameters.