-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample_03_test.go
More file actions
47 lines (37 loc) · 1.13 KB
/
example_03_test.go
File metadata and controls
47 lines (37 loc) · 1.13 KB
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
package nvector_test
import (
"fmt"
"github.com/ezzatron/nvector-go"
)
// Example 3: ECEF-vector to geodetic latitude
//
// Given an ECEF-vector of a position. Find geodetic latitude, longitude and
// height (using WGS-84 ellipsoid).
//
// See: https://www.ffi.no/en/research/n-vector/#example_3
func Example_n03ECEFToLatLon() {
// PROBLEM:
// Position B is given as an “ECEF-vector” pb (i.e. a vector from E, the
// center of the Earth, to B, decomposed in E):
pb := nvector.Vector{X: 0.71, Y: -0.72, Z: 0.1}.Scale(6371e3)
// Find the geodetic latitude, longitude and height, assuming WGS-84
// ellipsoid.
// SOLUTION:
// Step 1
//
// We have a function that converts ECEF-vectors to n-vectors:
b := nvector.FromECEF(pb, nvector.WGS84, nvector.ZAxisNorth)
// Step 2
//
// Find latitude, longitude and height:
gc := nvector.ToGeodeticCoordinates(b.Vector, nvector.ZAxisNorth)
h := -b.Depth
fmt.Printf(
"Pos B: lat, lon = %.8f, %.8f deg, height = %.8f m\n",
nvector.Degrees(gc.Latitude),
nvector.Degrees(gc.Longitude),
h,
)
// Output:
// Pos B: lat, lon = 5.68507573, -45.40066326 deg, height = 95772.10761822 m
}