TrajectoryData
TrajFlag
¶
Bases: int
Trajectory point classification flags for marking special trajectory events.
Provides enumeration values for identifying and filtering special points in ballistic trajectories. The flags can be combined using bitwise operations.
Flag Values
- NONE (0): Standard trajectory point with no special events
- ZERO_UP (1): Upward zero crossing (trajectory rising through sight line)
- ZERO_DOWN (2): Downward zero crossing (trajectory falling through sight line)
- ZERO (3): Any zero crossing (ZERO_UP | ZERO_DOWN)
- MACH (4): Mach 1 transition point (sound barrier crossing)
- RANGE (8): User requested point, typically by distance or time step
- APEX (16): Trajectory apex (maximum height point)
- ALL (31): All special points (combination of all above flags)
- MRT (32): Mid-Range Trajectory/Maximum Ordinate (largest slant height) [PROPOSED]
Examples:
Basic flag usage:
from py_ballisticcalc.trajectory_data import TrajFlag
# Filter for zero crossings only
flags = TrajFlag.ZERO
# Filter for multiple event types
flags = TrajFlag.ZERO | TrajFlag.APEX | TrajFlag.MACH
# Filter for all special points
flags = TrajFlag.ALL
# Check if a trajectory point has specific flags
if point.flag & TrajFlag.APEX:
print("Trajectory apex")
Trajectory calculation with flags:
# Calculate trajectory with zero crossings and apex
hit_result = calc.fire(shot, 1000, filter_flags=TrajFlag.ZERO | TrajFlag.APEX)
# Find all zero crossing points
zeros = [p for p in hit_result.trajectory if p.flag & TrajFlag.ZERO]
# Find apex point
apex = next((p for p in hit_result.trajectory if p.flag & TrajFlag.APEX), None)
Methods:
Name | Description |
---|---|
name |
Get the human-readable name for a trajectory flag value. |
Functions¶
name
staticmethod
¶
Get the human-readable name for a trajectory flag value.
Converts a numeric flag value to its corresponding string name for display, logging, or debugging purposes. Supports both individual flags and combined flag values with intelligent formatting.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
value
|
Union[int, TrajFlag]
|
The TrajFlag enum value or integer flag to convert. |
required |
Returns:
Type | Description |
---|---|
str
|
String name of the flag. For combined flags, returns names joined with "|". For unknown flags, returns "UNKNOWN". Special handling for ZERO flag combinations. |
Examples:
# Individual flag names
print(TrajFlag.name(TrajFlag.ZERO)) # "ZERO"
print(TrajFlag.name(TrajFlag.APEX)) # "APEX"
# Combined flags
combined = TrajFlag.ZERO | TrajFlag.APEX
print(TrajFlag.name(combined)) # "ZERO|APEX"
# Unknown flags
print(TrajFlag.name(999)) # "UNKNOWN"
Source code in py_ballisticcalc/trajectory_data.py
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
BaseTrajData
¶
Bases: NamedTuple
Minimal ballistic trajectory point data.
Represents the minimum state information for a single point in a ballistic trajectory. The data are kept in basic units (seconds, feet) to avoid unit tracking and conversion overhead.
Attributes:
Name | Type | Description |
---|---|---|
time |
float
|
Time since projectile launch in seconds. |
position |
Vector
|
3D position vector in feet (x=downrange, y=height, z=windage). |
velocity |
Vector
|
3D velocity vector in feet per second. |
mach |
float
|
Local speed of sound in feet per second. |
Examples:
from py_ballisticcalc.vector import Vector
# Create trajectory point at launch
launch_pt = BaseTrajData(
time=0.0,
position=Vector(0.0, -0.1, 0.0), # 0.1 ft scope height
velocity=Vector(2640.0, 0.0, 0.0), # 800 m/s ≈ 2640 fps
mach=1115.5 # Standard conditions
)
# Interpolate between points
interpolated = BaseTrajData.interpolate('time', 1.25, launch_pt, mid_pt, end_pt)
Note
This class is designed for efficiency in calculation engines that may compute thousands of points over a trajectory. For detailed data with units and derived quantities, use TrajectoryData which can be constructed from BaseTrajData using from_base_data().
Methods:
Name | Description |
---|---|
interpolate |
Interpolate a BaseTrajData point using monotone PCHIP (default) or linear. |
Functions¶
interpolate
staticmethod
¶
interpolate(
key_attribute: str,
key_value: float,
p0: BaseTrajData,
p1: BaseTrajData,
p2: BaseTrajData,
method: InterpolationMethod = "pchip",
) -> BaseTrajData
Interpolate a BaseTrajData point using monotone PCHIP (default) or linear.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_attribute
|
str
|
Can be 'time', 'mach', or a vector component like 'position.x' or 'velocity.z'. |
required |
key_value
|
float
|
The value to interpolate for. |
required |
p0
|
BaseTrajData
|
First bracketing point. |
required |
p1
|
BaseTrajData
|
Second (middle) bracketing point. |
required |
p2
|
BaseTrajData
|
Third bracketing point. |
required |
method
|
InterpolationMethod
|
'pchip' (default, monotone cubic Hermite) or 'linear'. |
'pchip'
|
Returns:
Type | Description |
---|---|
BaseTrajData
|
The interpolated data point. |
Raises:
Type | Description |
---|---|
AttributeError
|
If the key_attribute is not a member of BaseTrajData. |
ZeroDivisionError
|
If the interpolation fails due to zero division. (This will result if two of the points are identical). |
ValueError
|
If method is not one of 'pchip' or 'linear'. |
Source code in py_ballisticcalc/trajectory_data.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 |
|
TrajectoryData
¶
Bases: NamedTuple
Data for one point in ballistic trajectory.
Attributes:
Name | Type | Description |
---|---|---|
time |
float
|
Flight time in seconds |
distance |
Distance
|
Down-range (x-axis) coordinate of this point |
velocity |
Velocity
|
Velocity vector at this point |
mach |
float
|
Velocity in Mach terms |
height |
Distance
|
Vertical (y-axis) coordinate of this point |
slant_height |
Distance
|
Distance orthogonal to sight-line |
drop_adj |
Angular
|
Sight adjustment to zero slant_height at this distance |
windage |
Distance
|
Windage (z-axis) coordinate of this point |
windage_adj |
Angular
|
Windage adjustment |
slant_distance |
Distance
|
Distance along sight line that is closest to this point |
angle |
Angular
|
Angle of velocity vector relative to x-axis |
density_ratio |
float
|
Ratio of air density here to standard density |
drag |
float
|
Standard Drag Factor at this point |
energy |
Energy
|
Energy of bullet at this point |
ogw |
Weight
|
Optimal game weight, given .energy |
flag |
Union[TrajFlag, int]
|
Row type (TrajFlag) |
Methods:
Name | Description |
---|---|
look_distance |
Synonym for slant_distance. |
formatted |
Return attributes as tuple of strings, formatted per PreferredUnits. |
in_def_units |
Return attributes as tuple of floats converting to PreferredUnits. |
get_correction |
Calculate the sight adjustment in radians. |
calculate_energy |
Calculate the kinetic energy of a projectile. |
calculate_ogw |
Calculate the optimal game weight for a projectile. |
from_base_data |
Create a TrajectoryData object from BaseTrajData. |
from_props |
Create a TrajectoryData object. |
interpolate |
Interpolate TrajectoryData where key_attribute==value using PCHIP (default) or linear. |
Attributes¶
Functions¶
look_distance
¶
look_distance() -> Distance
Synonym for slant_distance.
Source code in py_ballisticcalc/trajectory_data.py
357 358 359 360 |
|
formatted
¶
formatted() -> Tuple[str, ...]
Return attributes as tuple of strings, formatted per PreferredUnits.
Returns:
Type | Description |
---|---|
Tuple[str, ...]
|
Tuple of formatted strings for this point, in PreferredUnits. |
Source code in py_ballisticcalc/trajectory_data.py
368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 |
|
in_def_units
¶
in_def_units() -> Tuple[float, ...]
Return attributes as tuple of floats converting to PreferredUnits.
Returns:
Type | Description |
---|---|
Tuple[float, ...]
|
Tuple of floats describing this point, in PreferredUnits. |
Source code in py_ballisticcalc/trajectory_data.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 |
|
get_correction
staticmethod
¶
Calculate the sight adjustment in radians.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
distance
|
float
|
The distance to the target in feet. |
required |
offset
|
float
|
The offset from the target in feet. |
required |
Returns:
Type | Description |
---|---|
float
|
The sight adjustment in radians. |
Source code in py_ballisticcalc/trajectory_data.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 |
|
calculate_energy
staticmethod
¶
Calculate the kinetic energy of a projectile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bullet_weight
|
float
|
Projectile weight in grains. |
required |
velocity
|
float
|
Projectile velocity in feet per second. |
required |
Returns:
Type | Description |
---|---|
float
|
Kinetic energy in foot-pounds (ft·lbf). |
Notes
Uses the standard small-arms approximation: E(ft·lbf) = weight(grains) * v(fps)^2 / 450400.
Source code in py_ballisticcalc/trajectory_data.py
438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
|
calculate_ogw
staticmethod
¶
Calculate the optimal game weight for a projectile.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
bullet_weight
|
float
|
Bullet weight in grains (per common OGW formula). |
required |
velocity
|
float
|
Projectile velocity in feet per second. |
required |
Returns:
Type | Description |
---|---|
float
|
The optimal game weight in pounds. |
Source code in py_ballisticcalc/trajectory_data.py
455 456 457 458 459 460 461 462 463 464 465 466 |
|
from_base_data
staticmethod
¶
from_base_data(
props: ShotProps,
data: BaseTrajData,
flag: Union[TrajFlag, int] = NONE,
) -> TrajectoryData
Create a TrajectoryData object from BaseTrajData.
Source code in py_ballisticcalc/trajectory_data.py
503 504 505 506 507 |
|
from_props
staticmethod
¶
from_props(
props: ShotProps,
time: float,
range_vector: Vector,
velocity_vector: Vector,
mach: float,
flag: Union[TrajFlag, int] = NONE,
) -> TrajectoryData
Create a TrajectoryData object.
Source code in py_ballisticcalc/trajectory_data.py
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 |
|
interpolate
staticmethod
¶
interpolate(
key_attribute: TRAJECTORY_DATA_ATTRIBUTES,
value: Union[float, GenericDimension],
p0: TrajectoryData,
p1: TrajectoryData,
p2: TrajectoryData,
flag: Union[TrajFlag, int] = NONE,
method: InterpolationMethod = "pchip",
) -> TrajectoryData
Interpolate TrajectoryData where key_attribute==value using PCHIP (default) or linear.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
key_attribute
|
TRAJECTORY_DATA_ATTRIBUTES
|
Attribute to key on (e.g., 'time', 'distance'). |
required |
value
|
Union[float, GenericDimension]
|
Target value for the key attribute. A bare float is treated as raw value for dimensioned fields. |
required |
p0
|
TrajectoryData
|
First bracketing point. |
required |
p1
|
TrajectoryData
|
Second (middle) bracketing point. |
required |
p2
|
TrajectoryData
|
Third bracketing point. |
required |
flag
|
Union[TrajFlag, int]
|
Flag to assign to the new point. |
NONE
|
method
|
InterpolationMethod
|
'pchip' (monotone cubic Hermite) or 'linear'. |
'pchip'
|
Returns:
Type | Description |
---|---|
TrajectoryData
|
Interpolated point with key_attribute==value. |
Raises:
Type | Description |
---|---|
AttributeError
|
If TrajectoryData doesn't have the specified attribute. |
KeyError
|
If the key_attribute is 'flag'. |
ZeroDivisionError
|
If interpolation fails due to zero division. |
ValueError
|
If method is not one of 'pchip' or 'linear'. |
Source code in py_ballisticcalc/trajectory_data.py
546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
|