dbookstaber / py_ballistics

Point-mass ballistic trajectory calculator with support for custom drag models
GNU Lesser General Public License v3.0
3 stars 0 forks source link

Refactoring #7

Closed dbookstaber closed 9 months ago

dbookstaber commented 11 months ago

New paradigm:

Here's an example showing how we get this "firing solution" from the existing paradigm:

# Establish 500-meter zero at 0 degree horizontal look
weapon = Weapon(9, 500, 15)
calc = Calculator(weapon, ammo)
zero_elevation = calc.elevation
print(f'Barrel elevation for zero: {zero_elevation << Unit.MIL}')
# We spot a target and sight reports the following "look angle" and "look distance" to the target:
target_elevation = Unit.DEGREE(30)
target_distance = 500
# Solve for barrel elevation to hit that target:
weapon = Weapon(9, target_distance, 15, target_elevation)
calc = Calculator(weapon, ammo)
barrel_elevation = calc.elevation
# Solve for sight adjustment from zero to hit new target:
barrel_minus_sight_mils = (barrel_elevation >> Angular.Mil) - (target_elevation >> Angular.Mil)
fire_solution_mils = barrel_minus_sight_mils - (zero_elevation >> Angular.Mil)
print(f'Barrel elevation to hit target at {target_elevation << Unit.DEGREE}, {target_distance}m: {barrel_elevation << Unit.MIL}')
print(f'Difference between sight line and barrel elevation is now {barrel_minus_sight_mils:.2f}MIL')
print(f'Sight adjustment to hit target is {fire_solution_mils:.2f}MIL')
dbookstaber commented 10 months ago

Also: It doesn't make sense to bind anything to the Calculator interface object. Weapon, Ammo, and Atmo are properties of a Shot. Therefore:

  1. Remove from Calculator the properties weapon, ammo, zero_atmo
dbookstaber commented 9 months ago

Done now in refactor_angles branch: 36e7f84264e3c5bf46f4bb3a791a78d3abe0845f