Class: Ballistics::Problem
- Inherits:
-
Object
- Object
- Ballistics::Problem
- Defined in:
- lib/ballistics/problem.rb
Constant Summary collapse
- DEFAULTS =
{ shooting_angle: 0, # degrees; downhill 0 to -90, uphill 0 to +90 wind_speed: 0, # mph wind_angle: 90, # degrees; 0-360 clockwise; 90 right, 270 left interval: 50, # yards max_range: 500, # yards y_intercept: 0, # inches; -2 means POI 2 inches below POA @ zero range }
Instance Attribute Summary collapse
-
#atmosphere ⇒ Object
Returns the value of attribute atmosphere.
-
#cartridge ⇒ Object
Returns the value of attribute cartridge.
-
#gun ⇒ Object
Returns the value of attribute gun.
-
#projectile ⇒ Object
Returns the value of attribute projectile.
Class Method Summary collapse
Instance Method Summary collapse
-
#enrich(opts = {}) ⇒ Object
Given a hash of specified options / params Return a hash of params enriched by DEFAULTS as well as any inferred parameters from @projectile, @cartridge, @gun, and @atmosphere.
-
#initialize(projectile: nil, cartridge: nil, gun: nil, atmosphere: nil) ⇒ Problem
constructor
A new instance of Problem.
-
#report ⇒ Object
Return a multiline string showing each component of the problem.
-
#table(trajectory: nil, fields: nil, opts: {}) ⇒ Object
Return a multiline string based on trajectory data.
-
#trajectory(opts = {}) ⇒ Object
Return a data structure with trajectory data at every interval for the specified range.
-
#zero_angle(opts = {}) ⇒ Object
Given a zero range and basic ballistics parameters Return the angle between sight axis and bore axis necessary to achieve zero.
Constructor Details
#initialize(projectile: nil, cartridge: nil, gun: nil, atmosphere: nil) ⇒ Problem
Returns a new instance of Problem.
27 28 29 30 31 32 33 34 35 |
# File 'lib/ballistics/problem.rb', line 27 def initialize(projectile: nil, cartridge: nil, gun: nil, atmosphere: nil) @projectile = projectile @cartridge = cartridge @gun = gun @atmosphere = atmosphere end |
Instance Attribute Details
#atmosphere ⇒ Object
Returns the value of attribute atmosphere.
25 26 27 |
# File 'lib/ballistics/problem.rb', line 25 def atmosphere @atmosphere end |
#cartridge ⇒ Object
Returns the value of attribute cartridge.
25 26 27 |
# File 'lib/ballistics/problem.rb', line 25 def cartridge @cartridge end |
#gun ⇒ Object
Returns the value of attribute gun.
25 26 27 |
# File 'lib/ballistics/problem.rb', line 25 def gun @gun end |
#projectile ⇒ Object
Returns the value of attribute projectile.
25 26 27 |
# File 'lib/ballistics/problem.rb', line 25 def projectile @projectile end |
Class Method Details
.simple(gun_id:, cart_id:, gun_family: nil) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/ballistics/problem.rb', line 17 def self.simple(gun_id:, cart_id:, gun_family: nil) gun = Ballistics::Gun.find(file: gun_family, id: gun_id) cart = gun.cartridges.fetch(cart_id) self.new(projectile: cart.projectile, cartridge: cart, gun: gun) end |
Instance Method Details
#enrich(opts = {}) ⇒ Object
Given a hash of specified options / params Return a hash of params enriched by DEFAULTS as well as any inferred
parameters from @projectile, @cartridge, @gun, and @atmosphere
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ballistics/problem.rb', line 41 def enrich(opts = {}) mine = {} mine.merge!(@projectile.params) if @projectile mine.merge!(@gun.params) if @gun mine[:velocity] = @cartridge.mv(@gun.) if @cartridge and @gun # Set up the return hash # opts overrides mine overrides DEFAULT ret = DEFAULTS.merge(mine.merge(opts)) # validate drag function and replace with the numeral if ret[:drag_function] and !ret[:drag_number] ret[:drag_number] = Ballistics::Projectile.drag_number(ret[:drag_function]) end # apply atmospheric correction to ballistic coefficient if ret[:ballistic_coefficient] and @atmosphere ret[:ballistic_coefficient] = @atmosphere.translate(ret[:ballistic_coefficient]) end ret end |
#report ⇒ Object
Return a multiline string showing each component of the problem
68 69 70 71 72 73 74 75 |
# File 'lib/ballistics/problem.rb', line 68 def report lines = [] lines << @gun.multiline if @gun lines << @cartridge.multiline if @cartridge lines << @projectile.multiline if @projectile lines << @atmosphere.multiline if @atmosphere lines.join("\n\n") end |
#table(trajectory: nil, fields: nil, opts: {}) ⇒ Object
Return a multiline string based on trajectory data
93 94 95 96 97 |
# File 'lib/ballistics/problem.rb', line 93 def table(trajectory: nil, fields: nil, opts: {}) Ballistics.table(trajectory: trajectory, fields: fields, opts: self.enrich(opts)) end |
#trajectory(opts = {}) ⇒ Object
Return a data structure with trajectory data at every interval for the
specified range
87 88 89 |
# File 'lib/ballistics/problem.rb', line 87 def trajectory(opts = {}) Ballistics.trajectory self.enrich opts end |
#zero_angle(opts = {}) ⇒ Object
Given a zero range and basic ballistics parameters Return the angle between sight axis and bore axis necessary to achieve zero
80 81 82 |
# File 'lib/ballistics/problem.rb', line 80 def zero_angle(opts = {}) Ballistics.zero_angle self.enrich opts end |