Skip to content

Weapon

Weapon dataclass

Weapon(
    sight_height: Optional[Union[float, Distance]] = None,
    twist: Optional[Union[float, Distance]] = None,
    zero_elevation: Optional[Union[float, Angular]] = None,
    sight: Optional[Sight] = None,
)

Weapon configuration for ballistic calculations.

This class represents the physical characteristics of a gun that affect trajectory calculations, including sight height, barrel twist rate, zero elevation, and optional sight system configuration.

Attributes:

Name Type Description
sight_height Distance

Vertical distance from line of sight to center of bore, measured at the muzzle perpendicular to the line of sight.

twist Distance

Distance for barrel rifling to complete one complete turn. Positive values indicate right-hand twist, negative for left-hand.

zero_elevation Angular

Angle of barrel centerline relative to line of sight when the sight is set to "zero" position.

sight Optional[Sight]

Optional Sight instance for advanced sight calculations.

Note

The sight height is critical for trajectory calculations as it determines the offset between the line of sight and the bullet's initial trajectory. Barrel twist affects spin drift calculations for long-range shots.

Example
weapon = Weapon(
    sight_height=Unit.Inch(2.5),
    twist=Unit.Inch(10),
    zero_elevation=Unit.Mil(0),
    sight=Sight('FFP', 100, Unit.Mil(0.2), Unit.Mil(0.2))
)

Parameters:

Name Type Description Default
sight_height Optional[Union[float, Distance]]

Vertical distance from line of sight to center of bore, measured at the muzzle. Defaults to 0 if not specified.

None
twist Optional[Union[float, Distance]]

Distance for barrel rifling to complete one complete turn. Positive value for right-hand twist, negative for left-hand. Defaults to 0 if not specified.

None
zero_elevation Optional[Union[float, Angular]]

Angle of barrel relative to sight line when sight is set to "zero." Typically computed by Calculator.set_weapon_zero(). Defaults to 0 if not specified.

None
sight Optional[Sight]

Optional Sight properties for advanced sight calculations.

None
Example
from py_ballisticcalc import Weapon, Unit, Sight

# Basic weapon configuration
weapon = Weapon(
    sight_height=Unit.Inch(2.5),
    twist=Unit.Inch(10)
)

# Advanced weapon with sight system
weapon = Weapon(
    sight_height=Unit.Inch(2.5),
    twist=Unit.Inch(10),
    zero_elevation=Unit.Mil(0),
    sight=Sight(
        'FFP', 
        scale_factor=Unit.Meter(100),
        h_click_size=Unit.Mil(0.2),
        v_click_size=Unit.Mil(0.2)
    )
)
Source code in py_ballisticcalc/munition.py
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
def __init__(self,
             sight_height: Optional[Union[float, Distance]] = None,
             twist: Optional[Union[float, Distance]] = None,
             zero_elevation: Optional[Union[float, Angular]] = None,
             sight: Optional[Sight] = None):
    """Initialize a Weapon instance with given parameters.

    Args:
        sight_height: Vertical distance from line of sight to center of bore,
                     measured at the muzzle. Defaults to 0 if not specified.
        twist: Distance for barrel rifling to complete one complete turn.
              Positive value for right-hand twist, negative for left-hand.
              Defaults to 0 if not specified.
        zero_elevation: Angle of barrel relative to sight line when sight
                       is set to "zero." Typically computed by Calculator.set_weapon_zero().
                       Defaults to 0 if not specified.
        sight: Optional Sight properties for advanced sight calculations.

    Example:
        ```python
        from py_ballisticcalc import Weapon, Unit, Sight

        # Basic weapon configuration
        weapon = Weapon(
            sight_height=Unit.Inch(2.5),
            twist=Unit.Inch(10)
        )

        # Advanced weapon with sight system
        weapon = Weapon(
            sight_height=Unit.Inch(2.5),
            twist=Unit.Inch(10),
            zero_elevation=Unit.Mil(0),
            sight=Sight(
                'FFP', 
                scale_factor=Unit.Meter(100),
                h_click_size=Unit.Mil(0.2),
                v_click_size=Unit.Mil(0.2)
            )
        )
        ```
    """
    self.sight_height = PreferredUnits.sight_height(sight_height or 0)
    self.twist = PreferredUnits.twist(twist or 0)
    self.zero_elevation = PreferredUnits.angular(zero_elevation or 0)
    self.sight = sight

sight_height instance-attribute

sight_height: Distance = sight_height(sight_height or 0)

twist instance-attribute

twist: Distance = twist(twist or 0)

zero_elevation instance-attribute

zero_elevation: Angular = angular(zero_elevation or 0)

sight instance-attribute

sight: Optional[Sight] = sight