File Coverage

lib/Physics/Ballistics.pm
Criterion Covered Total %
statement 9 14 64.2
branch 0 4 0.0
condition n/a
subroutine 3 5 60.0
pod 0 2 0.0
total 12 25 48.0


line stmt bran cond sub pod time code
1             package Physics::Ballistics;
2 3     3   21 use strict;
  3         7  
  3         88  
3 3     3   16 use warnings;
  3         12  
  3         90  
4              
5             # Work in progress; currently useless except for documentation.
6             # Would like this to become an easy, powerful interface akin to http://www.shooterscalculator.com/ballistic-trajectory-chart.php?t=0c84354b
7             # Generate graphs from multiple profiles via flight_sim, ebc, lethality, etc.
8             # Include in output statistics about weight and recoil.
9              
10 3     3   1008 use Math::Trig;
  3         34935  
  3         2543  
11              
12             our $VERSION = '1.03';
13             our $PI = Math::Trig::pi;
14              
15 0 0   0 0   sub setundef { ${$_[0]} = $_[1] unless ( defined ( ${$_[0]} ) ); }
  0            
  0            
16 0 0   0 0   sub absolute { $_[0] = 0 - $_[0] if ( $_[0] < 0 ); return $_[0]; }
  0            
17              
18             our %FUNCTION_DEPENDENCIES_H = (
19             'ebc' => [
20             {label => 'proj_mass', unit => 'grain'},
21             {label => 'proj_diam', unit => 'mm'},
22             [{label => 'proj_shape', unit => ''}, {label => 'proj_form_factor', unit => ''}], # list means one or the other must be defined
23             ],
24             'flight_simulator' => [
25             {label => 'drag_model', unit => ''},
26             {label => 'proj_bc', unit => ''},
27             {label => 'velocity', unit => 'fps'},
28             {label => 'sight_height', unit => 'inch'},
29             {label => 'shot_angle', unit => 'degree'},
30             {label => 'zero_range', unit => 'yard'}
31             ],
32             'muzzle_energy' => [
33             {label => 'proj_mass', unit => 'grain'},
34             {label => 'velocity', unit => 'fps'}
35             ],
36             'muzzle_velocity_from_energy' => [
37             {label => 'proj_mass', unit => 'grain'},
38             {label => 'proj_ke', unit => 'ftlb'},
39             ],
40             'cartridge_capacity' => [
41             {label => 'proj_diam', unit => 'mm'},
42             {label => 'case_base_diam', unit => 'mm'},
43             {label => 'case_len', unit => 'mm'},
44             {label => 'pressure', unit => 'psi'}
45             ],
46             'empty_brass' => [
47             {label => 'proj_diam', unit => 'mm'},
48             {label => 'case_base_diam', unit => 'mm'},
49             {label => 'case_len', unit => 'mm'},
50             {label => 'pressure', unit => 'psi'}
51             ],
52             'gunfire' => [
53             {label => 'proj_diam', unit => 'mm'},
54             {label => 'case_base_diam', unit => 'mm'},
55             {label => 'case_len', unit => 'mm'},
56             {label => 'pressure', unit => 'psi'},
57             {label => 'proj_mass', unit => 'grain'},
58             {label => 'barrel_len', unit => 'inch'}
59             ],
60             'powley' => [
61             {label => 'proj_diam', unit => 'mm'},
62             {label => 'case_base_diam', unit => 'mm'},
63             {label => 'case_len', unit => 'mm'},
64             {label => 'barrel_reference_len', unit => 'inch'},
65             {label => 'barrel_len', unit => 'inch'}
66             ],
67             'ke' => [
68             {label => 'velocity', unit => 'mps'},
69             {label => 'proj_mass', unit => 'grain'}
70             ],
71             'penetration_rha' => [ # Physics::Ballistics::Terminal::pc()
72             {label => 'proj_mass', unit => 'grain'},
73             {label => 'velocity', unit => 'fps'},
74             {label => 'proj_diam', unit => 'inch'},
75             {label => 'proj_composition', unit => ''}
76             ],
77             'penetration_flesh' => [ # Physics::Ballistics::Terminal::poncelet()
78             {label => 'proj_mass', unit => 'grain'},
79             {label => 'velocity', unit => 'fps'},
80             {label => 'proj_diam', unit => 'inch'},
81             {label => 'proj_composition', unit => ''}
82             ]
83             );
84              
85             our %FUNCTION_PRODUCT_H = (
86             'ebc' => [
87             {label => 'proj_bc', unit => 'grain'},
88             ],
89             'flight_simulator' => [
90             {label => 'flight_ar', unit => 'list'}
91             ],
92             'muzzle_energy' => [
93             {label => 'proj_ke', unit => 'ftlb'}
94             ],
95             'muzzle_velocity_from_energy' => [
96             {label => 'reference_velocity', unit => 'fps'}
97             ],
98             'cartridge_capacity' => [
99             {label => 'case_volume', unit => 'grain_water'}
100             ],
101             'empty_brass' => [
102             {label => 'case_mass', unit => 'grain'}
103             ],
104             'gunfire' => [
105             {label => '', unit => 'hash', mapping => {
106             'N*m' => {label => 'proj_ke', unit => 'joule'},
107             'f/s' => {label => 'velocity', unit => 'fps'} # zzapp -- whenever setting velocity, also set reference velocity for 24" barrel
108             }}
109             ],
110             'powley' => [
111             # special-case -- multiply by reference velocity to get new velocity -- zzapp
112             ],
113             'ke' => [
114             {label => 'proj_ke', unit => 'joule'}
115             ],
116             'penetration_rha' => [ # Physics::Ballistics::Terminal::pc()
117             {label => 'proj_penetration_rha', unit => 'mm'}
118             ],
119             'penetration_flesh' => [ # Physics::Ballistics::Terminal::poncelet()
120             {label => 'proj_penetration_flesh', unit => 'mm'}
121             ]
122             );
123              
124             1;
125              
126             =head1 NAME
127              
128             Physics::Ballistics -- Ballistics formulae.
129              
130             =head1 ABSTRACT
131              
132             Ballistics is the study of the launching, flight and effects of projectiles.
133             This distribution provides various formulae producing metrics of internal,
134             external and terminal ballistics.
135              
136             These formulae are primarily oriented towards the ballistics of small arms
137             bullets between 5mm and 14mm and diameter, and to a lesser extent heavier
138             hypervelocity projectiles ("long rod" penetrators) and shaped charges.
139              
140             More extensive documentation is available in each of these three constituent
141             modules.
142              
143             =head1 MODULES
144              
145             L - launch mechanics
146              
147             L - flight mechanics
148              
149             L - terminal effects
150              
151             =head1 TODO
152              
153             I would like Physics::Ballistics to provide the integrated functionality of
154             these modules in an object-oriented way, someday.
155              
156             Some rocket physics functions are works in progress. Those might get integrated here eventually.
157              
158             The units used and returned by these functions are horribly inconsistent, but at least they are documented. They might be made more consistent in the future.
159              
160             See also the individual modules for module-specific to-do lists.
161              
162             =head1 AUTHOR
163              
164             TTK Ciar,
165              
166             =head1 COPYRIGHT AND LICENSE
167              
168             Copyright 2007-2017 by TTK Ciar
169              
170             This library is free software; you can redistribute it and/or modify it under
171             the same terms as Perl itself.
172              
173             =cut