@math.gl/geospatial 4.0.0-beta.1 → 4.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +0 -1
- package/dist/constants.js +17 -7
- package/dist/ellipsoid/ellipsoid.d.ts +1 -2
- package/dist/ellipsoid/ellipsoid.js +124 -136
- package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts +2 -3
- package/dist/ellipsoid/helpers/ellipsoid-transform.js +108 -113
- package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts +1 -2
- package/dist/ellipsoid/helpers/scale-to-geodetic-surface.js +64 -60
- package/dist/index.cjs +17 -31
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +2 -3
- package/dist/index.js +0 -1
- package/dist/type-utils.d.ts +3 -4
- package/dist/type-utils.js +77 -51
- package/package.json +5 -6
- package/dist/constants.d.ts.map +0 -1
- package/dist/constants.js.map +0 -1
- package/dist/ellipsoid/ellipsoid.d.ts.map +0 -1
- package/dist/ellipsoid/ellipsoid.js.map +0 -1
- package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts.map +0 -1
- package/dist/ellipsoid/helpers/ellipsoid-transform.js.map +0 -1
- package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts.map +0 -1
- package/dist/ellipsoid/helpers/scale-to-geodetic-surface.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/type-utils.d.ts.map +0 -1
- package/dist/type-utils.js.map +0 -1
package/dist/constants.d.ts
CHANGED
package/dist/constants.js
CHANGED
|
@@ -1,12 +1,22 @@
|
|
|
1
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
1
3
|
export const WGS84_RADIUS_X = 6378137.0;
|
|
2
4
|
export const WGS84_RADIUS_Y = 6378137.0;
|
|
3
5
|
export const WGS84_RADIUS_Z = 6356752.3142451793;
|
|
6
|
+
// Pre-calculated ellipsoid defaults to avoid utils depending on `ellipsoid.js`
|
|
4
7
|
export const WGS84_CONSTANTS = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
|
|
9
|
+
radiiSquared: [
|
|
10
|
+
WGS84_RADIUS_X * WGS84_RADIUS_X,
|
|
11
|
+
WGS84_RADIUS_Y * WGS84_RADIUS_Y,
|
|
12
|
+
WGS84_RADIUS_Z * WGS84_RADIUS_Z
|
|
13
|
+
],
|
|
14
|
+
oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],
|
|
15
|
+
oneOverRadiiSquared: [
|
|
16
|
+
1.0 / (WGS84_RADIUS_X * WGS84_RADIUS_X),
|
|
17
|
+
1.0 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),
|
|
18
|
+
1.0 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)
|
|
19
|
+
],
|
|
20
|
+
maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),
|
|
21
|
+
centerToleranceSquared: 1e-1 // EPSILON1;
|
|
11
22
|
};
|
|
12
|
-
//# sourceMappingURL=constants.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Vector3, Matrix4, NumericArray } from '@math.gl/core';
|
|
2
|
-
import type { AxisDirection } from
|
|
2
|
+
import type { AxisDirection } from "./helpers/ellipsoid-transform.js";
|
|
3
3
|
/**
|
|
4
4
|
* A quadratic surface defined in Cartesian coordinates by the equation
|
|
5
5
|
* `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
|
|
@@ -66,4 +66,3 @@ export declare class Ellipsoid {
|
|
|
66
66
|
/** Computes a point which is the intersection of the surface normal with the z-axis. */
|
|
67
67
|
getSurfaceNormalIntersectionWithZAxis(position: number[], buffer?: number, result?: number[]): number[];
|
|
68
68
|
}
|
|
69
|
-
//# sourceMappingURL=ellipsoid.d.ts.map
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
// This file is derived from the Cesium math library under Apache 2 license
|
|
2
|
+
// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md
|
|
3
|
+
/* eslint-disable */
|
|
2
4
|
import { Vector3, Matrix4, assert, equals, _MathUtils, vec3 } from '@math.gl/core';
|
|
3
5
|
import { WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z } from "../constants.js";
|
|
4
6
|
import { fromCartographicToRadians, toCartographicFromRadians } from "../type-utils.js";
|
|
@@ -10,143 +12,129 @@ const scratchK = new Vector3();
|
|
|
10
12
|
const scratchPosition = new Vector3();
|
|
11
13
|
const scratchHeight = new Vector3();
|
|
12
14
|
const scratchCartesian = new Vector3();
|
|
15
|
+
/**
|
|
16
|
+
* A quadratic surface defined in Cartesian coordinates by the equation
|
|
17
|
+
* `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
|
|
18
|
+
* to represent the shape of planetary bodies.
|
|
19
|
+
*/
|
|
13
20
|
export class Ellipsoid {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
_defineProperty(this, "squaredXOverSquaredZ", void 0);
|
|
32
|
-
|
|
33
|
-
assert(x >= 0.0);
|
|
34
|
-
assert(y >= 0.0);
|
|
35
|
-
assert(z >= 0.0);
|
|
36
|
-
this.radii = new Vector3(x, y, z);
|
|
37
|
-
this.radiiSquared = new Vector3(x * x, y * y, z * z);
|
|
38
|
-
this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
|
|
39
|
-
this.oneOverRadii = new Vector3(x === 0.0 ? 0.0 : 1.0 / x, y === 0.0 ? 0.0 : 1.0 / y, z === 0.0 ? 0.0 : 1.0 / z);
|
|
40
|
-
this.oneOverRadiiSquared = new Vector3(x === 0.0 ? 0.0 : 1.0 / (x * x), y === 0.0 ? 0.0 : 1.0 / (y * y), z === 0.0 ? 0.0 : 1.0 / (z * z));
|
|
41
|
-
this.minimumRadius = Math.min(x, y, z);
|
|
42
|
-
this.maximumRadius = Math.max(x, y, z);
|
|
43
|
-
|
|
44
|
-
if (this.radiiSquared.z !== 0) {
|
|
45
|
-
this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
|
|
21
|
+
constructor(x = 0.0, y = 0.0, z = 0.0) {
|
|
22
|
+
this.centerToleranceSquared = _MathUtils.EPSILON1;
|
|
23
|
+
assert(x >= 0.0);
|
|
24
|
+
assert(y >= 0.0);
|
|
25
|
+
assert(z >= 0.0);
|
|
26
|
+
this.radii = new Vector3(x, y, z);
|
|
27
|
+
this.radiiSquared = new Vector3(x * x, y * y, z * z);
|
|
28
|
+
this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
|
|
29
|
+
this.oneOverRadii = new Vector3(x === 0.0 ? 0.0 : 1.0 / x, y === 0.0 ? 0.0 : 1.0 / y, z === 0.0 ? 0.0 : 1.0 / z);
|
|
30
|
+
this.oneOverRadiiSquared = new Vector3(x === 0.0 ? 0.0 : 1.0 / (x * x), y === 0.0 ? 0.0 : 1.0 / (y * y), z === 0.0 ? 0.0 : 1.0 / (z * z));
|
|
31
|
+
this.minimumRadius = Math.min(x, y, z);
|
|
32
|
+
this.maximumRadius = Math.max(x, y, z);
|
|
33
|
+
if (this.radiiSquared.z !== 0) {
|
|
34
|
+
this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
|
|
35
|
+
}
|
|
36
|
+
Object.freeze(this);
|
|
46
37
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
equals(right) {
|
|
52
|
-
return this === right || Boolean(right && this.radii.equals(right.radii));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
toString() {
|
|
56
|
-
return this.radii.toString();
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
cartographicToCartesian(cartographic, result = [0, 0, 0]) {
|
|
60
|
-
const normal = scratchNormal;
|
|
61
|
-
const k = scratchK;
|
|
62
|
-
const [,, height] = cartographic;
|
|
63
|
-
this.geodeticSurfaceNormalCartographic(cartographic, normal);
|
|
64
|
-
k.copy(this.radiiSquared).scale(normal);
|
|
65
|
-
const gamma = Math.sqrt(normal.dot(k));
|
|
66
|
-
k.scale(1 / gamma);
|
|
67
|
-
normal.scale(height);
|
|
68
|
-
k.add(normal);
|
|
69
|
-
return k.to(result);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
cartesianToCartographic(cartesian, result = [0, 0, 0]) {
|
|
73
|
-
scratchCartesian.from(cartesian);
|
|
74
|
-
const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
|
|
75
|
-
|
|
76
|
-
if (!point) {
|
|
77
|
-
return undefined;
|
|
38
|
+
/** Compares this Ellipsoid against the provided Ellipsoid componentwise */
|
|
39
|
+
equals(right) {
|
|
40
|
+
return this === right || Boolean(right && this.radii.equals(right.radii));
|
|
78
41
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
42
|
+
/** Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'. */
|
|
43
|
+
toString() {
|
|
44
|
+
return this.radii.toString();
|
|
45
|
+
}
|
|
46
|
+
cartographicToCartesian(cartographic, result = [0, 0, 0]) {
|
|
47
|
+
const normal = scratchNormal;
|
|
48
|
+
const k = scratchK;
|
|
49
|
+
const [, , height] = cartographic;
|
|
50
|
+
this.geodeticSurfaceNormalCartographic(cartographic, normal);
|
|
51
|
+
k.copy(this.radiiSquared).scale(normal);
|
|
52
|
+
const gamma = Math.sqrt(normal.dot(k));
|
|
53
|
+
k.scale(1 / gamma);
|
|
54
|
+
normal.scale(height);
|
|
55
|
+
k.add(normal);
|
|
56
|
+
return k.to(result);
|
|
57
|
+
}
|
|
58
|
+
cartesianToCartographic(cartesian, result = [0, 0, 0]) {
|
|
59
|
+
scratchCartesian.from(cartesian);
|
|
60
|
+
const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
|
|
61
|
+
if (!point) {
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
const normal = this.geodeticSurfaceNormal(point, scratchNormal);
|
|
65
|
+
const h = scratchHeight;
|
|
66
|
+
h.copy(scratchCartesian).subtract(point);
|
|
67
|
+
const longitude = Math.atan2(normal.y, normal.x);
|
|
68
|
+
const latitude = Math.asin(normal.z);
|
|
69
|
+
const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
|
|
70
|
+
return toCartographicFromRadians([longitude, latitude, height], result);
|
|
71
|
+
}
|
|
72
|
+
eastNorthUpToFixedFrame(origin, result = new Matrix4()) {
|
|
73
|
+
return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);
|
|
74
|
+
}
|
|
75
|
+
// Computes a 4x4 transformation matrix from a reference frame centered at
|
|
76
|
+
// the provided origin to the ellipsoid's fixed reference frame.
|
|
77
|
+
localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {
|
|
78
|
+
return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
|
|
79
|
+
}
|
|
80
|
+
geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
|
|
81
|
+
return scratchVector.from(cartesian).normalize().to(result);
|
|
82
|
+
}
|
|
83
|
+
geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
|
|
84
|
+
const cartographicVectorRadians = fromCartographicToRadians(cartographic);
|
|
85
|
+
const longitude = cartographicVectorRadians[0];
|
|
86
|
+
const latitude = cartographicVectorRadians[1];
|
|
87
|
+
const cosLatitude = Math.cos(latitude);
|
|
88
|
+
scratchVector
|
|
89
|
+
.set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))
|
|
90
|
+
.normalize();
|
|
91
|
+
return scratchVector.to(result);
|
|
92
|
+
}
|
|
93
|
+
geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
|
|
94
|
+
return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
|
|
95
|
+
}
|
|
96
|
+
/** Scales the provided Cartesian position along the geodetic surface normal
|
|
97
|
+
* so that it is on the surface of this ellipsoid. If the position is
|
|
98
|
+
* at the center of the ellipsoid, this function returns undefined. */
|
|
99
|
+
scaleToGeodeticSurface(cartesian, result) {
|
|
100
|
+
return scaleToGeodeticSurface(cartesian, this, result);
|
|
101
|
+
}
|
|
102
|
+
/** Scales the provided Cartesian position along the geocentric surface normal
|
|
103
|
+
* so that it is on the surface of this ellipsoid. */
|
|
104
|
+
scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
|
|
105
|
+
scratchPosition.from(cartesian);
|
|
106
|
+
const positionX = scratchPosition.x;
|
|
107
|
+
const positionY = scratchPosition.y;
|
|
108
|
+
const positionZ = scratchPosition.z;
|
|
109
|
+
const oneOverRadiiSquared = this.oneOverRadiiSquared;
|
|
110
|
+
const beta = 1.0 /
|
|
111
|
+
Math.sqrt(positionX * positionX * oneOverRadiiSquared.x +
|
|
112
|
+
positionY * positionY * oneOverRadiiSquared.y +
|
|
113
|
+
positionZ * positionZ * oneOverRadiiSquared.z);
|
|
114
|
+
return scratchPosition.multiplyScalar(beta).to(result);
|
|
115
|
+
}
|
|
116
|
+
/** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
|
|
117
|
+
* its components by the result of `Ellipsoid#oneOverRadii` */
|
|
118
|
+
transformPositionToScaledSpace(position, result = [0, 0, 0]) {
|
|
119
|
+
return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
|
|
120
|
+
}
|
|
121
|
+
/** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
|
|
122
|
+
* its components by the result of `Ellipsoid#radii`. */
|
|
123
|
+
transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
|
|
124
|
+
return scratchPosition.from(position).scale(this.radii).to(result);
|
|
125
|
+
}
|
|
126
|
+
/** Computes a point which is the intersection of the surface normal with the z-axis. */
|
|
127
|
+
getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
|
|
128
|
+
// Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)
|
|
129
|
+
assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
|
|
130
|
+
assert(this.radii.z > 0);
|
|
131
|
+
scratchPosition.from(position);
|
|
132
|
+
const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
|
|
133
|
+
if (Math.abs(z) >= this.radii.z - buffer) {
|
|
134
|
+
return undefined;
|
|
135
|
+
}
|
|
136
|
+
return scratchPosition.set(0.0, 0.0, z).to(result);
|
|
144
137
|
}
|
|
145
|
-
|
|
146
|
-
return scratchPosition.set(0.0, 0.0, z).to(result);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
138
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
//# sourceMappingURL=ellipsoid.js.map
|
|
139
|
+
/** An Ellipsoid instance initialized to the WGS84 standard. */
|
|
140
|
+
Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { NumericArray } from '@math.gl/core';
|
|
2
|
-
import type { Ellipsoid } from
|
|
3
|
-
export
|
|
2
|
+
import type { Ellipsoid } from "../ellipsoid.js";
|
|
3
|
+
export type AxisDirection = 'up' | 'down' | 'north' | 'east' | 'south' | 'west';
|
|
4
4
|
export declare function localFrameToFixedFrame(ellipsoid: Ellipsoid, firstAxis: AxisDirection, secondAxis: AxisDirection, thirdAxis: AxisDirection, cartesianOrigin: Readonly<NumericArray>, result: number[]): number[];
|
|
5
|
-
//# sourceMappingURL=ellipsoid-transform.d.ts.map
|
|
@@ -1,129 +1,124 @@
|
|
|
1
1
|
import { Vector3, assert, equals as equalsEpsilon } from '@math.gl/core';
|
|
2
2
|
const EPSILON14 = 1e-14;
|
|
3
3
|
const scratchOrigin = new Vector3();
|
|
4
|
+
// Caclulate third axis from given two axii
|
|
4
5
|
const VECTOR_PRODUCT_LOCAL_FRAME = {
|
|
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
|
-
|
|
6
|
+
up: {
|
|
7
|
+
south: 'east',
|
|
8
|
+
north: 'west',
|
|
9
|
+
west: 'south',
|
|
10
|
+
east: 'north'
|
|
11
|
+
},
|
|
12
|
+
down: {
|
|
13
|
+
south: 'west',
|
|
14
|
+
north: 'east',
|
|
15
|
+
west: 'north',
|
|
16
|
+
east: 'south'
|
|
17
|
+
},
|
|
18
|
+
south: {
|
|
19
|
+
up: 'west',
|
|
20
|
+
down: 'east',
|
|
21
|
+
west: 'down',
|
|
22
|
+
east: 'up'
|
|
23
|
+
},
|
|
24
|
+
north: {
|
|
25
|
+
up: 'east',
|
|
26
|
+
down: 'west',
|
|
27
|
+
west: 'up',
|
|
28
|
+
east: 'down'
|
|
29
|
+
},
|
|
30
|
+
west: {
|
|
31
|
+
up: 'north',
|
|
32
|
+
down: 'south',
|
|
33
|
+
north: 'down',
|
|
34
|
+
south: 'up'
|
|
35
|
+
},
|
|
36
|
+
east: {
|
|
37
|
+
up: 'south',
|
|
38
|
+
down: 'north',
|
|
39
|
+
north: 'up',
|
|
40
|
+
south: 'down'
|
|
41
|
+
}
|
|
41
42
|
};
|
|
42
43
|
const degeneratePositionLocalFrame = {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
north: [-1, 0, 0],
|
|
45
|
+
east: [0, 1, 0],
|
|
46
|
+
up: [0, 0, 1],
|
|
47
|
+
south: [1, 0, 0],
|
|
48
|
+
west: [0, -1, 0],
|
|
49
|
+
down: [0, 0, -1]
|
|
49
50
|
};
|
|
50
51
|
const scratchAxisVectors = {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
52
|
+
east: new Vector3(),
|
|
53
|
+
north: new Vector3(),
|
|
54
|
+
up: new Vector3(),
|
|
55
|
+
west: new Vector3(),
|
|
56
|
+
south: new Vector3(),
|
|
57
|
+
down: new Vector3()
|
|
57
58
|
};
|
|
58
59
|
const scratchVector1 = new Vector3();
|
|
59
60
|
const scratchVector2 = new Vector3();
|
|
60
61
|
const scratchVector3 = new Vector3();
|
|
62
|
+
// Computes a 4x4 transformation matrix from a reference frame
|
|
63
|
+
// centered at the provided origin to the provided ellipsoid's fixed reference frame.
|
|
64
|
+
// eslint-disable-next-line max-statements, max-params, complexity
|
|
61
65
|
export function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
66
|
+
const thirdAxisInferred = VECTOR_PRODUCT_LOCAL_FRAME[firstAxis] && VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
|
|
67
|
+
// firstAxis and secondAxis must be east, north, up, west, south or down.');
|
|
68
|
+
assert(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
|
|
69
|
+
let firstAxisVector;
|
|
70
|
+
let secondAxisVector;
|
|
71
|
+
let thirdAxisVector;
|
|
72
|
+
const origin = scratchOrigin.copy(cartesianOrigin);
|
|
73
|
+
// If x and y are zero, assume origin is at a pole, which is a special case.
|
|
74
|
+
const atPole = equalsEpsilon(origin.x, 0.0, EPSILON14) && equalsEpsilon(origin.y, 0.0, EPSILON14);
|
|
75
|
+
if (atPole) {
|
|
76
|
+
// Look up axis value and adjust
|
|
77
|
+
const sign = Math.sign(origin.z);
|
|
78
|
+
firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
|
|
79
|
+
if (firstAxis !== 'east' && firstAxis !== 'west') {
|
|
80
|
+
firstAxisVector.scale(sign);
|
|
81
|
+
}
|
|
82
|
+
secondAxisVector = scratchVector2.fromArray(degeneratePositionLocalFrame[secondAxis]);
|
|
83
|
+
if (secondAxis !== 'east' && secondAxis !== 'west') {
|
|
84
|
+
secondAxisVector.scale(sign);
|
|
85
|
+
}
|
|
86
|
+
thirdAxisVector = scratchVector3.fromArray(degeneratePositionLocalFrame[thirdAxis]);
|
|
87
|
+
if (thirdAxis !== 'east' && thirdAxis !== 'west') {
|
|
88
|
+
thirdAxisVector.scale(sign);
|
|
89
|
+
}
|
|
82
90
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
91
|
+
else {
|
|
92
|
+
// Calculate all axis
|
|
93
|
+
const { up, east, north } = scratchAxisVectors;
|
|
94
|
+
east.set(-origin.y, origin.x, 0.0).normalize();
|
|
95
|
+
ellipsoid.geodeticSurfaceNormal(origin, up);
|
|
96
|
+
north.copy(up).cross(east);
|
|
97
|
+
const { down, west, south } = scratchAxisVectors;
|
|
98
|
+
down.copy(up).scale(-1);
|
|
99
|
+
west.copy(east).scale(-1);
|
|
100
|
+
south.copy(north).scale(-1);
|
|
101
|
+
// Pick three axis based on desired orientation
|
|
102
|
+
firstAxisVector = scratchAxisVectors[firstAxis];
|
|
103
|
+
secondAxisVector = scratchAxisVectors[secondAxis];
|
|
104
|
+
thirdAxisVector = scratchAxisVectors[thirdAxis];
|
|
88
105
|
}
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
secondAxisVector = scratchAxisVectors[secondAxis];
|
|
108
|
-
thirdAxisVector = scratchAxisVectors[thirdAxis];
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
result[0] = firstAxisVector.x;
|
|
112
|
-
result[1] = firstAxisVector.y;
|
|
113
|
-
result[2] = firstAxisVector.z;
|
|
114
|
-
result[3] = 0.0;
|
|
115
|
-
result[4] = secondAxisVector.x;
|
|
116
|
-
result[5] = secondAxisVector.y;
|
|
117
|
-
result[6] = secondAxisVector.z;
|
|
118
|
-
result[7] = 0.0;
|
|
119
|
-
result[8] = thirdAxisVector.x;
|
|
120
|
-
result[9] = thirdAxisVector.y;
|
|
121
|
-
result[10] = thirdAxisVector.z;
|
|
122
|
-
result[11] = 0.0;
|
|
123
|
-
result[12] = origin.x;
|
|
124
|
-
result[13] = origin.y;
|
|
125
|
-
result[14] = origin.z;
|
|
126
|
-
result[15] = 1.0;
|
|
127
|
-
return result;
|
|
106
|
+
// TODO - assuming the result is column-major
|
|
107
|
+
result[0] = firstAxisVector.x;
|
|
108
|
+
result[1] = firstAxisVector.y;
|
|
109
|
+
result[2] = firstAxisVector.z;
|
|
110
|
+
result[3] = 0.0;
|
|
111
|
+
result[4] = secondAxisVector.x;
|
|
112
|
+
result[5] = secondAxisVector.y;
|
|
113
|
+
result[6] = secondAxisVector.z;
|
|
114
|
+
result[7] = 0.0;
|
|
115
|
+
result[8] = thirdAxisVector.x;
|
|
116
|
+
result[9] = thirdAxisVector.y;
|
|
117
|
+
result[10] = thirdAxisVector.z;
|
|
118
|
+
result[11] = 0.0;
|
|
119
|
+
result[12] = origin.x;
|
|
120
|
+
result[13] = origin.y;
|
|
121
|
+
result[14] = origin.z;
|
|
122
|
+
result[15] = 1.0;
|
|
123
|
+
return result;
|
|
128
124
|
}
|
|
129
|
-
//# sourceMappingURL=ellipsoid-transform.js.map
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { Ellipsoid } from
|
|
1
|
+
import type { Ellipsoid } from "../ellipsoid.js";
|
|
2
2
|
export declare function scaleToGeodeticSurface(cartesian: number[], ellipsoid: Ellipsoid, result?: number[]): number[];
|
|
3
|
-
//# sourceMappingURL=scale-to-geodetic-surface.d.ts.map
|