-
Notifications
You must be signed in to change notification settings - Fork 3
/
Projectile.go
98 lines (83 loc) · 2.93 KB
/
Projectile.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package externalballistics
import (
"math"
"github.com/gehtsoft-usa/go_ballisticcalc/bmath/unit"
)
//Projectile keeps description of a projectile
type Projectile struct {
ballisticCoefficient BallisticCoefficient
weight unit.Weight
hasDimensions bool
bulletDiameter unit.Distance
bulletLength unit.Distance
}
//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 CreateProjectileWithDimensions(ballisticCoefficient BallisticCoefficient,
bulletDiameter unit.Distance,
bulletLength unit.Distance,
weight unit.Weight) Projectile {
return Projectile{ballisticCoefficient: ballisticCoefficient,
hasDimensions: true,
bulletDiameter: bulletDiameter,
bulletLength: bulletLength,
weight: weight}
}
//CreateProjectile create projectile description without dimensions.
//
//If no dimensions set, the trajectory calculator won't be able to calculate spin drift.
func CreateProjectile(ballisticCoefficient BallisticCoefficient,
weight unit.Weight) Projectile {
return Projectile{ballisticCoefficient: ballisticCoefficient,
hasDimensions: false,
weight: weight}
}
//BallisticCoefficient returns ballistic coefficient of the projectile
func (v Projectile) BallisticCoefficient() BallisticCoefficient {
return v.ballisticCoefficient
}
//BulletWeight returns weight of the projectile
func (v Projectile) BulletWeight() unit.Weight {
return v.weight
}
//BulletDiameter returns the diameter (caliber) of the projectile
func (v Projectile) BulletDiameter() unit.Distance {
return v.bulletDiameter
}
//BulletLength return the length of the bullet
func (v Projectile) BulletLength() unit.Distance {
return v.bulletLength
}
//HasDimensions returns the flag indicating whether the projectile
//has dimensions set
func (v Projectile) HasDimensions() bool {
return v.hasDimensions
}
func (v Projectile) GetBallisticCoefficient() float64 {
if v.ballisticCoefficient.valueType == BC {
return v.ballisticCoefficient.value
}
return v.weight.In(unit.WeightGrain) / 7000.0 / math.Pow(v.bulletDiameter.In(unit.DistanceInch), 2) / v.ballisticCoefficient.value
}
//Ammunition struct keeps the des of ammunition (e.g. projectile loaded into a case shell)
type Ammunition struct {
projectile Projectile
muzzleVelocity unit.Velocity
}
//CreateAmmunition creates the description of the ammunition
func CreateAmmunition(bullet Projectile, muzzleVelocity unit.Velocity) Ammunition {
return Ammunition{
projectile: bullet,
muzzleVelocity: muzzleVelocity,
}
}
//Bullet returns the description of the projectile
func (v Ammunition) Bullet() Projectile {
return v.projectile
}
//MuzzleVelocity returns the velocity of the projectile at the muzzle
func (v Ammunition) MuzzleVelocity() unit.Velocity {
return v.muzzleVelocity
}