@@ -13,7 +13,6 @@ A golang port of [geographiclib](https://geographiclib.sourceforge.io/).
13
13
- [ Short Explanation] ( #short-explanation-of-library )
14
14
- [ Long Explanation] ( #long-explanation-of-library )
15
15
- [ Library Interface] ( #the-library-interface )
16
- - [ GeographicLib API] ( #geographiclib-api )
17
16
- [ Examples] ( #examples )
18
17
- [ Progress] ( #progress )
19
18
@@ -145,14 +144,73 @@ Reasonably accurate results can be obtained for $−0.2 \le f \le 0.2$. Here is
145
144
146
145
Here 1 nm = 1 nanometer = $10^{−9}$ m (not 1 nautical mile!)
147
146
148
- ## GeographicLib API
149
-
150
147
## 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
+ ```
156
214
157
215
158
216
## Progress
0 commit comments