externalballistics

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 7, 2023 License: LGPL-3.0 Imports: 4 Imported by: 0

README

BallisticCalculator

LGPL library for small arms ballistic calculations

The library provides trajectory calculation for projectiles including for various applications, including air rifles, bows, firearms, artillery and so on.

3DF model that is used in this calculator is rooted in old C sources of version 2 of the public version of JBM calculator, ported to C#, optimized, fixed and extended with elements described in Litz's "Applied Ballistics" book and from the friendly project of Alexandre Trofimov and then ported to Go.

The online version of Go documentation is located here: https://godoc.org/github.com/gehtsoft-usa/go_ballisticcalc

C# version of the package is located here: https://github.com/gehtsoft-usa/BallisticCalculator1

The online version of C# API documentation is located here: https://gehtsoft-usa.github.io/BallisticCalculator/web-content.html

Go documentation can be obtained using godoc tool.

The current status of the project is ALPHA version.

RISK NOTICE

The library performs very limited simulation of a complex physical process and so it performs a lot of approximations. Therefore the calculation results MUST NOT be considered as completely and reliably reflecting actual behavior or characteristics of projectiles. While these results may be used for educational purpose, they must NOT be considered as reliable for the areas where incorrect calculation may cause making a wrong decision, financial harm, or can put a human life at risk.

THE CODE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE MATERIALS OR THE USE OR OTHER DEALINGS IN THE MATERIALS.

Documentation

Index

Constants

View Source
const BC = 1

BC is the type of the ballisic coefficient value: Ballicitic Coefficient

View Source
const DragTableG1 byte = 1

DragTableG1 is identifier for G1 ballistic table

View Source
const DragTableG2 byte = 2

DragTableG2 is identifier for G2 ballistic table

View Source
const DragTableG5 byte = 3

DragTableG5 is identifier for G5 ballistic table

View Source
const DragTableG6 byte = 4

DragTableG6 is identifier for G6 ballistic table

View Source
const DragTableG7 byte = 5

DragTableG7 is identifier for G7 ballistic table

View Source
const DragTableG8 byte = 6

DragTableG8 is identifier for G8 ballistic table

View Source
const DragTableGC byte = 8

DragTableGC for a custom drag table

View Source
const DragTableGS byte = 7

DragTableGS is identifier for GL ballistic table

View Source
const FF = 2

FF is the type of the ballisic coefficient value: Form Factor

View Source
const PIR = 2.08551e-04

PIR = (PI/8)*(RHO0/144)

View Source
const TwistLeft byte = 2

TwistLeft is the flag indiciating that the barrel is left-hand twisted

View Source
const TwistRight byte = 1

TwistRight is the flag indiciating that the barrel is right-hand twisted

Variables

This section is empty.

Functions

func CalculateByCurve

func CalculateByCurve(data []DataPoint, curve []CurvePoint, mach float64) float64

CalculateByCurve calculates a drag value using pretabulted or data data and curve created by CalculateCurve

Types

type Ammunition

type Ammunition struct {
	// contains filtered or unexported fields
}

Ammunition struct keeps the des of ammunition (e.g. projectile loaded into a case shell)

func CreateAmmunition

func CreateAmmunition(bullet Projectile, muzzleVelocity unit.Velocity) Ammunition

CreateAmmunition creates the description of the ammunition

func (Ammunition) Bullet

func (v Ammunition) Bullet() Projectile

Bullet returns the description of the projectile

func (Ammunition) MuzzleVelocity

func (v Ammunition) MuzzleVelocity() unit.Velocity

MuzzleVelocity returns the velocity of the projectile at the muzzle

type Atmosphere

type Atmosphere struct {
	// contains filtered or unexported fields
}

Atmosphere describes the atmosphere conditions

func CreateAtmosphere

func CreateAtmosphere(altitude unit.Distance, pressure unit.Pressure, temperature unit.Temperature, humidity float64) (Atmosphere, error)

CreateAtmosphere creates the atmosphere with the specified parameter

func CreateDefaultAtmosphere

func CreateDefaultAtmosphere() Atmosphere

CreateDefaultAtmosphere creates a default atmosphere used in ballistic calculations

func CreateICAOAtmosphere

