From 499fba9c8b079fd702b4a132afb4fc42ef986068 Mon Sep 17 00:00:00 2001 From: gambon0120 Date: Sun, 18 Aug 2024 18:41:06 +0200 Subject: [PATCH 1/4] changed name of drop_adj, windage_adj and height --- py_ballisticcalc/munition.py | 18 +++++++++--------- py_ballisticcalc/trajectory_calc.py | 8 ++++---- py_ballisticcalc/trajectory_data.py | 16 ++++++++-------- tests/test_trajectory.py | 4 ++-- 4 files changed, 23 insertions(+), 23 deletions(-) diff --git a/py_ballisticcalc/munition.py b/py_ballisticcalc/munition.py index 32f672e..97d4a80 100644 --- a/py_ballisticcalc/munition.py +++ b/py_ballisticcalc/munition.py @@ -86,26 +86,26 @@ def get_sfp_step(click_size: Union[Angular, AbstractUnitType]): return Sight.ReticleStep(_v_step, _v_step) def get_adjustment(self, target_distance: Distance, - drop_adj: Angular, windage_adj: Angular, + drop_angle: Angular, windage_angle: Angular, magnification: float): """Calculate adjustment for target distance and magnification""" if self.focal_plane == Sight.FocalPlane.SFP: steps = self._adjust_sfp_reticle_steps(target_distance, magnification) return Sight.Clicks( - drop_adj.raw_value / steps.vertical.raw_value, - windage_adj.raw_value / steps.horizontal.raw_value + drop_angle.raw_value / steps.vertical.raw_value, + windage_angle.raw_value / steps.horizontal.raw_value ) if self.focal_plane == Sight.FocalPlane.FFP: return Sight.Clicks( - drop_adj.raw_value / self.v_click_size.raw_value, - windage_adj.raw_value / self.h_click_size.raw_value + drop_angle.raw_value / self.v_click_size.raw_value, + windage_angle.raw_value / self.h_click_size.raw_value ) if self.focal_plane == Sight.FocalPlane.LWIR: # adjust clicks to magnification return Sight.Clicks( - drop_adj.raw_value / (self.v_click_size.raw_value / magnification), - windage_adj.raw_value / (self.h_click_size.raw_value / magnification) + drop_angle.raw_value / (self.v_click_size.raw_value / magnification), + windage_angle.raw_value / (self.h_click_size.raw_value / magnification) ) raise AttributeError("Wrong focal_plane") @@ -113,8 +113,8 @@ def get_trajectory_adjustment(self, trajectory_point: 'TrajectoryData', magnific """Calculate adjustment for target distance and magnification for `TrajectoryData` instance""" return self.get_adjustment(trajectory_point.distance, - trajectory_point.drop_adj, - trajectory_point.windage_adj, + trajectory_point.drop_angle, + trajectory_point.windage_angle, magnification) diff --git a/py_ballisticcalc/trajectory_calc.py b/py_ballisticcalc/trajectory_calc.py index 11462c1..2b0d5e5 100644 --- a/py_ballisticcalc/trajectory_calc.py +++ b/py_ballisticcalc/trajectory_calc.py @@ -437,8 +437,8 @@ def create_trajectory_row(time: float, range_vector: Vector, velocity_vector: Ve :return: A TrajectoryData object representing the trajectory data. """ windage = range_vector.z + spin_drift - drop_adjustment = get_correction(range_vector.x, range_vector.y) - windage_adjustment = get_correction(range_vector.x, windage) + drop_angle = get_correction(range_vector.x, range_vector.y) + windage_angle = get_correction(range_vector.x, windage) trajectory_angle = math.atan(velocity_vector.y / velocity_vector.x) return TrajectoryData( @@ -448,9 +448,9 @@ def create_trajectory_row(time: float, range_vector: Vector, velocity_vector: Ve mach=velocity / mach, height=Distance.Foot(range_vector.y), target_drop=Distance.Foot((range_vector.y - range_vector.x * math.tan(look_angle)) * math.cos(look_angle)), - drop_adj=Angular.Radian(drop_adjustment - (look_angle if range_vector.x else 0)), + drop_angle=Angular.Radian(drop_angle - (look_angle if range_vector.x else 0)), windage=Distance.Foot(windage), - windage_adj=Angular.Radian(windage_adjustment), + windage_angle=Angular.Radian(windage_angle), look_distance=Distance.Foot(range_vector.x / math.cos(look_angle)), angle=Angular.Radian(trajectory_angle), density_factor=density_factor - 1, diff --git a/py_ballisticcalc/trajectory_data.py b/py_ballisticcalc/trajectory_data.py index b5273a6..daa3302 100644 --- a/py_ballisticcalc/trajectory_data.py +++ b/py_ballisticcalc/trajectory_data.py @@ -58,9 +58,9 @@ class TrajectoryData(NamedTuple): mach (float): velocity in Mach prefer_units height (Distance): y-axis coordinate target_drop (Distance): drop relative to sight-line - drop_adj (Angular): sight adjustment to zero target_drop at this distance + drop_angle (Angular): sight adjustment to zero target_drop at this distance windage (Distance): - windage_adj (Angular): + windage_angle (Angular): look_distance (Distance): sight-line distance = .distance/cosine(look_angle) # look_height (Distance): y-coordinate of sight-line = .distance*tan(look_angle) angle (Angular): Angle of velocity vector relative to x-axis @@ -77,9 +77,9 @@ class TrajectoryData(NamedTuple): mach: float height: Distance target_drop: Distance - drop_adj: Angular + drop_angle: Angular windage: Distance - windage_adj: Angular + windage_angle: Angular look_distance: Distance angle: Angular density_factor: float @@ -104,9 +104,9 @@ def _fmt(v: AbstractUnit, u: Unit): f'{self.mach:.2f} mach', _fmt(self.height, PreferredUnits.drop), _fmt(self.target_drop, PreferredUnits.drop), - _fmt(self.drop_adj, PreferredUnits.adjustment), + _fmt(self.drop_angle, PreferredUnits.adjustment), _fmt(self.windage, PreferredUnits.drop), - _fmt(self.windage_adj, PreferredUnits.adjustment), + _fmt(self.windage_angle, PreferredUnits.adjustment), _fmt(self.look_distance, PreferredUnits.distance), _fmt(self.angle, PreferredUnits.angular), f'{self.density_factor:.3e}', @@ -128,9 +128,9 @@ def in_def_units(self) -> tuple: self.mach, self.height >> PreferredUnits.drop, self.target_drop >> PreferredUnits.drop, - self.drop_adj >> PreferredUnits.adjustment, + self.drop_angle >> PreferredUnits.adjustment, self.windage >> PreferredUnits.drop, - self.windage_adj >> PreferredUnits.adjustment, + self.windage_angle >> PreferredUnits.adjustment, self.look_distance >> PreferredUnits.distance, self.angle >> PreferredUnits.angular, self.density_factor, diff --git a/tests/test_trajectory.py b/tests/test_trajectory.py index ed12d38..42cf0db 100644 --- a/tests/test_trajectory.py +++ b/tests/test_trajectory.py @@ -55,7 +55,7 @@ def validate_one(self, data: TrajectoryData, distance: float, velocity: float, self.custom_assert_equal(path, data.height >> Distance.Inch, 0.5, 'Drop') if distance > 1: - self.custom_assert_equal(hold, data.drop_adj >> adjustment_unit, 0.5, 'Hold') + self.custom_assert_equal(hold, data.drop_angle >> adjustment_unit, 0.5, 'Hold') if distance >= 800: self.custom_assert_equal(windage, data.windage >> Distance.Inch, 1.5, "Windage") @@ -66,7 +66,7 @@ def validate_one(self, data: TrajectoryData, distance: float, velocity: float, if distance > 1: self.custom_assert_equal(wind_adjustment, - data.windage_adj >> adjustment_unit, 0.5, "WAdj") + data.windage_angle >> adjustment_unit, 0.5, "WAdj") def test_path_g1(self): dm = DragModel(0.223, TableG1, 168, 0.308, 1.282) From 4ac980043d16f9ba9d9f1aab8cdd5a75ce981096 Mon Sep 17 00:00:00 2001 From: gambon0120 Date: Sun, 18 Aug 2024 18:43:01 +0200 Subject: [PATCH 2/4] added forgotten files --- py_ballisticcalc/trajectory_calc.py | 4 ++-- py_ballisticcalc/trajectory_data.py | 24 ++++++++++++------------ tests/test_computer.py | 28 ++++++++++++++-------------- tests/test_trajectory.py | 6 +++--- 4 files changed, 31 insertions(+), 31 deletions(-) diff --git a/py_ballisticcalc/trajectory_calc.py b/py_ballisticcalc/trajectory_calc.py index 2b0d5e5..8455d7b 100644 --- a/py_ballisticcalc/trajectory_calc.py +++ b/py_ballisticcalc/trajectory_calc.py @@ -207,7 +207,7 @@ def zero_angle(self, shot_info: Shot, distance: Distance) -> Angular: while zero_finding_error > cZeroFindingAccuracy and iterations_count < cMaxIterations: # Check height of trajectory at the zero distance (using current self.barrel_elevation) t = self._trajectory(shot_info, maximum_range, zero_distance, TrajFlag.NONE)[0] - height = t.height >> Distance.Foot + height = t.y >> Distance.Foot zero_finding_error = math.fabs(height - height_at_zero) if zero_finding_error > cZeroFindingAccuracy: # Adjust barrel elevation to close height at zero distance @@ -446,7 +446,7 @@ def create_trajectory_row(time: float, range_vector: Vector, velocity_vector: Ve distance=Distance.Foot(range_vector.x), velocity=Velocity.FPS(velocity), mach=velocity / mach, - height=Distance.Foot(range_vector.y), + y=Distance.Foot(range_vector.y), target_drop=Distance.Foot((range_vector.y - range_vector.x * math.tan(look_angle)) * math.cos(look_angle)), drop_angle=Angular.Radian(drop_angle - (look_angle if range_vector.x else 0)), windage=Distance.Foot(windage), diff --git a/py_ballisticcalc/trajectory_data.py b/py_ballisticcalc/trajectory_data.py index daa3302..cce1487 100644 --- a/py_ballisticcalc/trajectory_data.py +++ b/py_ballisticcalc/trajectory_data.py @@ -56,7 +56,7 @@ class TrajectoryData(NamedTuple): distance (Distance): x-axis coordinate velocity (Velocity): velocity mach (float): velocity in Mach prefer_units - height (Distance): y-axis coordinate + y (Distance): y-axis coordinate target_drop (Distance): drop relative to sight-line drop_angle (Angular): sight adjustment to zero target_drop at this distance windage (Distance): @@ -75,7 +75,7 @@ class TrajectoryData(NamedTuple): distance: Distance velocity: Velocity mach: float - height: Distance + y: Distance target_drop: Distance drop_angle: Angular windage: Distance @@ -102,7 +102,7 @@ def _fmt(v: AbstractUnit, u: Unit): _fmt(self.distance, PreferredUnits.distance), _fmt(self.velocity, PreferredUnits.velocity), f'{self.mach:.2f} mach', - _fmt(self.height, PreferredUnits.drop), + _fmt(self.y, PreferredUnits.drop), _fmt(self.target_drop, PreferredUnits.drop), _fmt(self.drop_angle, PreferredUnits.adjustment), _fmt(self.windage, PreferredUnits.drop), @@ -126,7 +126,7 @@ def in_def_units(self) -> tuple: self.distance >> PreferredUnits.distance, self.velocity >> PreferredUnits.velocity, self.mach, - self.height >> PreferredUnits.drop, + self.y >> PreferredUnits.drop, self.target_drop >> PreferredUnits.drop, self.drop_angle >> PreferredUnits.adjustment, self.windage >> PreferredUnits.drop, @@ -163,11 +163,11 @@ def overlay(self, ax: 'Axes', label: Optional[str] = None): # type: ignore cosine = math.cos(self.look_angle >> Angular.Radian) begin_dist = (self.begin.distance >> PreferredUnits.distance) * cosine - begin_drop = (self.begin.height >> PreferredUnits.drop) * cosine + begin_drop = (self.begin.y >> PreferredUnits.drop) * cosine end_dist = (self.end.distance >> PreferredUnits.distance) * cosine - end_drop = (self.end.height >> PreferredUnits.drop) * cosine + end_drop = (self.end.y >> PreferredUnits.drop) * cosine range_dist = (self.at_range.distance >> PreferredUnits.distance) * cosine - range_drop = (self.at_range.height >> PreferredUnits.drop) * cosine + range_drop = (self.at_range.y >> PreferredUnits.drop) * cosine h = self.target_height >> PreferredUnits.drop # Target position and height: @@ -326,20 +326,20 @@ def plot(self, look_angle: Optional[Angular] = None) -> 'Axes': # type: ignore "Use Calculator.fire(..., extra_data=True)") font_size = PLOT_FONT_SIZE df = self.dataframe() - ax = df.plot(x='distance', y=['height'], ylabel=PreferredUnits.drop.symbol) + ax = df.plot(x='distance', y=['y'], ylabel=PreferredUnits.drop.symbol) max_range = self.trajectory[-1].distance >> PreferredUnits.distance for p in self.trajectory: if TrajFlag(p.flag) & TrajFlag.ZERO: ax.plot([p.distance >> PreferredUnits.distance, p.distance >> PreferredUnits.distance], - [df['height'].min(), p.height >> PreferredUnits.drop], linestyle=':') - ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['height'].min(), + [df['y'].min(), p.y >> PreferredUnits.drop], linestyle=':') + ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['y'].min(), f"{(TrajFlag(p.flag) & TrajFlag.ZERO).name}", fontsize=font_size, rotation=90) if TrajFlag(p.flag) & TrajFlag.MACH: ax.plot([p.distance >> PreferredUnits.distance, p.distance >> PreferredUnits.distance], - [df['height'].min(), p.height >> PreferredUnits.drop], linestyle=':') - ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['height'].min(), + [df['y'].min(), p.y >> PreferredUnits.drop], linestyle=':') + ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['y'].min(), "Mach 1", fontsize=font_size, rotation=90) max_range_in_drop_units = self.trajectory[-1].distance >> PreferredUnits.drop diff --git a/tests/test_computer.py b/tests/test_computer.py index c35ef3d..1847965 100644 --- a/tests/test_computer.py +++ b/tests/test_computer.py @@ -33,8 +33,8 @@ def test_cant_zero_elevation(self): canted = copy.copy(self.baseline_shot) canted.cant_angle = Angular.Degree(90) t = self.calc.fire(canted, trajectory_range=self.range, trajectory_step=self.step) - self.assertAlmostEqual(t.trajectory[5].height.raw_value - self.weapon.sight_height.raw_value, - self.baseline_trajectory[5].height.raw_value) + self.assertAlmostEqual(t.trajectory[5].y.raw_value - self.weapon.sight_height.raw_value, + self.baseline_trajectory[5].y.raw_value) self.assertAlmostEqual(t.trajectory[5].windage.raw_value + self.weapon.sight_height.raw_value, self.baseline_trajectory[5].windage.raw_value) @@ -45,8 +45,8 @@ def test_cant_positive_elevation(self): canted = Shot(weapon=Weapon(sight_height=self.weapon.sight_height, twist=0, zero_elevation=Angular.Mil(2)), ammo=self.ammo, atmo=self.atmosphere, cant_angle=Angular.Degree(90)) t = self.calc.fire(canted, trajectory_range=self.range, trajectory_step=self.step) - self.assertAlmostEqual(t.trajectory[5].height.raw_value - self.weapon.sight_height.raw_value, - self.baseline_trajectory[5].height.raw_value, 2) + self.assertAlmostEqual(t.trajectory[5].y.raw_value - self.weapon.sight_height.raw_value, + self.baseline_trajectory[5].y.raw_value, 2) self.assertAlmostEqual(t.trajectory[0].windage.raw_value, -self.weapon.sight_height.raw_value) self.assertGreater(t.trajectory[5].windage.raw_value, t.trajectory[3].windage.raw_value) @@ -57,8 +57,8 @@ def test_cant_zero_sight_height(self): canted = Shot(weapon=Weapon(sight_height=0, twist=self.weapon.twist), ammo=self.ammo, atmo=self.atmosphere, cant_angle=Angular.Degree(90)) t = self.calc.fire(canted, trajectory_range=self.range, trajectory_step=self.step) - self.assertAlmostEqual(t.trajectory[5].height.raw_value - self.weapon.sight_height.raw_value, - self.baseline_trajectory[5].height.raw_value) + self.assertAlmostEqual(t.trajectory[5].y.raw_value - self.weapon.sight_height.raw_value, + self.baseline_trajectory[5].y.raw_value) self.assertAlmostEqual(t.trajectory[5].windage, self.baseline_trajectory[5].windage) # endregion Cant_angle @@ -83,14 +83,14 @@ def test_wind_from_back(self): shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=self.atmosphere, winds=[Wind(Velocity(5, Velocity.MPH), Angular(0, Angular.OClock))]) t = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_wind_from_front(self): """Wind from in front should increase drop""" shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=self.atmosphere, winds=[Wind(Velocity(5, Velocity.MPH), Angular(6, Angular.OClock))]) t = self.calc.fire(shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertLess(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertLess(t.trajectory[5].y, self.baseline_trajectory[5].y) # endregion Wind @@ -123,28 +123,28 @@ def test_humidity(self): humid = Atmo(humidity=.9) # 90% humidity shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=humid) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_temp_atmo(self): """Dropping temperature should increase drop (due to increasing density)""" cold = Atmo(temperature=Temperature.Celsius(0)) shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=cold) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertLess(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertLess(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_altitude(self): """Increasing altitude should decrease drop (due to decreasing density)""" high = Atmo.icao(Distance.Foot(5000)) shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=high) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_pressure(self): """Decreasing pressure should decrease drop (due to decreasing density)""" thin = Atmo(pressure=Pressure.InHg(20.0)) shot = Shot(weapon=self.weapon, ammo=self.ammo, atmo=thin) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) # endregion Atmo @@ -155,7 +155,7 @@ def test_ammo_drag(self): slick = Ammo(tdm, self.ammo.mv) shot = Shot(weapon=self.weapon, ammo=slick, atmo=self.atmosphere) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertGreater(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertGreater(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_ammo_optional(self): """DragModel.weight and .diameter, and Ammo.length, are only relevant when computing @@ -165,7 +165,7 @@ def test_ammo_optional(self): tammo = Ammo(tdm, mv=self.ammo.mv) shot = Shot(weapon=self.weapon, ammo=tammo, atmo=self.atmosphere) t = self.calc.fire(shot=shot, trajectory_range=self.range, trajectory_step=self.step) - self.assertEqual(t.trajectory[5].height, self.baseline_trajectory[5].height) + self.assertEqual(t.trajectory[5].y, self.baseline_trajectory[5].y) def test_powder_sensitivity(self): """With _globalUsePowderSensitivity: Reducing temperature should reduce muzzle velocity""" diff --git a/tests/test_trajectory.py b/tests/test_trajectory.py index 42cf0db..a851b19 100644 --- a/tests/test_trajectory.py +++ b/tests/test_trajectory.py @@ -48,11 +48,11 @@ def validate_one(self, data: TrajectoryData, distance: float, velocity: float, self.custom_assert_equal(ogv, data.ogw >> Weight.Pound, 1, "OGV") if distance >= 800: - self.custom_assert_equal(path, data.height >> Distance.Inch, 4, 'Drop') + self.custom_assert_equal(path, data.y >> Distance.Inch, 4, 'Drop') elif distance >= 500: - self.custom_assert_equal(path, data.height >> Distance.Inch, 1, 'Drop') + self.custom_assert_equal(path, data.y >> Distance.Inch, 1, 'Drop') else: - self.custom_assert_equal(path, data.height >> Distance.Inch, 0.5, 'Drop') + self.custom_assert_equal(path, data.y >> Distance.Inch, 0.5, 'Drop') if distance > 1: self.custom_assert_equal(hold, data.drop_angle >> adjustment_unit, 0.5, 'Hold') From f20fa90bdc294bc2644b34924702b40ff261438a Mon Sep 17 00:00:00 2001 From: gambon0120 Date: Sun, 18 Aug 2024 19:56:45 +0200 Subject: [PATCH 3/4] changed distance and look distance --- examples/kanik_50bmg_aid_shooting.py | 25 +++++++------- py_ballisticcalc/munition.py | 2 +- py_ballisticcalc/trajectory_calc.py | 4 +-- py_ballisticcalc/trajectory_data.py | 50 ++++++++++++++-------------- tests/test_danger_space.py | 8 ++--- tests/test_trajectory.py | 2 +- 6 files changed, 45 insertions(+), 46 deletions(-) diff --git a/examples/kanik_50bmg_aid_shooting.py b/examples/kanik_50bmg_aid_shooting.py index 52306d4..80232bc 100644 --- a/examples/kanik_50bmg_aid_shooting.py +++ b/examples/kanik_50bmg_aid_shooting.py @@ -50,25 +50,24 @@ def calculate_lead_angle(target_speed, target_size, bullet_speed, initial_distance, time_of_flight): """ - Розрахунок кута упередження маючи швидкість і розмір цілі, швидкість кулі, початкову відстань до цілі. - - :param target_speed: Швидкість цілі (м/с) - :param target_size: Довжина цілі (м) - :param bullet_speed: Швидкість кулі (м/с) - :param initial_distance: Початкова відстань до цілі (м) - :return: Кут упередження в градусах + Calculation of the lead angle given the target speed and size, bullet speed, and initial distance to the target. + + :param target_speed: Target speed (m/s) + :param target_size: Target length (m) + :param bullet_speed: Bullet speed (m/s) + :param initial_distance: Initial distance to the target (m) + :param time_of_flight: Time of flight (s) + :return: Lead angle in degrees """ # Час польоту кулі # time_of_flight = initial_distance / bullet_speed - # Відстань, яку пройде ніс цілі - # distance_nose_travel = target_speed * time_of_flight + target_size - distance_nose_travel = target_speed * time_of_flight + target_size - - # Обчислення кута упередження + # Distance the target's nose will travel + distance_nose_travel = target_speed * time_of_flight + target_size + lead_angle = math.atan(distance_nose_travel / initial_distance) - # Перетворення кута в градуси + # Converting the angle to degrees lead_angle_degrees = math.degrees(lead_angle) return lead_angle_degrees diff --git a/py_ballisticcalc/munition.py b/py_ballisticcalc/munition.py index 97d4a80..8a888d2 100644 --- a/py_ballisticcalc/munition.py +++ b/py_ballisticcalc/munition.py @@ -112,7 +112,7 @@ def get_adjustment(self, target_distance: Distance, def get_trajectory_adjustment(self, trajectory_point: 'TrajectoryData', magnification: float) -> Clicks: """Calculate adjustment for target distance and magnification for `TrajectoryData` instance""" - return self.get_adjustment(trajectory_point.distance, + return self.get_adjustment(trajectory_point.x, trajectory_point.drop_angle, trajectory_point.windage_angle, magnification) diff --git a/py_ballisticcalc/trajectory_calc.py b/py_ballisticcalc/trajectory_calc.py index 8455d7b..0816f07 100644 --- a/py_ballisticcalc/trajectory_calc.py +++ b/py_ballisticcalc/trajectory_calc.py @@ -443,7 +443,7 @@ def create_trajectory_row(time: float, range_vector: Vector, velocity_vector: Ve return TrajectoryData( time=time, - distance=Distance.Foot(range_vector.x), + x=Distance.Foot(range_vector.x), velocity=Velocity.FPS(velocity), mach=velocity / mach, y=Distance.Foot(range_vector.y), @@ -451,7 +451,7 @@ def create_trajectory_row(time: float, range_vector: Vector, velocity_vector: Ve drop_angle=Angular.Radian(drop_angle - (look_angle if range_vector.x else 0)), windage=Distance.Foot(windage), windage_angle=Angular.Radian(windage_angle), - look_distance=Distance.Foot(range_vector.x / math.cos(look_angle)), + distance=Distance.Foot(range_vector.x / math.cos(look_angle)), angle=Angular.Radian(trajectory_angle), density_factor=density_factor - 1, drag=drag, diff --git a/py_ballisticcalc/trajectory_data.py b/py_ballisticcalc/trajectory_data.py index cce1487..7ebc856 100644 --- a/py_ballisticcalc/trajectory_data.py +++ b/py_ballisticcalc/trajectory_data.py @@ -53,7 +53,7 @@ class TrajectoryData(NamedTuple): Attributes: time (float): bullet flight time - distance (Distance): x-axis coordinate + x (Distance): x-axis coordinate velocity (Velocity): velocity mach (float): velocity in Mach prefer_units y (Distance): y-axis coordinate @@ -61,8 +61,8 @@ class TrajectoryData(NamedTuple): drop_angle (Angular): sight adjustment to zero target_drop at this distance windage (Distance): windage_angle (Angular): - look_distance (Distance): sight-line distance = .distance/cosine(look_angle) - # look_height (Distance): y-coordinate of sight-line = .distance*tan(look_angle) + distance (Distance): sight-line distance = .x/cosine(look_angle) + # look_height (Distance): y-coordinate of sight-line = .x*tan(look_angle) angle (Angular): Angle of velocity vector relative to x-axis density_factor (float): Ratio of air density here to standard density drag (float): Current drag coefficient @@ -72,7 +72,7 @@ class TrajectoryData(NamedTuple): """ time: float - distance: Distance + x: Distance velocity: Velocity mach: float y: Distance @@ -80,7 +80,7 @@ class TrajectoryData(NamedTuple): drop_angle: Angular windage: Distance windage_angle: Angular - look_distance: Distance + distance: Distance angle: Angular density_factor: float drag: float @@ -99,7 +99,7 @@ def _fmt(v: AbstractUnit, u: Unit): return ( f'{self.time:.3f} s', - _fmt(self.distance, PreferredUnits.distance), + _fmt(self.x, PreferredUnits.distance), _fmt(self.velocity, PreferredUnits.velocity), f'{self.mach:.2f} mach', _fmt(self.y, PreferredUnits.drop), @@ -107,7 +107,7 @@ def _fmt(v: AbstractUnit, u: Unit): _fmt(self.drop_angle, PreferredUnits.adjustment), _fmt(self.windage, PreferredUnits.drop), _fmt(self.windage_angle, PreferredUnits.adjustment), - _fmt(self.look_distance, PreferredUnits.distance), + _fmt(self.distance, PreferredUnits.distance), _fmt(self.angle, PreferredUnits.angular), f'{self.density_factor:.3e}', f'{self.drag:.3f}', @@ -123,7 +123,7 @@ def in_def_units(self) -> tuple: """ return ( self.time, - self.distance >> PreferredUnits.distance, + self.x >> PreferredUnits.distance, self.velocity >> PreferredUnits.velocity, self.mach, self.y >> PreferredUnits.drop, @@ -131,7 +131,7 @@ def in_def_units(self) -> tuple: self.drop_angle >> PreferredUnits.adjustment, self.windage >> PreferredUnits.drop, self.windage_angle >> PreferredUnits.adjustment, - self.look_distance >> PreferredUnits.distance, + self.distance >> PreferredUnits.distance, self.angle >> PreferredUnits.angular, self.density_factor, self.drag, @@ -150,11 +150,11 @@ class DangerSpace(NamedTuple): look_angle: Angular def __str__(self) -> str: - return f'Danger space at {self.at_range.distance << PreferredUnits.distance} ' \ + return f'Danger space at {self.at_range.x << PreferredUnits.distance} ' \ + f'for {self.target_height << PreferredUnits.drop} tall target ' \ + (f'at {self.look_angle << Angular.Degree} look-angle ' if self.look_angle != 0 else '') \ - + f'ranges from {self.begin.distance << PreferredUnits.distance} ' \ - + f'to {self.end.distance << PreferredUnits.distance}' + + f'ranges from {self.begin.x << PreferredUnits.distance} ' \ + + f'to {self.end.x << PreferredUnits.distance}' def overlay(self, ax: 'Axes', label: Optional[str] = None): # type: ignore """Highlights danger-space region on plot""" @@ -162,11 +162,11 @@ def overlay(self, ax: 'Axes', label: Optional[str] = None): # type: ignore raise ImportError("Use `pip install py_ballisticcalc[charts]` to get results as a plot") cosine = math.cos(self.look_angle >> Angular.Radian) - begin_dist = (self.begin.distance >> PreferredUnits.distance) * cosine + begin_dist = (self.begin.x >> PreferredUnits.distance) * cosine begin_drop = (self.begin.y >> PreferredUnits.drop) * cosine - end_dist = (self.end.distance >> PreferredUnits.distance) * cosine + end_dist = (self.end.x >> PreferredUnits.distance) * cosine end_drop = (self.end.y >> PreferredUnits.drop) * cosine - range_dist = (self.at_range.distance >> PreferredUnits.distance) * cosine + range_dist = (self.at_range.x >> PreferredUnits.distance) * cosine range_drop = (self.at_range.y >> PreferredUnits.drop) * cosine h = self.target_height >> PreferredUnits.drop @@ -182,7 +182,7 @@ def overlay(self, ax: 'Axes', label: Optional[str] = None): # type: ignore edgecolor='none', facecolor='r', alpha=0.3) ax.add_patch(polygon) if label is None: # Add default label - label = f"Danger space\nat {self.at_range.distance << PreferredUnits.distance}" + label = f"Danger space\nat {self.at_range.x << PreferredUnits.distance}" if label != '': ax.text(begin_dist + (end_dist - begin_dist) / 2, end_drop, label, linespacing=1.2, fontsize=PLOT_FONT_SIZE, ha='center', va='top') @@ -326,29 +326,29 @@ def plot(self, look_angle: Optional[Angular] = None) -> 'Axes': # type: ignore "Use Calculator.fire(..., extra_data=True)") font_size = PLOT_FONT_SIZE df = self.dataframe() - ax = df.plot(x='distance', y=['y'], ylabel=PreferredUnits.drop.symbol) - max_range = self.trajectory[-1].distance >> PreferredUnits.distance + ax = df.plot(x='x', y=['y'], ylabel=PreferredUnits.drop.symbol) + max_range = self.trajectory[-1].x >> PreferredUnits.distance for p in self.trajectory: if TrajFlag(p.flag) & TrajFlag.ZERO: - ax.plot([p.distance >> PreferredUnits.distance, p.distance >> PreferredUnits.distance], + ax.plot([p.x_sight >> PreferredUnits.distance, p.x >> PreferredUnits.distance], [df['y'].min(), p.y >> PreferredUnits.drop], linestyle=':') - ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['y'].min(), + ax.text((p.x >> PreferredUnits.distance) + max_range / 100, df['y'].min(), f"{(TrajFlag(p.flag) & TrajFlag.ZERO).name}", fontsize=font_size, rotation=90) if TrajFlag(p.flag) & TrajFlag.MACH: - ax.plot([p.distance >> PreferredUnits.distance, p.distance >> PreferredUnits.distance], + ax.plot([p.x >> PreferredUnits.distance, p.x >> PreferredUnits.distance], [df['y'].min(), p.y >> PreferredUnits.drop], linestyle=':') - ax.text((p.distance >> PreferredUnits.distance) + max_range / 100, df['y'].min(), + ax.text((p.x >> PreferredUnits.distance) + max_range / 100, df['y'].min(), "Mach 1", fontsize=font_size, rotation=90) - max_range_in_drop_units = self.trajectory[-1].distance >> PreferredUnits.drop + max_range_in_drop_units = self.trajectory[-1].x >> PreferredUnits.drop # Sight line - x_sight = [0, df.distance.max()] + x_sight = [0, df.x.max()] y_sight = [0, max_range_in_drop_units * math.tan(look_angle >> Angular.Radian)] ax.plot(x_sight, y_sight, linestyle='--', color=[.3, 0, .3, .5]) # Barrel pointing line - x_bbl = [0, df.distance.max()] + x_bbl = [0, df.x.max()] y_bbl = [-(self.shot.weapon.sight_height >> PreferredUnits.drop), max_range_in_drop_units * math.tan(self.trajectory[0].angle >> Angular.Radian) - (self.shot.weapon.sight_height >> PreferredUnits.drop)] diff --git a/tests/test_danger_space.py b/tests/test_danger_space.py index 98881fd..29aa583 100644 --- a/tests/test_danger_space.py +++ b/tests/test_danger_space.py @@ -23,15 +23,15 @@ def test_danger_space(self): ) self.assertAlmostEqual( - round(danger_space.begin.distance >> Distance.Yard, Distance.Yard.accuracy), 393.6, 0) + round(danger_space.begin.x >> Distance.Yard, Distance.Yard.accuracy), 393.6, 0) self.assertAlmostEqual( - round(danger_space.end.distance >> Distance.Yard, Distance.Yard.accuracy), 579.0, 0) + round(danger_space.end.x >> Distance.Yard, Distance.Yard.accuracy), 579.0, 0) danger_space = self.shot_result.danger_space( Distance.Yard(500), Distance.Inch(10), self.look_angle ) self.assertAlmostEqual( - round(danger_space.begin.distance >> Distance.Yard, Distance.Yard.accuracy), 484.5, 0) + round(danger_space.begin.x >> Distance.Yard, Distance.Yard.accuracy), 484.5, 0) self.assertAlmostEqual( - round(danger_space.end.distance >> Distance.Yard, Distance.Yard.accuracy), 514.8, 0) + round(danger_space.end.x >> Distance.Yard, Distance.Yard.accuracy), 514.8, 0) diff --git a/tests/test_trajectory.py b/tests/test_trajectory.py index a851b19..10543e6 100644 --- a/tests/test_trajectory.py +++ b/tests/test_trajectory.py @@ -40,7 +40,7 @@ def validate_one(self, data: TrajectoryData, distance: float, velocity: float, windage: float, wind_adjustment: float, time: float, ogv: float, adjustment_unit: Unit): - self.custom_assert_equal(distance, data.distance >> Distance.Yard, 0.001, "Distance") + self.custom_assert_equal(distance, data.x >> Distance.Yard, 0.001, "Distance") self.custom_assert_equal(velocity, data.velocity >> Velocity.FPS, 5, "Velocity") self.custom_assert_equal(mach, data.mach, 0.005, "Mach") self.custom_assert_equal(energy, data.energy >> Energy.FootPound, 5, "Energy") From 77ebf5b1a2869486e43999ec80a48a110da62dfe Mon Sep 17 00:00:00 2001 From: gambon0120 Date: Sun, 18 Aug 2024 20:42:49 +0200 Subject: [PATCH 4/4] fixed type check --- py_ballisticcalc/trajectory_data.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/py_ballisticcalc/trajectory_data.py b/py_ballisticcalc/trajectory_data.py index 7ebc856..ae79693 100644 --- a/py_ballisticcalc/trajectory_data.py +++ b/py_ballisticcalc/trajectory_data.py @@ -331,7 +331,7 @@ def plot(self, look_angle: Optional[Angular] = None) -> 'Axes': # type: ignore for p in self.trajectory: if TrajFlag(p.flag) & TrajFlag.ZERO: - ax.plot([p.x_sight >> PreferredUnits.distance, p.x >> PreferredUnits.distance], + ax.plot([p.x >> PreferredUnits.distance, p.x >> PreferredUnits.distance], [df['y'].min(), p.y >> PreferredUnits.drop], linestyle=':') ax.text((p.x >> PreferredUnits.distance) + max_range / 100, df['y'].min(), f"{(TrajFlag(p.flag) & TrajFlag.ZERO).name}",