Skip to content

Commit d78776c

Browse files
committed
Mostly done with readme
1 parent e13b7a7 commit d78776c

File tree

2 files changed

+130
-8
lines changed

2 files changed

+130
-8
lines changed

README.md

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ A golang port of [geographiclib](https://geographiclib.sourceforge.io/).
1313
- [Short Explanation](#short-explanation-of-library)
1414
- [Long Explanation](#long-explanation-of-library)
1515
- [Library Interface](#the-library-interface)
16-
- [GeographicLib API](#geographiclib-api)
1716
- [Examples](#examples)
1817
- [Progress](#progress)
1918

@@ -145,14 +144,73 @@ Reasonably accurate results can be obtained for $−0.2 \le f \le 0.2$. Here is
145144

146145
Here 1 nm = 1 nanometer = $10^{−9}$ m (not 1 nautical mile!)
147146

148-
## GeographicLib API
149-
150147
## Examples
151-
- [ ] Add Examples to README
152-
- [ ] Examples of direct case on Earth
153-
- [ ] Examples of direct case on Mars
154-
- [ ] Examples of inverse case
155-
- [ ] Examples of calculating an area
148+
```go
149+
package geographiclibgo_test
150+
151+
import (
152+
"fmt"
153+
154+
geodesic "github.com/natemcintosh/geographiclib-go"
155+
)
156+
157+
func Example() {
158+
// Create a struct representing the Earth
159+
earth := geodesic.Wgs84()
160+
161+
// If I start in the middle of Times Square in New York City, and head due West for
162+
// 1000km, where will I end up?
163+
NY_lat := 40.757954
164+
NY_lon := -73.985548
165+
ended_up_at := earth.DirectCalcLatLon(NY_lat, NY_lon, -90, 1000e3)
166+
fmt.Println("Ended up at", ended_up_at)
167+
168+
// Looking on a map, we have ended up in Lafayette Township, a little ways outside
169+
// Indianapolis
170+
171+
// Now let's do the inverse calculation. What is the distance from New York City to
172+
// Chicago?
173+
CHI_lat := 41.882609
174+
CHI_lon := -87.621978
175+
NYC_to_CHI_dist := earth.InverseCalcDistance(NY_lat, NY_lon, CHI_lat, CHI_lon)
176+
fmt.Printf("Distance from NYC to CHI is %0.1f m\n", NYC_to_CHI_dist)
177+
178+
// Wyoming is a fairly rectangular state. Taking its four corners as its boundaries,
179+
// what is its area?
180+
WY_corners_lat_lon := [][2]float64{
181+
{40.997958, -111.046710},
182+
{45.001311, -111.055200},
183+
{44.997380, -104.057699},
184+
{41.001432, -104.053249},
185+
}
186+
polygon := geodesic.NewPolygonArea(earth, false)
187+
for _, corner := range WY_corners_lat_lon {
188+
polygon.AddPoint(corner[0], corner[1])
189+
}
190+
polygon_result := polygon.Compute(true, false)
191+
fmt.Printf("Wyoming area is approximatley %0.0f m^2\n", polygon_result.Area)
192+
193+
// What is the approximate perimeter of Wyoming?
194+
fmt.Printf("Wyoming perimeter is approximately %0.0f m\n", polygon_result.Perimeter)
195+
196+
// But we don't only have to do calculations on Earth. Let's try some on Mars!
197+
mars_equatorial_radius_m := 3396.2e3
198+
mars_flattening_factor := 5.0304e-3
199+
mars := geodesic.NewGeodesic(mars_equatorial_radius_m, mars_flattening_factor)
200+
201+
// What is the distance from Olympus Mons (18.65, -133.8) to the Curiosity Rover's
202+
// landing site (-4.47, 137.42)?
203+
mars_distance := mars.InverseCalcDistance(18.65, -133.8, -4.47, 137.42)
204+
fmt.Printf("Olympus Mons to Curiosity landing site is %0.0f m", mars_distance)
205+
206+
// Output:
207+
// Ended up at {40.15431701948773 -85.75720579845405}
208+
// Distance from NYC to CHI is 1147311.9 m
209+
// Wyoming area is approximatley 253282066939 m^2
210+
// Wyoming perimeter is approximately 2028472 m
211+
// Olympus Mons to Curiosity landing site is 5348380 m
212+
}
213+
```
156214

157215

158216
## Progress

example_test.go

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package geographiclibgo_test
2+
3+
import (
4+
"fmt"
5+
6+
geodesic "github.com/natemcintosh/geographiclib-go"
7+
)
8+
9+
func Example() {
10+
// Create a struct representing the Earth
11+
earth := geodesic.Wgs84()
12+
13+
// If I start in the middle of Times Square in New York City, and head due West for
14+
// 1000km, where will I end up?
15+
NY_lat := 40.757954
16+
NY_lon := -73.985548
17+
ended_up_at := earth.DirectCalcLatLon(NY_lat, NY_lon, -90, 1000e3)
18+
fmt.Println("Ended up at", ended_up_at)
19+
20+
// Looking on a map, we have ended up in Lafayette Township, a little ways outside
21+
// Indianapolis
22+
23+
// Now let's do the inverse calculation. What is the distance from New York City to
24+
// Chicago?
25+
CHI_lat := 41.882609
26+
CHI_lon := -87.621978
27+
NYC_to_CHI_dist := earth.InverseCalcDistance(NY_lat, NY_lon, CHI_lat, CHI_lon)
28+
fmt.Printf("Distance from NYC to CHI is %0.1f m\n", NYC_to_CHI_dist)
29+
30+
// Wyoming is a fairly rectangular state. Taking its four corners as its boundaries,
31+
// what is its area?
32+
WY_corners_lat_lon := [][2]float64{
33+
{40.997958, -111.046710},
34+
{45.001311, -111.055200},
35+
{44.997380, -104.057699},
36+
{41.001432, -104.053249},
37+
}
38+
polygon := geodesic.NewPolygonArea(earth, false)
39+
for _, corner := range WY_corners_lat_lon {
40+
polygon.AddPoint(corner[0], corner[1])
41+
}
42+
polygon_result := polygon.Compute(true, false)
43+
fmt.Printf("Wyoming area is approximatley %0.0f m^2\n", polygon_result.Area)
44+
45+
// What is the approximate perimeter of Wyoming?
46+
fmt.Printf("Wyoming perimeter is approximately %0.0f m\n", polygon_result.Perimeter)
47+
48+
// But we don't only have to do calculations on Earth. Let's try some on Mars!
49+
mars_equatorial_radius_m := 3396.2e3
50+
mars_flattening_factor := 5.0304e-3
51+
mars := geodesic.NewGeodesic(mars_equatorial_radius_m, mars_flattening_factor)
52+
53+
// What is the distance from Olympus Mons (18.65, -133.8) to the Curiosity Rover's
54+
// landing site (-4.47, 137.42)?
55+
mars_distance := mars.InverseCalcDistance(18.65, -133.8, -4.47, 137.42)
56+
fmt.Printf("Olympus Mons to Curiosity landing site is %0.0f m", mars_distance)
57+
58+
// Output:
59+
// Ended up at {40.15431701948773 -85.75720579845405}
60+
// Distance from NYC to CHI is 1147311.9 m
61+
// Wyoming area is approximatley 253282066939 m^2
62+
// Wyoming perimeter is approximately 2028472 m
63+
// Olympus Mons to Curiosity landing site is 5348380 m
64+
}

0 commit comments

Comments
 (0)