func CreateICAOAtmosphere(altitude unit.Distance) Atmosphere

CreateICAOAtmosphere creates default ICAO atmosphere for the specified altitude

func (Atmosphere) Altitude

func (a Atmosphere) Altitude() unit.Distance

Altitude returns the ground level altitude over the sea level

func (Atmosphere) Humidity

func (a Atmosphere) Humidity() float64

Humidity returns the relative humidity set in 0 to 1 coefficient

multiply this value by 100 to get percents

func (Atmosphere) HumidityInPercents

func (a Atmosphere) HumidityInPercents() float64

HumidityInPercents returns relative humidity in percents (0..100)

func (Atmosphere) Mach

func (a Atmosphere) Mach() unit.Velocity

Mach returns the speed of sound at the atmosphere with such parameters

func (Atmosphere) Pressure

func (a Atmosphere) Pressure() unit.Pressure

Pressure returns the pressure at the ground level

func (Atmosphere) String

func (a Atmosphere) String() string

func (Atmosphere) Temperature

func (a Atmosphere) Temperature() unit.Temperature

Temperature returns the temperature at the ground level

type BallisticCoefficient

type BallisticCoefficient struct {
	// contains filtered or unexported fields
}

BallisticCoefficient keeps data about ballistic coefficient of a projectile

The ballistic coefficient (BC) of a body is a measure of its ability to overcome air resistance in flight.

The small arm ballistics, BC is expressed vs a standard projectile. Different ballistic tables uses different standard projectiles, for example G1 uses flat based 2 caliber length with a 2 caliber ogive

G1 and G7 are the most used for small arms ballistics

func CreateBallisticCoefficient

func CreateBallisticCoefficient(value float64, dragTable byte) (BallisticCoefficient, error)

CreateBallisticCoefficient creates ballistic coefficient object using the ballistic coefficient value and ballistic table.

func CreateBallisticCoefficientForCustomDragFunction

func CreateBallisticCoefficientForCustomDragFunction(value float64, valueType byte, dragTable dragFunction) (BallisticCoefficient, error)

CreateBallisticCoefficient creates ballistic coefficient object using the the custom drag function

func (BallisticCoefficient) Drag

func (v BallisticCoefficient) Drag(mach float64) float64

Drag calculates the aerodynamic drag (deceleration factor) calculated for the speed expressed in mach (speed of sound)

func (BallisticCoefficient) Table

func (v BallisticCoefficient) Table() byte

Table return the name of the ballistic table

func (BallisticCoefficient) Value

func (v BallisticCoefficient) Value() float64

Value returns the ballistic coefficient value

func (BallisticCoefficient) ValueType

func (v BallisticCoefficient) ValueType() byte

ValueType returns the ballistic coefficient value type (BC or FF)

type CurvePoint

type CurvePoint struct {
	A, B, C float64
}

CurvePoint is an approximation of drag to speed function curve made on the base of the ballistic

func CalculateCurve

func CalculateCurve(dataPoints []DataPoint) []CurvePoint

CalculateCurve calculates a curve for CalculateByCurve function using pretabulated or radar data

type DataPoint

type DataPoint struct {
	A, B float64
}

DataPoint is one value of the ballistic table used in table-based calculations below

The calculation is based on original JavaScript code by Alexandre Trofimov

type Projectile

type Projectile struct {
	// contains filtered or unexported fields
}

Projectile keeps description of a projectile

func CreateProjectile

func CreateProjectile(ballisticCoefficient BallisticCoefficient,
	weight unit.Weight) Projectile

CreateProjectile create projectile description without dimensions.

If no dimensions set, the trajectory calculator won't be able to calculate spin drift.

func CreateProjectileWithDimensions

func CreateProjectileWithDimensions(ballisticCoefficient BallisticCoefficient,
	bulletDiameter unit.Distance,
	bulletLength unit.Distance,
	weight unit.Weight) Projectile

CreateProjectileWithDimensions creates the description of a projectile with dimensions (diameter and length)

Dimensions are only required if you want to take into account projectile spin drift. TwistInfo must be also set in this case.

func (Projectile) BallisticCoefficient

func (v Projectile) BallisticCoefficient() BallisticCoefficient

BallisticCoefficient returns ballistic coefficient of the projectile

func (Projectile) BulletDiameter

func (v Projectile) BulletDiameter() unit.Distance

BulletDiameter returns the diameter (caliber) of the projectile

func (Projectile) BulletLength

func (v Projectile) BulletLength() unit.Distance

BulletLength return the length of the bullet

func (Projectile) BulletWeight

func (v Projectile) BulletWeight() unit.Weight

BulletWeight returns weight of the projectile

func (Projectile) GetBallisticCoefficient

func (v Projectile) GetBallisticCoefficient() float64

func (Projectile) HasDimensions

func (v Projectile) HasDimensions() bool

HasDimensions returns the flag indicating whether the projectile has dimensions set

type ShotParameters

type ShotParameters struct {
	// contains filtered or unexported fields
}

ShotParameters struct keeps parameters of the shot to be calculated

func CreateShotParameterUnlevel

func CreateShotParameterUnlevel(sightAngle unit.Angular, maxDistance unit.Distance, step unit.Distance, shotAngle unit.Angular, cantAngle unit.Angular) ShotParameters

CreateShotParameterUnlevel creates the parameter of the shot aimed at the target which is not on th same level as the shooter

sightAngle - is the angle between scope centerline and the barrel centerline

shotAngle - is the angle between lines drawn from the shooter to the target and the horizon. The positive angle means that the target is higher and the negative angle means that the target is lower

func CreateShotParameters

func CreateShotParameters(sightAngle unit.Angular, maxDistance unit.Distance, step unit.Distance) ShotParameters

CreateShotParameters creates parameters of the shot

sightAngle - is the angle between scope centerline and the barrel centerline

func (ShotParameters) CantAngle

func (v ShotParameters) CantAngle() unit.Angular

CantAngle returns the cant angle (the angle between centers of scope and the barrel projection and zenith line)

func (ShotParameters) MaximumDistance

func (v ShotParameters) MaximumDistance() unit.Distance

MaximumDistance returns the maximum distance to be calculated

func (ShotParameters) ShotAngle

func (v ShotParameters) ShotAngle() unit.Angular

ShotAngle returns the angle of the short

func (ShotParameters) SightAngle

func (v ShotParameters) SightAngle() unit.Angular

SightAngle returns the angle of the sight

func (ShotParameters) Step

func (v ShotParameters) Step() unit.Distance

Step returns the step between calculation results

type Timespan

type Timespan struct {
	// contains filtered or unexported fields
}

Timespan keeps the amount of time spent

func (Timespan) Minutes

func (v Timespan) Minutes() float64

Minutes return the whole number of minutes

func (Timespan) Seconds

func (v Timespan) Seconds() float64

Seconds return the whole number of the seconds

func (Timespan) TotalSeconds

func (v Timespan) TotalSeconds() float64

TotalSeconds returns the total number of seconds

type TrajectoryCalculator

type TrajectoryCalculator struct {
	// contains filtered or unexported fields
}

TrajectoryCalculator table is used to calculate the trajectory of a projectile shot with the parameters specified

func CreateTrajectoryCalculator

func CreateTrajectoryCalculator() TrajectoryCalculator

CreateTrajectoryCalculator creates and instance of the trajectory calculator

func (TrajectoryCalculator) MaximumCalculatorStepSize

func (v TrajectoryCalculator) MaximumCalculatorStepSize() unit.Distance

MaximumCalculatorStepSize returns the maximum size of one calculation iteration.

func (*TrajectoryCalculator) SetMaximumCalculatorStepSize

func (v *TrajectoryCalculator) SetMaximumCalculatorStepSize(x unit.Distance)

SetMaximumCalculatorStepSize sets the maximum size of one calculation iteration.

As the generic rule, the maximum step of the calculation must not be greater than a half of the step used in the short parameter. The smaller value is, the calculation is more precise but takes more time to calculate. From practical standpoint the value in range from 0.5 to 5 feet produces good enough accuracy.

func (TrajectoryCalculator) SightAngle

func (v TrajectoryCalculator) SightAngle(ammunition Ammunition, weapon Weapon, atmosphere Atmosphere) unit.Angular

SightAngle calculates the sight angle for a rifle with scope height specified and zeroed using the ammo specified at the range specified and under the conditions (atmosphere) specified.

The calculated value is to be used as sightAngle parameter of the ShotParameters structure

func (TrajectoryCalculator) Trajectory

func (v TrajectoryCalculator) Trajectory(ammunition Ammunition, weapon Weapon, atmosphere Atmosphere, shotInfo ShotParameters, windInfo []WindInfo) []TrajectoryData

Trajectory calculates the trajectory with the parameters specified

type TrajectoryData

type TrajectoryData struct {
	// contains filtered or unexported fields
}

TrajectoryData structure keeps information about one point of the trajectory.

func (TrajectoryData) Drop

func (v TrajectoryData) Drop() unit.Distance

Drop returns the shorted distance between the projectile and the shot line

The positive value means the the projectile is above this line and the negative value means that the projectile is below this line

func (TrajectoryData) DropAdjustment

func (v TrajectoryData) DropAdjustment() unit.Angular

DropAdjustment returns the angle between the shot line and the line from the muzzle to the current projectile position in the plane perpendicular to the ground

func (TrajectoryData) Energy

func (v TrajectoryData) Energy() unit.Energy

Energy returns the kinetic energy of the projectile

func (TrajectoryData) MachVelocity

func (v TrajectoryData) MachVelocity() float64

MachVelocity returns the proportion between the current projectile velocity and the speed of the sound

func (TrajectoryData) OptimalGameWeight

func (v TrajectoryData) OptimalGameWeight() unit.Weight

OptimalGameWeight returns the weight of game to which a kill shot is probable with the kinetic energy that the projectile currently have

func (TrajectoryData) Time

func (v TrajectoryData) Time() Timespan

Time return the amount of time spent since the shot moment

func (TrajectoryData) TravelledDistance

func (v TrajectoryData) TravelledDistance() unit.Distance

TravelledDistance returns the distance measured between the muzzle and the projection of the current bullet position to the line between the muzzle and the target

func (TrajectoryData) Velocity

func (v TrajectoryData) Velocity() unit.Velocity

Velocity returns the current projectile velocity

func (TrajectoryData) Windage

func (v TrajectoryData) Windage() unit.Distance

Windage returns the distance to which the projectile is displaced by wind

func (TrajectoryData) WindageAdjustment

func (v TrajectoryData) WindageAdjustment() unit.Angular

WindageAdjustment returns the angle between the shot line and the line from the muzzle to the current projectile position in the place parallel to the ground

type TwistInfo

type TwistInfo struct {
	// contains filtered or unexported fields
}

TwistInfo contains the rifling twist information

The rifling twist is used to calculate spin drift only

func CreateTwist

func CreateTwist(direction byte, twist unit.Distance) TwistInfo

CreateTwist creates twist information

Direction must be either Twist_Right or Twist_Left constant

func (TwistInfo) Direction

func (v TwistInfo) Direction() byte

Direction returns the twist direction (see TwistRight and TwistLeft)

func (TwistInfo) Twist

func (v TwistInfo) Twist() unit.Distance

Twist returns the twist step (the distance inside the barrel at which the projectile makes one turn)

type Weapon

type Weapon struct {
	// contains filtered or unexported fields
}

Weapon struct contains the weapon description

func CreateWeapon

func CreateWeapon(sightHeight unit.Distance, zeroInfo ZeroInfo) Weapon

CreateWeapon creates the weapon definition with no twist info

If no twist info is set, spin drift won't be calculated

func CreateWeaponWithTwist

func CreateWeaponWithTwist(sightHeight unit.Distance, zeroInfo ZeroInfo, twist TwistInfo) Weapon

CreateWeaponWithTwist creates weapon description with twist info

If twist info AND bullet dimensions are set, spin drift will be calculated

func (Weapon) ClickValue

func (v Weapon) ClickValue() unit.Angular

ClickValue returns the value of one click of the scope

func (Weapon) HasTwist

func (v Weapon) HasTwist() bool

HasTwist returns the flag indicating whether the rifling twist information is set

func (*Weapon) SetClickValue

func (v *Weapon) SetClickValue(click unit.Angular)

