lob 0.7.0
 
Loading...
Searching...
No Matches
lob.hpp
Go to the documentation of this file.
1// Copyright (c) 2025 Joel Benway
2// SPDX-License-Identifier: GPL-3.0-or-later
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#include <type_traits>
12
13#include "lob/lob_export.hpp"
14
15namespace lob {
16
21LOB_EXPORT const char* Version();
22
26enum class LOB_EXPORT DragFunctionT : uint8_t {
27 kG1 = 1U,
28 kG2 = 2U,
29 kG5 = 5U,
30 kG6 = 6U,
31 kG7 = 7U,
32 kG8 = 8U
33};
34
38enum class LOB_EXPORT AtmosphereReferenceT : uint8_t {
39 kArmyStandardMetro,
41};
42
48enum class LOB_EXPORT ClockAngleT : uint8_t {
49 kI = 1U,
61}; // enum class ClockAngleT
62
63enum class LOB_EXPORT ErrorT : uint8_t {
64 kNone,
91}; // enum class ErrorT
92
94template <typename T = double>
95constexpr T NaN() {
96 static_assert(std::is_floating_point<T>::value,
97 "NaN() only supports floating-point types");
98 return std::numeric_limits<T>::quiet_NaN();
99}
100
106struct LOB_EXPORT Input {
107 static constexpr uint8_t kTableSize{85};
108 std::array<uint16_t, kTableSize> drags{};
110 double speed_of_sound{NaN()};
111 uint16_t velocity{0};
112 double mass{NaN()};
113 double optic_height{NaN()};
114 struct Gravity {
115 double x{NaN()};
116 double y{NaN()};
117 } gravity;
118 struct Wind {
119 double x{NaN()};
120 double z{NaN()};
121 } wind;
122 struct Coriolis {
123 double cos_l_sin_a{NaN()};
124 double sin_l{NaN()};
125 double cos_l_cos_a{NaN()};
126 } corilolis;
127 double zero_angle{NaN()};
131 uint16_t minimum_speed{0};
132 double max_time{NaN()};
133 uint16_t step_size{0};
134 ErrorT error{ErrorT::kNotFormed};
135}; // struct Input
136
137class Impl;
138
143class LOB_EXPORT Builder {
144 public:
147 Builder(const Builder& other);
148 Builder(Builder&& other) noexcept;
150 const Builder& rhs);
152 Builder&& rhs) noexcept;
153
160
167
174
180 Builder& DiameterInch(double value);
181
188
194 Builder& BaseDiameterInch(double value);
195
201 Builder& LengthInch(double value);
202
208 Builder& NoseLengthInch(double value);
209
215 Builder& TailLengthInch(double value);
216
222 Builder& OgiveRtR(double value);
223
233 Builder& MachVsDragTable(const float* pmachs, const float* pdrags,
234 size_t size);
244 template <size_t N>
245 Builder& MachVsDragTable(const std::array<float, N>& machs,
246 const std::array<float, N>& drags) {
247 return MachVsDragTable(machs.data(), drags.data(), N);
248 }
249
255 Builder& MassGrains(double value);
256
262 Builder& InitialVelocityFps(uint16_t value);
269
277
286 Builder& ZeroAngleMOA(double value);
287
293 Builder& ZeroDistanceYds(double value);
294
303
310
316 Builder& AirPressureInHg(double value);
317
328
334 Builder& TemperatureDegF(double value);
335
346
353
361
368 Builder& WindHeadingDeg(double value);
369
375 Builder& WindSpeedFps(double value);
376
382 Builder& WindSpeedMph(double value);
383
390 Builder& AzimuthDeg(double value);
391
398 Builder& LatitudeDeg(double value);
399
405 Builder& RangeAngleDeg(double value);
406
413 Builder& MinimumSpeed(uint16_t value);
414
421 Builder& MinimumEnergy(uint16_t value);
422
429 Builder& MaximumTime(double value);
430
436 Builder& StepSize(uint16_t value);
437
442 Builder& Reset() noexcept;
443
449
450 private:
451 static constexpr size_t kBufferSize{536};
452 union AlignmentT {
453 double foo;
454 size_t bar;
455 };
456 alignas(AlignmentT) std::array<uint8_t, kBufferSize> buffer_{};
457 Impl* pimpl_{nullptr};
458}; // class Builder
459
463struct LOB_EXPORT Output {
464 uint32_t range{0};
465 uint16_t velocity{0};
466 uint32_t energy{0};
467 double elevation{0.0};
468 double deflection{0.0};
469 double time_of_flight{0.0};
470}; // struct Output
471
480LOB_EXPORT size_t Solve(const Input& in, const uint32_t* pranges, Output* pouts,
481 size_t size);
482
491template <size_t N>
492size_t Solve(const Input& in, const std::array<uint32_t, N>& pranges,
493 std::array<Output, N>& pouts) {
494 return Solve(in, pranges.data(), pouts.data(), N);
495}
496
502LOB_EXPORT double MoaToMil(double value);
503
509LOB_EXPORT double MoaToDeg(double value);
510
516LOB_EXPORT double MoaToIphy(double value);
517
525LOB_EXPORT double MoaToInch(double value, double range_ft);
526
532LOB_EXPORT double MilToMoa(double value);
533
539LOB_EXPORT double MilToDeg(double value);
540
546LOB_EXPORT double MilToIphy(double value);
547
555LOB_EXPORT double MilToInch(double value, double range_ft);
556
562LOB_EXPORT double DegToMoa(double value);
563
569LOB_EXPORT double DegToMil(double value);
570
577LOB_EXPORT double InchToMoa(double value, double range_ft);
578
585LOB_EXPORT double InchToMil(double value, double range_ft);
586
593LOB_EXPORT double InchToDeg(double value, double range_ft);
594
600LOB_EXPORT double JToFtLbs(double value);
601
607LOB_EXPORT double FtLbsToJ(double value);
608
614LOB_EXPORT double MtoYd(double value);
615
621LOB_EXPORT double YdToFt(double value);
622
628LOB_EXPORT double MToFt(double value);
629
635LOB_EXPORT double FtToIn(double value);
636
642LOB_EXPORT double MmToIn(double value);
643
649LOB_EXPORT double CmToIn(double value);
650
656LOB_EXPORT double YdToM(double value);
657
663LOB_EXPORT double FtToM(double value);
664
670LOB_EXPORT double FtToYd(double value);
671
677LOB_EXPORT double InToMm(double value);
678
684LOB_EXPORT double InToCm(double value);
685
691LOB_EXPORT double InToFt(double value);
692
698LOB_EXPORT double PaToInHg(double value);
699
705LOB_EXPORT double MbarToInHg(double value);
706
712LOB_EXPORT double PsiToInHg(double value);
713
719LOB_EXPORT double LbsToGrain(double value);
720
726LOB_EXPORT double GToGrain(double value);
727
733LOB_EXPORT double KgToGrain(double value);
734
740LOB_EXPORT double KgSqMToPmsi(double value);
741
747LOB_EXPORT double FpsToMps(double value);
748
754LOB_EXPORT double MpsToFps(double value);
755
761LOB_EXPORT double KphToMph(double value);
762
768LOB_EXPORT double KnToMph(double value);
769
775LOB_EXPORT double MsToS(double value);
776
782LOB_EXPORT double UsToS(double value);
783
789LOB_EXPORT double SToMs(double value);
790
796LOB_EXPORT double SToUs(double value);
797
803LOB_EXPORT double DegCToDegF(double value);
804
805} // namespace lob
806
807// This file is part of lob.
808//
809// lob is free software: you can redistribute it and/or modify it under the
810// terms of the GNU General Public License as published by the Free Software
811// Foundation, either version 3 of the License, or (at your option) any later
812// version.
813//
814// lob is distributed in the hope that it will be useful, but WITHOUT ANY
815// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
816// A PARTICULAR PURPOSE. See the GNU General Public License for more details.
817//
818// You should have received a copy of the GNU General Public License along with
819// lob. If not, see <https://www.gnu.org/licenses/>.
Builder & WindHeadingDeg(double value)
Sets the wind heading in degrees.
Builder & LengthInch(double value)
Sets the projectile length in inches.
Builder & TemperatureDegF(double value)
Sets the temperature in degrees Fahrenheit.
Builder & ZeroAngleMOA(double value)
Sets the angle between the sight and launch angle used to achieve zero.
Builder & operator=(const Builder &rhs)
Move constructor.
Builder & MaximumTime(double value)
Sets the maximum time of flight for the solver.
Input Build()
Builds the Input object with the configured parameters.
Builder & MassGrains(double value)
Sets the projectile mass in grains.
Builder & AzimuthDeg(double value)
Sets the azimuth (bearing) of the target in degrees.
Builder & TailLengthInch(double value)
Sets the projectile tail length in inches.
Builder & operator=(Builder &&rhs) noexcept
Copy assignment constructor.
Builder & InitialVelocityFps(uint16_t value)
Sets the initial velocity of the projectile in feet per second.
Builder & AltitudeOfFiringSiteFt(double value)
Sets the altitude of the firing site in feet.
Builder & MeplatDiameterInch(double value)
Sets the projectile meplat diameter in inches.
Builder & MinimumEnergy(uint16_t value)
Sets the minimum energy threshold for the solver.
Builder & BallisticCoefficientPsi(double value)
Move assignment constructor.
Builder & AirPressureInHg(double value)
Sets the air pressure in inches of mercury (inHg).
~Builder()
Default constructor.
Builder & DiameterInch(double value)
Sets the projectile diameter (caliber) in inches.
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:245
Builder & LatitudeDeg(double value)
Sets the latitude of the firing location in degrees.
Builder & OpticHeightInches(double value)
Sets the height of the optic above the bore in inches.
Builder & BCAtmosphere(AtmosphereReferenceT type)
Sets the atmosphere reference associated with ballistic coefficient.
Builder & Reset() noexcept
Resets the builder state by creating a fresh Impl object.
Builder & ZeroDistanceYds(double value)
Sets the zero distance in yards.
Builder & MinimumSpeed(uint16_t value)
Sets the minimum speed threshold for the solver.
Builder & RangeAngleDeg(double value)
Sets the range angle (inclination) to the target in degrees.
Builder(const Builder &other)
Default destructor.
Builder & WindSpeedMph(double value)
Sets the wind speed in miles per hour.
Builder & BCDragFunction(DragFunctionT type)
Sets the drag function associated with ballistic coefficient.
Builder & ZeroImpactHeightInches(double value)
Sets the zero impact height in inches.
Builder(Builder &&other) noexcept
Copy constructor.
Builder & NoseLengthInch(double value)
Sets the projectile nose length in inches.
Builder & AltitudeOfBarometerFt(double value)
Sets the altitude of the location where air pressure was taken in feet.
Builder & OgiveRtR(double value)
Sets the Rt/R ratio of the projectile ogive.
Builder & TwistInchesPerTurn(double value)
Sets the twist rate of the barrel in inches per turn.
Builder & WindSpeedFps(double value)
Sets the wind speed in feet per second.
Builder & StepSize(uint16_t value)
Sets the step size for the numerical solver.
Builder & MachVsDragTable(const float *pmachs, const float *pdrags, size_t size)
Loads a custom Mach vs Drag table for the projectile.
Builder & BaseDiameterInch(double value)
Sets the projectile base diameter in inches.
Builder & RelativeHumidityPercent(double value)
Sets the relative humidity at the firing site in percent.
Builder & AltitudeOfThermometerFt(double value)
Sets the altitude of the location where temperature was taken in feet.
Definition lob.hpp:15
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.
constexpr T NaN()
Not-a-Number for floating-point values.
Definition lob.hpp:95
enum LOB_EXPORT kG7
G6 drag function.
Definition lob.hpp:31
enum LOB_EXPORT kDiameterOOR
Definition lob.hpp:73
enum LOB_EXPORT DragFunctionT
Enumerates the supported drag functions.
Definition lob.hpp:26
LOB_EXPORT double JToFtLbs(double value)
Converts joules to foot-pounds.
enum LOB_EXPORT kAltitudeOfThermometerOOR
Definition lob.hpp:68
LOB_EXPORT double SToUs(double value)
Converts seconds to microseconds.
enum LOB_EXPORT ErrorT
Definition lob.hpp:63
enum LOB_EXPORT kVI
five o'clock
Definition lob.hpp:54
enum LOB_EXPORT kAzimuthOOR
Definition lob.hpp:69
enum LOB_EXPORT kZeroDataRequired
Definition lob.hpp:88
enum LOB_EXPORT kMaximumTimeOOR
Definition lob.hpp:80
enum LOB_EXPORT kNotFormed
Definition lob.hpp:91
enum LOB_EXPORT kV
four o'clock
Definition lob.hpp:53
LOB_EXPORT double MmToIn(double value)
Converts millimeters to inches.
enum LOB_EXPORT kTailLengthOOR
Definition lob.hpp:85
enum LOB_EXPORT kX
nine o'clock
Definition lob.hpp:58
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
six o'clock
Definition lob.hpp:55
LOB_EXPORT double MtoYd(double value)
Converts meters to yards.
enum LOB_EXPORT kInternalError
Definition lob.hpp:76
enum LOB_EXPORT AtmosphereReferenceT
Enumerates the supported atmosphere reference types.
Definition lob.hpp:38
enum LOB_EXPORT kII
one o'clock
Definition lob.hpp:50
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:28
enum LOB_EXPORT kAirPressureOOR
Definition lob.hpp:65
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
seven o'clock
Definition lob.hpp:56
enum LOB_EXPORT kRangeAngleOOR
Definition lob.hpp:84
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:41
enum LOB_EXPORT kNoseLengthOOR
Definition lob.hpp:82
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 kOgiveRtROOR
Definition lob.hpp:83
LOB_EXPORT size_t Solve(const Input &in, const uint32_t *pranges, Output *pouts, size_t size)
Solves the exterior ballistics problem for a given set of ranges.
enum LOB_EXPORT kBallisticCoefficientOOR
Definition lob.hpp:70
enum LOB_EXPORT kG5
G2 drag function.
Definition lob.hpp:29
enum LOB_EXPORT kZeroDistanceOOR
Definition lob.hpp:89
enum LOB_EXPORT kIV
three o'clock
Definition lob.hpp:52
enum LOB_EXPORT kBallisticCoefficientRequired
Definition lob.hpp:71
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 kInitialVelocityRequired
Definition lob.hpp:75
enum LOB_EXPORT kG6
G5 drag function.
Definition lob.hpp:30
enum LOB_EXPORT kAltitudeOfFiringSiteOOR
Definition lob.hpp:67
LOB_EXPORT double KgSqMToPmsi(double value)
Converts kilograms per square meter to pounds mass per square inch.
enum LOB_EXPORT kIX
eight o'clock
Definition lob.hpp:57
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.
enum LOB_EXPORT kLengthOOR
Definition lob.hpp:78
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 double FtToIn(double value)
Converts feet to inches.
enum LOB_EXPORT kMassOOR
Definition lob.hpp:79
LOB_EXPORT double FtToM(double value)
Converts feet to meters.
enum LOB_EXPORT kIII
two o'clock
Definition lob.hpp:51
LOB_EXPORT double YdToFt(double value)
Converts yards to feet.
enum LOB_EXPORT kZeroAngleOOR
Definition lob.hpp:87
enum LOB_EXPORT kAltitudeOfBarometerOOR
Definition lob.hpp:66
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:48
LOB_EXPORT double MilToIphy(double value)
Converts milliradians (MIL) to inches per hundred yards (IPHY).
enum LOB_EXPORT kWindHeadingOOR
Definition lob.hpp:86
LOB_EXPORT double FtToYd(double value)
Converts feet to yards.
enum LOB_EXPORT kMeplatDiameterOOR
Definition lob.hpp:81
LOB_EXPORT double MoaToMil(double value)
Converts minutes of angle (MOA) to milliradians (MIL).
enum LOB_EXPORT kXI
ten o'clock
Definition lob.hpp:59
enum LOB_EXPORT kHumidityOOR
Definition lob.hpp:74
LOB_EXPORT double MilToDeg(double value)
Converts milliradians (MIL) to degrees.
enum LOB_EXPORT kLatitudeOOR
Definition lob.hpp:77
LOB_EXPORT double FpsToMps(double value)
Converts feet per second to meters per second.
enum LOB_EXPORT kXII
eleven o'clock
Definition lob.hpp:61
enum LOB_EXPORT kBaseDiameterOOR
Definition lob.hpp:72
Definition lob.hpp:122
double cos_l_sin_a
Coriolis effect parameters.
Definition lob.hpp:123
double sin_l
2Ωcos(latitude)sin(azimuth)
Definition lob.hpp:124
double cos_l_cos_a
2Ωsin(latitude)
Definition lob.hpp:125
Height of the optic above the bore.
Definition lob.hpp:114
double x
Gravity vector.
Definition lob.hpp:115
double y
Acceleration ft/s/s in the x-direction.
Definition lob.hpp:116
Definition lob.hpp:118
double x
Wind vector.
Definition lob.hpp:119
double z
Wind speed in fps in the x-direction.
Definition lob.hpp:120
Structure of input parameters consumed by the solver.
Definition lob.hpp:106
std::array< uint16_t, kTableSize > drags
The size of drag table.
Definition lob.hpp:108
double max_time
Minimum speed for solver.
Definition lob.hpp:132
double spindrift_factor
Aerodynamic jump effect in Moa.
Definition lob.hpp:130
double optic_height
Mass of the projectile in pounds.
Definition lob.hpp:113
double mass
Initial velocity of projectile in Fps.
Definition lob.hpp:112
double zero_angle
Definition lob.hpp:127
double aerodynamic_jump
Miller stability factor.
Definition lob.hpp:129
uint16_t velocity
The local speed of sound in Fps.
Definition lob.hpp:111
uint16_t step_size
Max time of flight for solver.
Definition lob.hpp:133
uint16_t minimum_speed
Spin drift factor.
Definition lob.hpp:131
double table_coefficient
The drag table.
Definition lob.hpp:109
double speed_of_sound
Used to scale the drag table.
Definition lob.hpp:110
double stability_factor
Angle between sight and trajectory.
Definition lob.hpp:128
ErrorT error
Step size for solver.
Definition lob.hpp:134
static constexpr uint8_t kTableSize
Definition lob.hpp:107
Structure holding the output results of the ballistic calculation.
Definition lob.hpp:463
double elevation
Calculated energy in foot-pounds.
Definition lob.hpp:467
uint32_t range
Definition lob.hpp:464
double time_of_flight
Calculated windage deflection in inches.
Definition lob.hpp:469
uint16_t velocity
Associated range in yards.
Definition lob.hpp:465
uint32_t energy
Calculated velocity in feet per second.
Definition lob.hpp:466
double deflection
Calculated elevation change in inches.
Definition lob.hpp:468