Skip to content

Commit

Permalink
* fix: ordering weapon attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
o-murphy committed Oct 12, 2023
1 parent a398afc commit 9c4372a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 16 deletions.
2 changes: 1 addition & 1 deletion py_ballisticcalc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
__copyright__ = ("",)

__credits__ = ["o-murphy"]
__version__ = "1.1.0b7"
__version__ = "1.1.0b8"

from .drag_model import * # pylint: disable=import-error
from .drag_tables import *
Expand Down
12 changes: 3 additions & 9 deletions py_ballisticcalc/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,17 @@ def to_dataframe(trajectory: list[TrajectoryData]):
trajectory = [p.in_def_units() for p in trajectory]
return pd.DataFrame(trajectory, columns=col_names)

def show_plot(self, shot, winds):
def show_plot(self, shot, current_atmo, winds):
import matplotlib
import matplotlib.pyplot as plt

matplotlib.use('TkAgg')
self._calc = TrajectoryCalc(self.ammo)
# self.update_elevation()
data = self._calc.trajectory(self.weapon, self.zero_atmo, shot, winds,
data = self._calc.trajectory(self.weapon, current_atmo, shot, winds,
TrajFlag.ALL.value) # Step in 10-yard increments to produce smoother curves
df = self.to_dataframe(data)
ax = df.plot(x='distance', y=['drop'], ylabel=Set.Units.drop.symbol)

# zero_d = self.weapon.zero_distance >> Set.Units.distance
# zero = ax.plot([zero_d, zero_d], [df['drop'].min(), df['drop'].max()], linestyle='--')

for p in data:

if TrajFlag(p.flag) & TrajFlag.ZERO:
Expand All @@ -120,11 +117,8 @@ def show_plot(self, shot, winds):
[df['drop'].min(), p.drop >> Set.Units.drop], linestyle='--', label='mach')
ax.text(p.distance >> Set.Units.distance, df['drop'].min(), " Mach")

#sh = self.weapon.sight_height >> Set.Units.drop

# # scope line
x_values = [0, df.distance.max()] # Adjust these as needed
# y_values = [sh, sh - df.distance.max() * math.tan(self.elevation >> Angular.Degree)] # Adjust these as needed
y_values = [0, 0] # Adjust these as needed
ax.plot(x_values, y_values, linestyle='--', label='scope line')
ax.text(df.distance.max() - 100, -100, "Scope")
Expand Down
2 changes: 1 addition & 1 deletion py_ballisticcalc/munition.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class Weapon(TypedUnits):
"""
sight_height: [float, Distance] = field(default_factory=lambda: Set.Units.sight_height)
zero_distance: [float, Distance] = field(default_factory=lambda: Set.Units.distance)
zero_look_angle: [float, Angular] = field(default_factory=lambda: Set.Units.angular)
twist: [float, Distance] = field(default_factory=lambda: Set.Units.twist)
zero_look_angle: [float, Angular] = field(default_factory=lambda: Set.Units.angular)

def __post_init__(self):
if not self.twist:
Expand Down
3 changes: 1 addition & 2 deletions py_ballisticcalc/trajectory_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,5 @@ def in_def_units(self) -> tuple:
self.angle >> Set.Units.angular,
self.energy >> Set.Units.energy,
self.ogw >> Set.Units.ogw,

self.flag
TrajFlag(self.flag)
)
7 changes: 4 additions & 3 deletions tests/test_plot.py.bak → tests/plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@
dm = DragModel(0.22, TableG7, 168, 0.308)
ammo = Ammo(dm, 1.22, Velocity(2600, Velocity.FPS))
atmosphere = Atmo.icao()
weapon = Weapon(3, 100, 11.24)
weapon = Weapon(4, 100, 11.24)

calc = Calculator(weapon, ammo, atmosphere)
calc.update_elevation()
shot = Shot(1200, Distance.Foot(0.2), sight_angle=calc.elevation, shot_angle=Angular.Mil(0))
atmo = Atmo.icao()

calc.show_plot(shot, [Wind()])
shot = Shot(1200, Distance.Foot(0.2), zero_angle=calc.elevation, relative_angle=Angular.MOA(0))
calc.show_plot(shot, atmo, [Wind()])

0 comments on commit 9c4372a

Please sign in to comment.