lob 0.2.2
 
Loading...
Searching...
No Matches
lob.hpp
Go to the documentation of this file.
1// This file is a part of lob, an exterior ballistics calculation library
2// Copyright (c) 2025 Joel Benway
3// Please see end of file for extended copyright information
4
5#pragma once
6
7#include <array>
8#include <cstddef>
9#include <cstdint>
10#include <limits>
11
12#include "lob/lob_export.hpp"
13
14namespace lob {
15
20LOB_EXPORT const char* Version();
21
25enum class LOB_EXPORT DragFunctionT : uint8_t {
26 kG1,
32};
33
37enum class LOB_EXPORT AtmosphereReferenceT : uint8_t {
38 kArmyStandardMetro,
40};
41
47enum class LOB_EXPORT ClockAngleT : uint8_t {
48 kIII = 0U,
60}; // enum class ClockAngleT
61
63static constexpr auto kNaN = std::numeric_limits<float>::quiet_NaN();
64
70struct LOB_EXPORT Input {
71 static constexpr uint8_t kTableSize{
72 85};
73 std::array<uint16_t, kTableSize> drags{};
75 kNaN};
76 float speed_of_sound{kNaN};
77 uint16_t velocity{0};
78 float mass{kNaN};
79 float optic_height{kNaN};
80 struct Gravity {
81 float x{kNaN};
82 float y{kNaN};
83 } gravity;
84 struct Wind {
85 float x{kNaN};
86 float z{kNaN};
87 } wind;
88 struct Coriolis {
89 float cos_l_sin_a{kNaN};
90 float sin_l{kNaN};
91 float cos_l_cos_a{kNaN};
92 } corilolis;
94 kNaN};
95 float aerodynamic_jump{kNaN};
96 float stability_factor{kNaN};
97}; // struct Input
98
99class Impl;
100
105class LOB_EXPORT Builder {
106 public:
109 Builder(const Builder& other);
110 Builder(Builder&& other) noexcept;
112 const Builder& rhs);
114 Builder&& rhs) noexcept;
115
139 Builder& DiameterInch(float value);
145 Builder& LengthInch(float value);
156 Builder& MachVsDragTable(const float* pmachs, const float* pdrags,
157 size_t size);
167 template <size_t N>
168 Builder& MachVsDragTable(const std::array<float, N>& machs,
169 const std::array<float, N>& drags) {
170 return MachVsDragTable(machs.data(), drags.data(), N);
171 }
172
177 Builder& MassGrains(float value);
183 Builder& InitialVelocityFps(uint16_t value);
205 Builder& ZeroAngleMOA(float value);
277 Builder& WindHeadingDeg(float value);
283 Builder& WindSpeedFps(float value);
289 Builder& WindSpeedMph(float value);
296 Builder& AzimuthDeg(float value);
303 Builder& LatitudeDeg(float value);
309 Builder& RangeAngleDeg(float value);
315
316 private:
317 static constexpr size_t kBufferSize{392};
318 union AlignmentT {
319 double foo;
320 size_t bar;
321 };
322 alignas(AlignmentT) std::array<uint8_t, kBufferSize> buffer_{};
323 Impl* pimpl_{nullptr};
324}; // class Builder
325
329struct LOB_EXPORT Options {
330 uint16_t min_speed{0};
331 uint16_t min_energy{0};
332 float max_time{kNaN};
333 uint16_t step_size{0};
334}; // struct Options
335
339struct LOB_EXPORT Output {
340 uint32_t range{0};
341 uint16_t velocity{0};
342 uint32_t energy{0};
343 float elevation{0.0F};
344 float deflection{0.0F};
345 float time_of_flight{0.0F};
346}; // struct Output
347
357LOB_EXPORT size_t Solve(const Input& in, const uint32_t* pranges, Output* pouts,
358 size_t size, const Options& options);
359
369template <size_t N>
370size_t Solve(const Input& in, const std::array<uint32_t, N>* pranges,
371 std::array<Output, N>* pouts, const Options& options = Options{}) {
372 return Solve(in, pranges->data(), pouts->data(), N, options);
373}
374
380LOB_EXPORT double MoaToMil(double value);
381
387LOB_EXPORT double MoaToDeg(double value);
388
394LOB_EXPORT double MoaToIphy(double value);
395
403LOB_EXPORT double MoaToInch(double value, double range_ft);
404
410LOB_EXPORT double MilToMoa(double value);
411
417LOB_EXPORT double MilToDeg(double value);
418
424LOB_EXPORT double MilToIphy(double value);
425
433LOB_EXPORT double MilToInch(double value, double range_ft);
434
440LOB_EXPORT double DegToMoa(double value);
441
447LOB_EXPORT double DegToMil(double value);
448
455LOB_EXPORT double InchToMoa(double value, double range_ft);
456
463LOB_EXPORT double InchToMil(double value, double range_ft);
464
471LOB_EXPORT double InchToDeg(double value, double range_ft);
472
478LOB_EXPORT double JToFtLbs(double value);
479
485LOB_EXPORT double FtLbsToJ(double value);
486
492LOB_EXPORT double MtoYd(double value);
493
499LOB_EXPORT double YdToFt(double value);
500
506LOB_EXPORT double MToFt(double value);
507
513LOB_EXPORT double FtToIn(double value);
514
520LOB_EXPORT double MmToIn(double value);
521
527LOB_EXPORT double CmToIn(double value);
528
534LOB_EXPORT double YdToM(double value);
535
541LOB_EXPORT double FtToM(double value);
542
548LOB_EXPORT double FtToYd(double value);
549
555LOB_EXPORT double InToMm(double value);
556
562LOB_EXPORT double InToCm(double value);
563
569LOB_EXPORT double InToFt(double value);
570
576LOB_EXPORT double PaToInHg(double value);
577
583LOB_EXPORT double MbarToInHg(double value);
584
590LOB_EXPORT double PsiToInHg(double value);
591
597LOB_EXPORT double LbsToGrain(double value);
598
604LOB_EXPORT double GToGrain(double value);
605
611LOB_EXPORT double KgToGrain(double value);
612
618LOB_EXPORT double KgSqMToPmsi(double value);
619
625LOB_EXPORT double FpsToMps(double value);
626
632LOB_EXPORT double MpsToFps(double value);
633
639LOB_EXPORT double KphToMph(double value);
640
646LOB_EXPORT double KnToMph(double value);
647
653LOB_EXPORT double MsToS(double value);
654
660LOB_EXPORT double UsToS(double value);
661
667LOB_EXPORT double SToMs(double value);
668
674LOB_EXPORT double SToUs(double value);
675
681LOB_EXPORT double DegCToDegF(double value);
682
683} // namespace lob
684
685// This program is free software: you can redistribute it and/or modify
686// it under the terms of the GNU General Public License as published by
687// the Free Software Foundation, either version 3 of the License, or
688// (at your option) any later version.
689
690// This program is distributed in the hope that it will be useful,
691// but WITHOUT ANY WARRANTY; without even the implied warranty of
692// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
693// GNU General Public License for more details.
694
695// You should have received a copy of the GNU General Public License
696// along with this program. If not, see <https://www.gnu.org/licenses/>.
Builder & ZeroImpactHeightInches(float value)
Sets the zero impact height in inches.
Builder & WindSpeedFps(float value)
Sets the wind speed in feet per second.
Builder & AltitudeOfBarometerFt(float value)
Sets the altitude of the location where air pressure was taken in feet.
Builder & BallisticCoefficentPsi(float value)
Move assignment constructor.
Builder & operator=(const Builder &rhs)
Move constructor.
Builder & TwistInchesPerTurn(float value)
Sets the twist rate of the barrel in inches per turn.
Builder & RelativeHumidityPercent(float value)
Sets the relative humidity at the firing site in percent.
Input Build()
Builds the Input object with the configured parameters.
Builder & AltitudeOfFiringSiteFt(float value)
Sets the altitude of the firing site in feet.
Builder & operator=(Builder &&rhs) noexcept
Copy assignment constructor.
Builder & AzimuthDeg(float value)
Sets the azimuth (bearing) of the target in degrees.
Builder & ZeroAngleMOA(float value)
Sets the angle between the sight and launch angle used to achieve zero.
Builder & TemperatureDegF(float value)
Sets the temperature in degrees Fahrenheit.
Builder & LengthInch(float value)
Sets the projectile length in inches.
Builder & WindHeadingDeg(float value)
Sets the wind heading in degrees.
Builder & DiameterInch(float value)
Sets the projectile diameter (caliber) in inches.
Builder & LatitudeDeg(float value)
Sets the latitude of the firing location in degrees.
Builder & InitialVelocityFps(uint16_t value)
Sets the initial velocity of the projectile in feet per second.
Builder & AirPressureInHg(float value)
Sets the air pressure in inches of mercury (inHg).
~Builder()
Default constructor.
Builder & WindHeading(ClockAngleT value)
Sets the wind heading using a clock angle.
Builder & MachVsDragTable(const std::array< float, N > &machs, const std::array< float, N > &drags)
Loads a custom Mach vs Drag table for the projectile.
Definition lob.hpp:168
Builder & BCAtmosphere(AtmosphereReferenceT type)
Sets the atmosphere reference associated with ballistic coefficient.
Builder(const Builder &other)
Default destructor.
Builder & ZeroDistanceYds(float value)
Sets the zero distance in yards.
Builder & BCDragFunction(DragFunctionT type)
Sets the drag function associated with ballistic coefficient.
Builder & MassGrains(float value)
Sets the projectile mass in grains.
Builder & RangeAngleDeg(float value)
Sets the range angle (inclination) to the target in degrees.
Builder(Builder &&other) noexcept
Copy constructor.
Builder & AltitudeOfThermometerFt(float value)
Sets the altitude of the location where temperature was taken in feet.
Builder & OpticHeightInches(float value)
Sets the height of the optic above the bore in inches.
Builder & MachVsDragTable(const float *pmachs, const float *pdrags, size_t size)
Loads a custom Mach vs Drag table for the projectile.
Builder & WindSpeedMph(float value)
Sets the wind speed in miles per hour.
Definition lob.hpp:14
LOB_EXPORT double PsiToInHg(double value)
Converts pounds per square inch (PSI) to inches of mercury.
LOB_EXPORT double SToMs(double value)
Converts seconds to milliseconds.
enum LOB_EXPORT kI
two o'clock
Definition lob.hpp:50
enum LOB_EXPORT kG7
G6 drag function.
Definition lob.hpp:30
enum LOB_EXPORT DragFunctionT
Enumerates the supported drag functions.
Definition lob.hpp:25
LOB_EXPORT double JToFtLbs(double value)
Converts joules to foot-pounds.
LOB_EXPORT double SToUs(double value)
Converts seconds to microseconds.
enum LOB_EXPORT kVI
seven o'clock
Definition lob.hpp:57
enum LOB_EXPORT kV
six o'clock
Definition lob.hpp:58
LOB_EXPORT double MmToIn(double value)
Converts millimeters to inches.
enum LOB_EXPORT kX
eleven o'clock
Definition lob.hpp:53
LOB_EXPORT double KphToMph(double value)
Converts kilometers per hour to miles per hour.
LOB_EXPORT double InchToMil(double value, double range_ft)
Inches of projection at a given range to milliradians (MIL)
enum LOB_EXPORT kVII
eight o'clock
Definition lob.hpp:56
LOB_EXPORT double MtoYd(double value)
Converts meters to yards.
enum LOB_EXPORT AtmosphereReferenceT
Enumerates the supported atmosphere reference types.
Definition lob.hpp:37
enum LOB_EXPORT kII
three o'clock
Definition lob.hpp:49
LOB_EXPORT double YdToM(double value)
Converts yards to meters.
LOB_EXPORT double InToFt(double value)
Converts inches to feet.
LOB_EXPORT double DegToMoa(double value)
Converts degrees to minutes of angle (MOA).
LOB_EXPORT double UsToS(double value)
Converts microseconds to seconds.
LOB_EXPORT double MoaToDeg(double value)
Converts minutes of angle (MOA) to degrees.
enum LOB_EXPORT kG2
G1 drag function.
Definition lob.hpp:27
enum LOB_EXPORT kG8
G7 drag function.
Definition lob.hpp:32
LOB_EXPORT double MoaToInch(double value, double range_ft)
Converts minutes of angle (MOA) to projected inches at a given range in feet.
enum LOB_EXPORT kVIII
nine o'clock
Definition lob.hpp:55
LOB_EXPORT double PaToInHg(double value)
Converts pascals to inches of mercury.
LOB_EXPORT double DegCToDegF(double value)
Converts degrees celsius to degrees fahrenheit.
LOB_EXPORT const char * Version()
Gets the library version in major.minor.patch format.
enum LOB_EXPORT kIcao
Army Standard Metro.
Definition lob.hpp:40
LOB_EXPORT double CmToIn(double value)
Converts centimeters to inches.
LOB_EXPORT double KnToMph(double value)
Converts Knots to miles per hour.
enum LOB_EXPORT kG5
G2 drag function.
Definition lob.hpp:28
enum LOB_EXPORT kIV
five o'clock
Definition lob.hpp:60
LOB_EXPORT double InchToMoa(double value, double range_ft)
Inches of projection at a given range to minutes of angle (MOA)
LOB_EXPORT double MToFt(double value)
Converts meters to feet.
LOB_EXPORT double InToMm(double value)
Converts inches to millimeters.
LOB_EXPORT double InchToDeg(double value, double range_ft)
Inches of projection at a given range to degrees.
LOB_EXPORT double GToGrain(double value)
Converts grams to grains.
enum LOB_EXPORT kG6
G5 drag function.
Definition lob.hpp:29
LOB_EXPORT double KgSqMToPmsi(double value)
Converts kilograms per square meter to pounds mass per square inch.
enum LOB_EXPORT kIX
ten o'clock
Definition lob.hpp:54
LOB_EXPORT double MoaToIphy(double value)
Converts minutes of angle (MOA) to inches per hundred yards (IPHY).
LOB_EXPORT double MbarToInHg(double value)
Converts millibars to inches of mercury.
LOB_EXPORT double MsToS(double value)
Converts milliseconds to seconds.
LOB_EXPORT double MpsToFps(double value)
Converts meters per second to feet per second.
LOB_EXPORT double FtLbsToJ(double value)
Converts foot-pounds to joules.
LOB_EXPORT double MilToMoa(double value)
Converts milliradians (MIL) to minutes of angle (MOA).
LOB_EXPORT double DegToMil(double value)
Converts degrees to milliradians (MIL).
LOB_EXPORT double LbsToGrain(double value)
Converts pounds to grains.
LOB_EXPORT size_t Solve(const Input &in, const uint32_t *pranges, Output *pouts, size_t size, const Options &options)
Solves the exterior ballistics problem for a given set of ranges.
LOB_EXPORT double FtToIn(double value)
Converts feet to inches.
LOB_EXPORT double FtToM(double value)
Converts feet to meters.
LOB_EXPORT double YdToFt(double value)
Converts yards to feet.
LOB_EXPORT double KgToGrain(double value)
Converts kilograms to grains.
LOB_EXPORT double MilToInch(double value, double range_ft)
Converts milliradians (MIL) to projected inches at a given range in feet.
LOB_EXPORT double InToCm(double value)
Converts inches to centimeters.
enum LOB_EXPORT ClockAngleT
Enumerates clock angle positions.
Definition lob.hpp:47
LOB_EXPORT double MilToIphy(double value)
Converts milliradians (MIL) to inches per hundred yards (IPHY).
LOB_EXPORT double FtToYd(double value)
Converts feet to yards.
LOB_EXPORT double MoaToMil(double value)
Converts minutes of angle (MOA) to milliradians (MIL).
enum LOB_EXPORT kXI
twelve o'clock
Definition lob.hpp:52
LOB_EXPORT double MilToDeg(double value)
Converts milliradians (MIL) to degrees.
LOB_EXPORT double FpsToMps(double value)
Converts feet per second to meters per second.
enum LOB_EXPORT kXII
one o'clock
Definition lob.hpp:51
Definition lob.hpp:88
float cos_l_cos_a
2Ωsin(latitude)
Definition lob.hpp:91
float sin_l
2Ωcos(latitude)sin(azimuth)
Definition lob.hpp:90
float cos_l_sin_a
Coriolis effect parameters.
Definition lob.hpp:89
Height of the optic above the bore.
Definition lob.hpp:80
float y
Acceleration ft/s/s in the x-direction.
Definition lob.hpp:82
float x
Gravity vector.
Definition lob.hpp:81
Definition lob.hpp:84
float z
Wind speed in fps in the x-direction.
Definition lob.hpp:86
float x
Wind vector.
Definition lob.hpp:85
Structure of input parameters consumed by the solver.
Definition lob.hpp:70
std::array< uint16_t, kTableSize > drags
The size of the drag table.
Definition lob.hpp:73
float speed_of_sound
A coefficient used to scale the drag table.
Definition lob.hpp:76
uint16_t velocity
The local speed of sound in Fps.
Definition lob.hpp:77
float zero_angle
Definition lob.hpp:93
float optic_height
Mass of the projectile in pounds.
Definition lob.hpp:79
float table_coefficent
The drag table.
Definition lob.hpp:74
float mass
Initial velocity of projectile in Fps.
Definition lob.hpp:78
float aerodynamic_jump
Angle between the sight and initial trajectory.
Definition lob.hpp:95
static constexpr uint8_t kTableSize
Definition lob.hpp:71
float stability_factor
Aerodynamic jump effect in Moa.
Definition lob.hpp:96
Structure holding optional parameters for the Solve function.
Definition lob.hpp:329
uint16_t step_size
Maximum time of flight in seconds.
Definition lob.hpp:333
uint16_t min_speed
Definition lob.hpp:330
float max_time
Minimum energy threshold in foot-pounds.
Definition lob.hpp:332
uint16_t min_energy
Minimum speed threshold in feet per second.
Definition lob.hpp:331
Structure holding the output results of the ballistic calculation.
Definition lob.hpp:339
uint32_t range
Definition lob.hpp:340
float elevation
Calculated energy in foot-pounds.
Definition lob.hpp:343
uint16_t velocity
Associated range in yards.
Definition lob.hpp:341
float deflection
Calculated elevation change in inches.
Definition lob.hpp:344
uint32_t energy
Calculated velocity in feet per second.
Definition lob.hpp:342
float time_of_flight
Calculated windage deflection in inches.
Definition lob.hpp:345