Skip to content

Instantly share code, notes, and snippets.

@wthorp
Created January 24, 2021 16:25
Show Gist options
  • Save wthorp/44592eb6841f835505a3a71bc77a61d5 to your computer and use it in GitHub Desktop.
Save wthorp/44592eb6841f835505a3a71bc77a61d5 to your computer and use it in GitHub Desktop.
polynomial approximation of mercator conversion
package main
import (
"fmt"
"math"
"math/rand"
"testing"
)
func main() {
x := testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
ddLat := -855113 + rand.Float64()*(855113*2)
y1 := ddLat / 180 * math.Pi
y2 := math.Log(math.Tan(y1) + (1 / math.Cos(y1)))
wmLat := y2 / math.Pi * 20037508.342789
_ = wmLat
}
})
fmt.Println(x)
//https://www.numberempire.com/taylorseriesexpansion.php
//%pi-log(tan((%pi/4)+(x/2))) =>
//%pi-x-x^3/6-x^5/24-(61*x^7)/5040-(277*x^9)/72576-(50521*x^11)/39916800-(41581*x^13)/95800320
x = testing.Benchmark(func(b *testing.B) {
for i := 0; i < b.N; i++ {
ddLat := -855113 + rand.Float64()*(855113*2)
y1 := ddLat / 180 * math.Pi
y2 := y1 + (math.Pow(y1, 3) / 6) +
(math.Pow(y1, 5) / 24) +
(math.Pow(y1, 7) * 61 / 5040) +
(math.Pow(y1, 9) * 277 / 72576) +
(math.Pow(y1, 11) * 50521 / 39916800) +
(math.Pow(y1, 13) * 41581 / 95800320)
wmLat := y2 / math.Pi * 20037508.342789
_ = wmLat
}
})
fmt.Println(x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment