Skip to content

Commit

Permalink
Merge pull request #1 from michaelwp/fix-formula
Browse files Browse the repository at this point in the history
fix formula
  • Loading branch information
michaelwp authored Apr 19, 2021
2 parents 7854175 + db49997 commit 2f5d2b5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
17 changes: 16 additions & 1 deletion go_distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package go_distance
import "math"

func (l LatLon) Count() Miles {
var theta = l.LatStart - l.LatEnd
var theta = l.LonStart - l.LonEnd

var dist = math.Sin(Degree(l.LatStart).ToRadians().ToFloat64())*
math.Sin(Degree(l.LatEnd).ToRadians().ToFloat64()) +
Expand All @@ -19,6 +19,21 @@ func (l LatLon) Count() Miles {
return Miles(miles)
}

//func (l LatLon) Count() Miles {
// var earthRadiusMiles = 3.958
//
// var dLat = Degree(l.LatEnd - l.LatStart).ToRadians().ToFloat64()
// var dLon = Degree(l.LonEnd - l.LatStart).ToRadians().ToFloat64()
//
// l.LatStart = Degree(l.LatStart).ToRadians().ToFloat64()
// l.LatEnd = Degree(l.LatEnd).ToRadians().ToFloat64()
//
// var a = math.Sin(dLat/2) * math.Sin(dLat/2) +
// math.Sin(dLon/2)*math.Sin(dLon/2)*math.Cos(l.LatStart)*math.Cos(l.LatEnd)
// var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a))
// return earthRadiusMiles * c
//}

func (deg Degree) ToRadians() Radian {
return Radian(float64(deg) * (math.Pi / 180.0))
}
Expand Down
4 changes: 2 additions & 2 deletions go_distance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func TestLatLon_count(t *testing.T) {
LonStart: 106.6388177,
LatEnd: -6.3027637,
LonEnd: 106.6410986,
}, 0.5238991320272929},
}, 0.40323836641733635},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -94,7 +94,7 @@ func TestMiles_Kilometre(t *testing.T) {
want Kilometre
}{
{"Miles To Kilometres",
0.5238991320272929, 0.8431339247333317},
0.40323836641733635, 0.6489492455635418},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down

0 comments on commit 2f5d2b5

Please sign in to comment.