lob 0.6.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,
33};
34
38enum class LOB_EXPORT AtmosphereReferenceT : uint8_t {
39 kArmyStandardMetro,
41};
42
48enum class LOB_EXPORT ClockAngleT : uint8_t {
49 kIII = 0U,
61}; // enum class ClockAngleT
62
64template <typename T = double>
65constexpr T NaN() {
66 static_assert(std::is_floating_point<T>::value,
67 "NaN() only supports floating-point types");
68 return std::numeric_limits<T>::quiet_NaN();
69}
70
76struct LOB_EXPORT Input {
77 static constexpr uint8_t kTableSize{85};
78 std::array<uint16_t, kTableSize> drags{};
80 double speed_of_sound{NaN()};
81 uint16_t velocity{0};
82 double mass{NaN()};
83 double optic_height{NaN()};
84 struct Gravity {
85 double x{NaN()};
86 double y{NaN()};
87 } gravity;
88 struct Wind {
89 double x{NaN()};
90 double z{NaN()};
91 } wind;
92 struct Coriolis {
93 double cos_l_sin_a{NaN()};
94 double sin_l{NaN()};
95 double cos_l_cos_a{NaN()};
96 } corilolis;
97 double zero_angle{NaN()};
101 uint16_t minimum_speed{0};
102 double max_time{NaN()};
103 uint16_t step_size{0};
104}; // struct Input
105
106class Impl;
107
112class LOB_EXPORT Builder {
113 public:
116 Builder(const Builder& other);
117 Builder(Builder&& other) noexcept;
119 const Builder& rhs);
121 Builder&& rhs) noexcept;
122
146 Builder& DiameterInch(double value);
147
154
160 Builder& BaseDiameterInch(double value);
161
167 Builder& LengthInch(double value);
168
174 Builder& NoseLengthInch(double value);
175
181 Builder& TailLengthInch(double value);
182
188 Builder& OgiveRtR(double value);
189
200 Builder& MachVsDragTable(const float* pmachs, const float* pdrags,
201 size_t size);
211 template <size_t N>
212 Builder& MachVsDragTable(const std::array<float, N>& machs,
213 const std::array<float, N>& drags) {
214 return MachVsDragTable(machs.data(), drags.data(), N);
215 }
216
221 Builder& MassGrains(double value);
227 Builder& InitialVelocityFps(uint16_t value);
249 Builder& ZeroAngleMOA(double value);
255 Builder& ZeroDistanceYds(double value);
275 Builder& AirPressureInHg(double value);
291 Builder& TemperatureDegF(double value);
321 Builder& WindHeadingDeg(double value);
327 Builder& WindSpeedFps(double value);
333 Builder& WindSpeedMph(double value);
340 Builder& AzimuthDeg(double value);
347 Builder& LatitudeDeg(double value);
353 Builder& RangeAngleDeg(double value);
360 Builder& MinimumSpeed(uint16_t value);
361
368 Builder& MinimumEnergy(uint16_t value);
369
376 Builder& MaximumTime(double value);
377
383 Builder& StepSize(uint16_t value);
389
390 private:
391 static constexpr size_t kBufferSize{536};
392 union AlignmentT {
393 double foo;
394 size_t bar;
395 };
396 alignas(AlignmentT) std::array<uint8_t, kBufferSize> buffer_{};
397 Impl* pimpl_{nullptr};
398}; // class Builder
399
403struct LOB_EXPORT Output {
404 uint32_t range{0};
405 uint16_t velocity{0};
406 uint32_t energy{0};
407 double elevation{0.0};
408 double deflection{0.0};
409 double time_of_flight{0.0};
410}; // struct Output
411
420LOB_EXPORT size_t Solve(const Input& in, const uint32_t* pranges, Output* pouts,
421 size_t size);
422
431template <size_t N>
432size_t Solve(const Input& in, const std::array<uint32_t, N>& pranges,
433 std::array<Output, N>& pouts) {
434 return Solve(in, pranges.data(), pouts.data(), N);
435}
436
442LOB_EXPORT double MoaToMil(double value);
443
449LOB_EXPORT double MoaToDeg(double value);
450
456LOB_EXPORT double MoaToIphy(double value);
457
465LOB_EXPORT double MoaToInch(double value, double range_ft);
466
472LOB_EXPORT double MilToMoa(double value);
473
479LOB_EXPORT double MilToDeg(double value);
480
486LOB_EXPORT double MilToIphy(double value);
487
495LOB_EXPORT double MilToInch(double value, double range_ft);
496
502LOB_EXPORT double DegToMoa(double value);
503
509LOB_EXPORT double DegToMil(double value);
510
517LOB_EXPORT double InchToMoa(double value, double range_ft);
518
525LOB_EXPORT double InchToMil(double value, double range_ft);
526
533LOB_EXPORT double InchToDeg(double value, double range_ft);
534
540LOB_EXPORT double JToFtLbs(double value);
541
547LOB_EXPORT double FtLbsToJ(double value);
548
554LOB_EXPORT double MtoYd(double value);
555
561LOB_EXPORT double YdToFt(double value);
562
568LOB_EXPORT double MToFt(double value);
569
575LOB_EXPORT double FtToIn(double value);
576
582LOB_EXPORT double MmToIn(double value);
583
589LOB_EXPORT double CmToIn(double value);
590
596LOB_EXPORT double YdToM(double value);
597
603LOB_EXPORT double FtToM(double value);
604
610LOB_EXPORT double FtToYd(double value);
611
617LOB_EXPORT double InToMm(double value);
618
624LOB_EXPORT double InToCm(double value);
625
631LOB_EXPORT double InToFt(double value);
632
638LOB_EXPORT double PaToInHg(double value);
639
645LOB_EXPORT double MbarToInHg(double value);
646
652LOB_EXPORT double PsiToInHg(double value);
653
659LOB_EXPORT double LbsToGrain(double value);
660
666LOB_EXPORT double GToGrain(double value);
667
673LOB_EXPORT double KgToGrain(double value);
674
680LOB_EXPORT double KgSqMToPmsi(double value);
681
687LOB_EXPORT double FpsToMps(double value);
688
694LOB_EXPORT double MpsToFps(double value);
695
701LOB_EXPORT double KphToMph(double value);
702
708LOB_EXPORT double KnToMph(double value);
709
715LOB_EXPORT double MsToS(double value);
716
722LOB_EXPORT double UsToS(double value);
723
729LOB_EXPORT double SToMs(double value);
730
736LOB_EXPORT double SToUs(double value);
737
743LOB_EXPORT double DegCToDegF(double value);
744
745} // namespace lob
746
747// This file is part of lob.
748//
749// lob is free software: you can redistribute it and/or modify it under the
750// terms of the GNU General Public License as published by the Free Software
751// Foundation, either version 3 of the License, or (at your option) any later
752// version.
753//
754// lob is distributed in the hope that it will be useful, but WITHOUT ANY
755// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
756// A PARTICULAR PURPOSE. See the GNU General Public License for more details.
757//
758// You should have received a copy of the GNU General Public License along with
759// 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:212
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 & 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.
enum LOB_EXPORT kI
two o'clock
Definition lob.hpp:51
constexpr T NaN()
Not-a-Number for floating-point values.
Definition lob.hpp:65
enum LOB_EXPORT kG7
G6 drag function.
Definition lob.hpp:31
enum LOB_EXPORT DragFunctionT
Enumerates the supported drag functions.
Definition lob.hpp:26
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:58
enum LOB_EXPORT kV
six o'clock
Definition lob.hpp:59
LOB_EXPORT double MmToIn(double value)
Converts millimeters to inches.
enum LOB_EXPORT kX
eleven o'clock
Definition lob.hpp:54
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:57
LOB_EXPORT double MtoYd(double value)
Converts meters to yards.
enum LOB_EXPORT AtmosphereReferenceT
Enumerates the supported atmosphere reference types.
Definition lob.hpp:38
enum LOB_EXPORT kII
three 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 kG8
G7 drag function.
Definition lob.hpp:33
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:56
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
LOB_EXPORT double CmToIn(double value)
Converts centimeters to inches.
LOB_EXPORT double KnToMph(double value)
Converts Knots to miles per hour.
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 kG5
G2 drag function.
Definition lob.hpp:29
enum LOB_EXPORT kIV
five o'clock
Definition lob.hpp:61
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:30
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:55
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 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:48
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:53
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:52
Definition lob.hpp:92
double cos_l_sin_a
Coriolis effect parameters.
Definition lob.hpp:93
double sin_l
2Ωcos(latitude)sin(azimuth)
Definition lob.hpp:94
double cos_l_cos_a
2Ωsin(latitude)
Definition lob.hpp:95
Height of the optic above the bore.
Definition lob.hpp:84
double x
Gravity vector.
Definition lob.hpp:85
double y
Acceleration ft/s/s in the x-direction.
Definition lob.hpp:86
Definition lob.hpp:88
double x
Wind vector.
Definition lob.hpp:89
double z
Wind speed in fps in the x-direction.
Definition lob.hpp:90
Structure of input parameters consumed by the solver.
Definition lob.hpp:76
std::array< uint16_t, kTableSize > drags
The size of drag table.
Definition lob.hpp:78
double max_time
Minimum speed for solver.
Definition lob.hpp:102
double spindrift_factor
Aerodynamic jump effect in Moa.
Definition lob.hpp:100
double optic_height
Mass of the projectile in pounds.
Definition lob.hpp:83
double mass
Initial velocity of projectile in Fps.
Definition lob.hpp:82
double zero_angle
Definition lob.hpp:97
double aerodynamic_jump
Miller stability factor.
Definition lob.hpp:99
uint16_t velocity
The local speed of sound in Fps.
Definition lob.hpp:81
uint16_t step_size
Max time of flight for solver.
Definition lob.hpp:103
uint16_t minimum_speed
Spin drift factor.
Definition lob.hpp:101
double table_coefficient
The drag table.
Definition lob.hpp:79
double speed_of_sound
Used to scale the drag table.
Definition lob.hpp:80
double stability_factor
Angle between sight and trajectory.
Definition lob.hpp:98
static constexpr uint8_t kTableSize
Definition lob.hpp:77
Structure holding the output results of the ballistic calculation.
Definition lob.hpp:403
double elevation
Calculated energy in foot-pounds.
Definition lob.hpp:407
uint32_t range
Definition lob.hpp:404
double time_of_flight
Calculated windage deflection in inches.
Definition lob.hpp:409
uint16_t velocity
Associated range in yards.
Definition lob.hpp:405
uint32_t energy
Calculated velocity in feet per second.
Definition lob.hpp:406
double deflection
Calculated elevation change in inches.
Definition lob.hpp:408