SetClickValue sets the value of one click of the scope

func (Weapon) SightHeight

func (v Weapon) SightHeight() unit.Distance

SightHeight returns the height of the sight centerline over the barrel centerline

func (Weapon) Twist

func (v Weapon) Twist() TwistInfo

Twist returns the rifling twist information

func (Weapon) Zero

func (v Weapon) Zero() ZeroInfo

Zero returns the zeroing information

type WindInfo

type WindInfo struct {
	// contains filtered or unexported fields
}

WindInfo structure keeps information about wind

func AddWindInfo

func AddWindInfo(untilRange unit.Distance, windVelocity unit.Velocity, direction unit.Angular) WindInfo

AddWindInfo creates description of one wind

func CreateNoWind

func CreateNoWind() []WindInfo

CreateNoWind creates wind description with no wind

func CreateOnlyWindInfo

func CreateOnlyWindInfo(windVelocity unit.Velocity, direction unit.Angular) []WindInfo

CreateOnlyWindInfo creates the wind information for the constant wind for the whole distance of the shot

func CreateWindInfo

func CreateWindInfo(winds ...WindInfo) []WindInfo

CreateWindInfo creates a wind descriptor from multiple winds

winds must be ordered from the closest to the muzzlepoint to the farest to the muzzlepoint

func (WindInfo) Direction

func (v WindInfo) Direction() unit.Angular

Direction returns the wind direction.

0 degrees means wind blowing into the face 90 degrees means wind blowing from the left -90 or 270 degrees means wind blowing from the right 180 degrees means wind blowing from the back

func (WindInfo) UntilDistance

func (v WindInfo) UntilDistance() unit.Distance

UntilDistance returns the distance from the shooter until which the wind blows

func (WindInfo) Velocity

func (v WindInfo) Velocity() unit.Velocity

Velocity returns the wind velocity

type ZeroInfo

type ZeroInfo struct {
	// contains filtered or unexported fields
}

ZeroInfo structure keeps the information about zeroing of the weapon

func CreateZeroInfo

func CreateZeroInfo(distance unit.Distance) ZeroInfo

CreateZeroInfo creates zero information using distance only

func CreateZeroInfoWithAnotherAmmo

func CreateZeroInfoWithAnotherAmmo(distance unit.Distance, ammo Ammunition) ZeroInfo

CreateZeroInfoWithAnotherAmmo creates zero information using distance and other ammunition

func CreateZeroInfoWithAnotherAmmoAndAtmosphere

func CreateZeroInfoWithAnotherAmmoAndAtmosphere(distance unit.Distance, ammo Ammunition, atmosphere Atmosphere) ZeroInfo

CreateZeroInfoWithAnotherAmmoAndAtmosphere creates zero information using distance, other conditions and other ammunition

func CreateZeroInfoWithAtmosphere

func CreateZeroInfoWithAtmosphere(distance unit.Distance, atmosphere Atmosphere) ZeroInfo

CreateZeroInfoWithAtmosphere creates zero information using distance and conditions

func (ZeroInfo) Ammunition

func (v ZeroInfo) Ammunition() Ammunition

Ammunition return ammo used to zero

func (ZeroInfo) Atmosphere

func (v ZeroInfo) Atmosphere() Atmosphere

Atmosphere returns conditions at the time of zeroing

func (ZeroInfo) HasAmmunition

func (v ZeroInfo) HasAmmunition() bool

HasAmmunition return flag indicating whether other ammo is used to zero

func (ZeroInfo) HasAtmosphere

func (v ZeroInfo) HasAtmosphere() bool

HasAtmosphere returns flag indicating whether weapon is zeroed under different conditions

func (ZeroInfo) ZeroDistance

func (v ZeroInfo) ZeroDistance() unit.Distance

ZeroDistance returns the distance at which the weapon was zeroed

Directories

Path Synopsis
unit
Package unit consists of the helper classes for all measurement unit that are used in trajectory calculation - e.g.
Package unit consists of the helper classes for all measurement unit that are used in trajectory calculation - e.g.
vector
Package vector provides simple operations on 3d vector required for 3DF trajectory calculation
Package vector provides simple operations on 3d vector required for 3DF trajectory calculation

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL