@math.gl/geospatial 3.5.6 → 3.6.0-alpha.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.
Files changed (56) hide show
  1. package/dist/constants.d.ts +12 -0
  2. package/dist/constants.d.ts.map +1 -0
  3. package/dist/constants.js +22 -0
  4. package/dist/ellipsoid/ellipsoid.d.ts +68 -0
  5. package/dist/ellipsoid/ellipsoid.d.ts.map +1 -0
  6. package/dist/ellipsoid/ellipsoid.js +132 -0
  7. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts +2 -0
  8. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts.map +1 -0
  9. package/dist/ellipsoid/helpers/ellipsoid-transform.js +124 -0
  10. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts +3 -0
  11. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.d.ts.map +1 -0
  12. package/dist/ellipsoid/helpers/scale-to-geodetic-surface.js +70 -0
  13. package/dist/es5/constants.js +4 -4
  14. package/dist/es5/constants.js.map +1 -1
  15. package/dist/es5/ellipsoid/ellipsoid.js +123 -161
  16. package/dist/es5/ellipsoid/ellipsoid.js.map +1 -1
  17. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js +25 -21
  18. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  19. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js +39 -46
  20. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  21. package/dist/es5/index.js +2 -2
  22. package/dist/es5/index.js.map +1 -1
  23. package/dist/es5/type-utils.js +13 -19
  24. package/dist/es5/type-utils.js.map +1 -1
  25. package/dist/esm/constants.js.map +1 -1
  26. package/dist/esm/ellipsoid/ellipsoid.js +22 -7
  27. package/dist/esm/ellipsoid/ellipsoid.js.map +1 -1
  28. package/dist/esm/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  29. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js +1 -2
  30. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  31. package/dist/esm/index.js.map +1 -1
  32. package/dist/esm/type-utils.js +3 -3
  33. package/dist/esm/type-utils.js.map +1 -1
  34. package/dist/index.d.ts +3 -0
  35. package/dist/index.d.ts.map +1 -0
  36. package/dist/index.js +2 -0
  37. package/dist/type-utils.d.ts +24 -0
  38. package/dist/type-utils.d.ts.map +1 -0
  39. package/dist/type-utils.js +94 -0
  40. package/package.json +4 -4
  41. package/src/{constants.js → constants.ts} +0 -0
  42. package/src/ellipsoid/{ellipsoid.js → ellipsoid.ts} +96 -35
  43. package/src/ellipsoid/helpers/{ellipsoid-transform.js → ellipsoid-transform.ts} +0 -0
  44. package/src/ellipsoid/helpers/{scale-to-geodetic-surface.js → scale-to-geodetic-surface.ts} +0 -0
  45. package/src/{index.js → index.ts} +0 -0
  46. package/src/type-utils.ts +143 -0
  47. package/dist/es5/ellipsoid/ellipsoid.d.ts +0 -95
  48. package/dist/es5/index.d.ts +0 -1
  49. package/dist/es5/type-utils.d.ts +0 -55
  50. package/dist/esm/ellipsoid/ellipsoid.d.ts +0 -95
  51. package/dist/esm/index.d.ts +0 -1
  52. package/dist/esm/type-utils.d.ts +0 -55
  53. package/src/ellipsoid/ellipsoid.d.ts +0 -95
  54. package/src/index.d.ts +0 -1
  55. package/src/type-utils.d.ts +0 -55
  56. package/src/type-utils.js +0 -71
@@ -0,0 +1,12 @@
1
+ export declare const WGS84_RADIUS_X = 6378137;
2
+ export declare const WGS84_RADIUS_Y = 6378137;
3
+ export declare const WGS84_RADIUS_Z = 6356752.314245179;
4
+ export declare const WGS84_CONSTANTS: {
5
+ radii: number[];
6
+ radiiSquared: number[];
7
+ oneOverRadii: number[];
8
+ oneOverRadiiSquared: number[];
9
+ maximumRadius: number;
10
+ centerToleranceSquared: number;
11
+ };
12
+ //# sourceMappingURL=constants.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,cAAc,UAAY,CAAC;AACxC,eAAO,MAAM,cAAc,UAAY,CAAC;AACxC,eAAO,MAAM,cAAc,oBAAqB,CAAC;AAIjD,eAAO,MAAM,eAAe;;;;;;;CAe3B,CAAC"}
@@ -0,0 +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
3
+ export const WGS84_RADIUS_X = 6378137.0;
4
+ export const WGS84_RADIUS_Y = 6378137.0;
5
+ export const WGS84_RADIUS_Z = 6356752.3142451793;
6
+ // Pre-calculated ellipsoid defaults to avoid utils depending on `ellipsoid.js`
7
+ export const WGS84_CONSTANTS = {
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;
22
+ };
@@ -0,0 +1,68 @@
1
+ import { Vector3, Matrix4, NumericArray } from '@math.gl/core';
2
+ /**
3
+ * A quadratic surface defined in Cartesian coordinates by the equation
4
+ * `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
5
+ * to represent the shape of planetary bodies.
6
+ */
7
+ export default class Ellipsoid {
8
+ /** An Ellipsoid instance initialized to the WGS84 standard. */
9
+ static readonly WGS84: Ellipsoid;
10
+ readonly radii: Vector3;
11
+ readonly radiiSquared: Vector3;
12
+ readonly radiiToTheFourth: Vector3;
13
+ readonly oneOverRadii: Vector3;
14
+ readonly oneOverRadiiSquared: Vector3;
15
+ readonly minimumRadius: number;
16
+ readonly maximumRadius: number;
17
+ readonly centerToleranceSquared: number;
18
+ readonly squaredXOverSquaredZ: number;
19
+ /** Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions. */
20
+ constructor(x: number, y: number, z: number);
21
+ constructor();
22
+ /** Compares this Ellipsoid against the provided Ellipsoid componentwise */
23
+ equals(right: Ellipsoid): boolean;
24
+ /** Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'. */
25
+ toString(): string;
26
+ /** Converts the provided cartographic to Cartesian representation. */
27
+ cartographicToCartesian(cartographic: number[], result: Vector3): Vector3;
28
+ cartographicToCartesian(cartographic: number[], result?: number[]): number[];
29
+ /** Converts the provided cartesian to cartographic (lng/lat/z) representation.
30
+ * The cartesian is undefined at the center of the ellipsoid. */
31
+ cartesianToCartographic(cartesian: number[], result: Vector3): Vector3;
32
+ cartesianToCartographic(cartesian: number[], result?: number[]): number[];
33
+ /** Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes
34
+ * centered at the provided origin to the provided ellipsoid's fixed reference frame. */
35
+ eastNorthUpToFixedFrame(origin: number[], result?: Matrix4): Matrix4;
36
+ eastNorthUpToFixedFrame(origin: number[], result: number[]): number[];
37
+ /** Computes a 4x4 transformation matrix from a reference frame centered at
38
+ * the provided origin to the ellipsoid's fixed reference frame.
39
+ */
40
+ localFrameToFixedFrame(firstAxis: string, secondAxis: string, thirdAxis: string, origin: Readonly<NumericArray>, result?: Matrix4): Matrix4;
41
+ localFrameToFixedFrame<Matrix4T>(firstAxis: string, secondAxis: string, thirdAxis: string, origin: Readonly<NumericArray>, result: number[]): number[];
42
+ /** Computes the unit vector directed from the center of this ellipsoid toward
43
+ * the provided Cartesian position. */
44
+ geocentricSurfaceNormal(cartesian: number[], result?: number[]): number[];
45
+ geocentricSurfaceNormal<NumArray>(cartesian: number[], result: NumArray): NumArray;
46
+ /** Computes the normal of the plane tangent to the surface of the ellipsoid at provided position. */
47
+ geodeticSurfaceNormalCartographic<NumArray>(cartographic: number[], result: NumArray): NumArray;
48
+ geodeticSurfaceNormalCartographic(cartographic: number[]): number[];
49
+ /** Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position. */
50
+ geodeticSurfaceNormal<NumArrayT>(cartesian: number[], result: NumArrayT): NumArrayT;
51
+ geodeticSurfaceNormal(cartesian: number[]): number[];
52
+ /** Scales the provided Cartesian position along the geodetic surface normal
53
+ * so that it is on the surface of this ellipsoid. If the position is
54
+ * at the center of the ellipsoid, this function returns undefined. */
55
+ scaleToGeodeticSurface(cartesian: number[], result?: number[]): number[];
56
+ /** Scales the provided Cartesian position along the geocentric surface normal
57
+ * so that it is on the surface of this ellipsoid. */
58
+ scaleToGeocentricSurface(cartesian: number[], result?: number[]): number[];
59
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
60
+ * its components by the result of `Ellipsoid#oneOverRadii` */
61
+ transformPositionToScaledSpace(position: number[], result?: number[]): number[];
62
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
63
+ * its components by the result of `Ellipsoid#radii`. */
64
+ transformPositionFromScaledSpace(position: number[], result?: number[]): number[];
65
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
66
+ getSurfaceNormalIntersectionWithZAxis(position: number[], buffer?: number, result?: number[]): number[];
67
+ }
68
+ //# sourceMappingURL=ellipsoid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ellipsoid.d.ts","sourceRoot":"","sources":["../../src/ellipsoid/ellipsoid.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,OAAO,E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AM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAoB1E;kEAC8D;IAC9D,8BAA8B,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAK/E;4DACwD;IACxD,gCAAgC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAKjF,wFAAwF;IACxF,qCAAqC,CACnC,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,CAAC,EAAE,MAAM,EACf,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,MAAM,EAAE;CAeZ"}
@@ -0,0 +1,132 @@
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 */
4
+ import { Vector3, Matrix4, assert, equals, _MathUtils } from '@math.gl/core';
5
+ import * as vec3 from 'gl-matrix/vec3';
6
+ import { WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z } from '../constants';
7
+ import { fromCartographicToRadians, toCartographicFromRadians } from '../type-utils';
8
+ import scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';
9
+ import localFrameToFixedFrame from './helpers/ellipsoid-transform';
10
+ const scratchVector = new Vector3();
11
+ const scratchNormal = new Vector3();
12
+ const scratchK = new Vector3();
13
+ const scratchPosition = new Vector3();
14
+ const scratchHeight = new Vector3();
15
+ const scratchCartesian = new Vector3();
16
+ let wgs84;
17
+ /**
18
+ * A quadratic surface defined in Cartesian coordinates by the equation
19
+ * `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used
20
+ * to represent the shape of planetary bodies.
21
+ */
22
+ export default class Ellipsoid {
23
+ constructor(x = 0.0, y = 0.0, z = 0.0) {
24
+ this.centerToleranceSquared = _MathUtils.EPSILON1;
25
+ assert(x >= 0.0);
26
+ assert(y >= 0.0);
27
+ assert(z >= 0.0);
28
+ this.radii = new Vector3(x, y, z);
29
+ this.radiiSquared = new Vector3(x * x, y * y, z * z);
30
+ this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);
31
+ 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);
32
+ 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));
33
+ this.minimumRadius = Math.min(x, y, z);
34
+ this.maximumRadius = Math.max(x, y, z);
35
+ if (this.radiiSquared.z !== 0) {
36
+ this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
37
+ }
38
+ Object.freeze(this);
39
+ }
40
+ /** Compares this Ellipsoid against the provided Ellipsoid componentwise */
41
+ equals(right) {
42
+ return this === right || Boolean(right && this.radii.equals(right.radii));
43
+ }
44
+ /** Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'. */
45
+ toString() {
46
+ return this.radii.toString();
47
+ }
48
+ cartographicToCartesian(cartographic, result = [0, 0, 0]) {
49
+ const normal = scratchNormal;
50
+ const k = scratchK;
51
+ const [, , height] = cartographic;
52
+ this.geodeticSurfaceNormalCartographic(cartographic, normal);
53
+ k.copy(this.radiiSquared).scale(normal);
54
+ const gamma = Math.sqrt(normal.dot(k));
55
+ k.scale(1 / gamma);
56
+ normal.scale(height);
57
+ k.add(normal);
58
+ return k.to(result);
59
+ }
60
+ cartesianToCartographic(cartesian, result = [0, 0, 0]) {
61
+ scratchCartesian.from(cartesian);
62
+ const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);
63
+ if (!point) {
64
+ return undefined;
65
+ }
66
+ const normal = this.geodeticSurfaceNormal(point, scratchNormal);
67
+ const h = scratchHeight;
68
+ h.copy(scratchCartesian).subtract(point);
69
+ const longitude = Math.atan2(normal.y, normal.x);
70
+ const latitude = Math.asin(normal.z);
71
+ const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);
72
+ return toCartographicFromRadians([longitude, latitude, height], result);
73
+ }
74
+ eastNorthUpToFixedFrame(origin, result = new Matrix4()) {
75
+ return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);
76
+ }
77
+ // Computes a 4x4 transformation matrix from a reference frame centered at
78
+ // the provided origin to the ellipsoid's fixed reference frame.
79
+ localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {
80
+ return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);
81
+ }
82
+ geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {
83
+ return scratchVector.from(cartesian).normalize().to(result);
84
+ }
85
+ geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {
86
+ const cartographicVectorRadians = fromCartographicToRadians(cartographic);
87
+ const longitude = cartographicVectorRadians[0];
88
+ const latitude = cartographicVectorRadians[1];
89
+ const cosLatitude = Math.cos(latitude);
90
+ scratchVector
91
+ .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))
92
+ .normalize();
93
+ return scratchVector.to(result);
94
+ }
95
+ geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {
96
+ return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);
97
+ }
98
+ scaleToGeodeticSurface(cartesian, result) {
99
+ return scaleToGeodeticSurface(cartesian, this, result);
100
+ }
101
+ scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
102
+ scratchPosition.from(cartesian);
103
+ const positionX = scratchPosition.x;
104
+ const positionY = scratchPosition.y;
105
+ const positionZ = scratchPosition.z;
106
+ const oneOverRadiiSquared = this.oneOverRadiiSquared;
107
+ const beta = 1.0 /
108
+ Math.sqrt(positionX * positionX * oneOverRadiiSquared.x +
109
+ positionY * positionY * oneOverRadiiSquared.y +
110
+ positionZ * positionZ * oneOverRadiiSquared.z);
111
+ return scratchPosition.multiplyScalar(beta).to(result);
112
+ }
113
+ transformPositionToScaledSpace(position, result = [0, 0, 0]) {
114
+ return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
115
+ }
116
+ transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
117
+ return scratchPosition.from(position).scale(this.radii).to(result);
118
+ }
119
+ getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {
120
+ // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)
121
+ assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
122
+ assert(this.radii.z > 0);
123
+ scratchPosition.from(position);
124
+ const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
125
+ if (Math.abs(z) >= this.radii.z - buffer) {
126
+ return undefined;
127
+ }
128
+ return scratchPosition.set(0.0, 0.0, z).to(result);
129
+ }
130
+ }
131
+ /** An Ellipsoid instance initialized to the WGS84 standard. */
132
+ Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
@@ -0,0 +1,2 @@
1
+ export default function localFrameToFixedFrame(ellipsoid: any, firstAxis: any, secondAxis: any, thirdAxis: any, cartesianOrigin: any, result: any): any;
2
+ //# sourceMappingURL=ellipsoid-transform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ellipsoid-transform.d.ts","sourceRoot":"","sources":["../../../src/ellipsoid/helpers/ellipsoid-transform.ts"],"names":[],"mappings":"AAuEA,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,SAAS,KAAA,EACT,SAAS,KAAA,EACT,UAAU,KAAA,EACV,SAAS,KAAA,EACT,eAAe,KAAA,EACf,MAAM,KAAA,OAwEP"}
@@ -0,0 +1,124 @@
1
+ import { Vector3, assert, equals as equalsEpsilon } from '@math.gl/core';
2
+ const EPSILON14 = 1e-14;
3
+ const scratchOrigin = new Vector3();
4
+ // Caclulate third axis from given two axii
5
+ const VECTOR_PRODUCT_LOCAL_FRAME = {
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
+ }
42
+ };
43
+ const degeneratePositionLocalFrame = {
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]
50
+ };
51
+ const scratchAxisVectors = {
52
+ east: new Vector3(),
53
+ north: new Vector3(),
54
+ up: new Vector3(),
55
+ west: new Vector3(),
56
+ south: new Vector3(),
57
+ down: new Vector3()
58
+ };
59
+ const scratchVector1 = new Vector3();
60
+ const scratchVector2 = new Vector3();
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
65
+ export default function localFrameToFixedFrame(ellipsoid, firstAxis, secondAxis, thirdAxis, cartesianOrigin, result) {
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
+ }
90
+ }
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];
105
+ }
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;
124
+ }
@@ -0,0 +1,3 @@
1
+ import { Vector3 } from '@math.gl/core';
2
+ export default function scaleToGeodeticSurface(cartesian: any, ellipsoid: any, result?: Vector3): any;
3
+ //# sourceMappingURL=scale-to-geodetic-surface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scale-to-geodetic-surface.d.ts","sourceRoot":"","sources":["../../../src/ellipsoid/helpers/scale-to-geodetic-surface.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAqB,MAAM,eAAe,CAAC;AAU1D,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,SAAS,KAAA,EAAE,SAAS,KAAA,EAAE,MAAM,UAAgB,OAuF1F"}
@@ -0,0 +1,70 @@
1
+ /* eslint-disable */
2
+ import { Vector3, _MathUtils } from '@math.gl/core';
3
+ const scratchVector = new Vector3();
4
+ const scaleToGeodeticSurfaceIntersection = new Vector3();
5
+ const scaleToGeodeticSurfaceGradient = new Vector3();
6
+ // Scales the provided Cartesian position along the geodetic surface normal
7
+ // so that it is on the surface of this ellipsoid. If the position is
8
+ // at the center of the ellipsoid, this function returns undefined.
9
+ export default function scaleToGeodeticSurface(cartesian, ellipsoid, result = new Vector3()) {
10
+ const { oneOverRadii, oneOverRadiiSquared, centerToleranceSquared } = ellipsoid;
11
+ scratchVector.from(cartesian);
12
+ const positionX = cartesian.x;
13
+ const positionY = cartesian.y;
14
+ const positionZ = cartesian.z;
15
+ const oneOverRadiiX = oneOverRadii.x;
16
+ const oneOverRadiiY = oneOverRadii.y;
17
+ const oneOverRadiiZ = oneOverRadii.z;
18
+ const x2 = positionX * positionX * oneOverRadiiX * oneOverRadiiX;
19
+ const y2 = positionY * positionY * oneOverRadiiY * oneOverRadiiY;
20
+ const z2 = positionZ * positionZ * oneOverRadiiZ * oneOverRadiiZ;
21
+ // Compute the squared ellipsoid norm.
22
+ const squaredNorm = x2 + y2 + z2;
23
+ const ratio = Math.sqrt(1.0 / squaredNorm);
24
+ // When very close to center or at center
25
+ if (!Number.isFinite(ratio)) {
26
+ return undefined;
27
+ }
28
+ // As an initial approximation, assume that the radial intersection is the projection point.
29
+ const intersection = scaleToGeodeticSurfaceIntersection;
30
+ intersection.copy(cartesian).scale(ratio);
31
+ // If the position is near the center, the iteration will not converge.
32
+ if (squaredNorm < centerToleranceSquared) {
33
+ return intersection.to(result);
34
+ }
35
+ const oneOverRadiiSquaredX = oneOverRadiiSquared.x;
36
+ const oneOverRadiiSquaredY = oneOverRadiiSquared.y;
37
+ const oneOverRadiiSquaredZ = oneOverRadiiSquared.z;
38
+ // Use the gradient at the intersection point in place of the true unit normal.
39
+ // The difference in magnitude will be absorbed in the multiplier.
40
+ const gradient = scaleToGeodeticSurfaceGradient;
41
+ gradient.set(intersection.x * oneOverRadiiSquaredX * 2.0, intersection.y * oneOverRadiiSquaredY * 2.0, intersection.z * oneOverRadiiSquaredZ * 2.0);
42
+ // Compute the initial guess at the normal vector multiplier, lambda.
43
+ let lambda = ((1.0 - ratio) * cartesian.len()) / (0.5 * gradient.len());
44
+ let correction = 0.0;
45
+ let xMultiplier;
46
+ let yMultiplier;
47
+ let zMultiplier;
48
+ let func;
49
+ do {
50
+ lambda -= correction;
51
+ xMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredX);
52
+ yMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredY);
53
+ zMultiplier = 1.0 / (1.0 + lambda * oneOverRadiiSquaredZ);
54
+ const xMultiplier2 = xMultiplier * xMultiplier;
55
+ const yMultiplier2 = yMultiplier * yMultiplier;
56
+ const zMultiplier2 = zMultiplier * zMultiplier;
57
+ const xMultiplier3 = xMultiplier2 * xMultiplier;
58
+ const yMultiplier3 = yMultiplier2 * yMultiplier;
59
+ const zMultiplier3 = zMultiplier2 * zMultiplier;
60
+ func = x2 * xMultiplier2 + y2 * yMultiplier2 + z2 * zMultiplier2 - 1.0;
61
+ // "denominator" here refers to the use of this expression in the velocity and acceleration
62
+ // computations in the sections to follow.
63
+ const denominator = x2 * xMultiplier3 * oneOverRadiiSquaredX +
64
+ y2 * yMultiplier3 * oneOverRadiiSquaredY +
65
+ z2 * zMultiplier3 * oneOverRadiiSquaredZ;
66
+ const derivative = -2.0 * denominator;
67
+ correction = func / derivative;
68
+ } while (Math.abs(func) > _MathUtils.EPSILON12);
69
+ return scratchVector.scale([xMultiplier, yMultiplier, zMultiplier]).to(result);
70
+ }
@@ -4,13 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.WGS84_CONSTANTS = exports.WGS84_RADIUS_Z = exports.WGS84_RADIUS_Y = exports.WGS84_RADIUS_X = void 0;
7
- var WGS84_RADIUS_X = 6378137.0;
7
+ const WGS84_RADIUS_X = 6378137.0;
8
8
  exports.WGS84_RADIUS_X = WGS84_RADIUS_X;
9
- var WGS84_RADIUS_Y = 6378137.0;
9
+ const WGS84_RADIUS_Y = 6378137.0;
10
10
  exports.WGS84_RADIUS_Y = WGS84_RADIUS_Y;
11
- var WGS84_RADIUS_Z = 6356752.3142451793;
11
+ const WGS84_RADIUS_Z = 6356752.3142451793;
12
12
  exports.WGS84_RADIUS_Z = WGS84_RADIUS_Z;
13
- var WGS84_CONSTANTS = {
13
+ const WGS84_CONSTANTS = {
14
14
  radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],
15
15
  radiiSquared: [WGS84_RADIUS_X * WGS84_RADIUS_X, WGS84_RADIUS_Y * WGS84_RADIUS_Y, WGS84_RADIUS_Z * WGS84_RADIUS_Z],
16
16
  oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/constants.js"],"names":["WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","WGS84_CONSTANTS","radii","radiiSquared","oneOverRadii","oneOverRadiiSquared","maximumRadius","Math","max","centerToleranceSquared"],"mappings":";;;;;;AAGO,IAAMA,cAAc,GAAG,SAAvB;;AACA,IAAMC,cAAc,GAAG,SAAvB;;AACA,IAAMC,cAAc,GAAG,kBAAvB;;AAIA,IAAMC,eAAe,GAAG;AAC7BC,EAAAA,KAAK,EAAE,CAACJ,cAAD,EAAiBC,cAAjB,EAAiCC,cAAjC,CADsB;AAE7BG,EAAAA,YAAY,EAAE,CACZL,cAAc,GAAGA,cADL,EAEZC,cAAc,GAAGA,cAFL,EAGZC,cAAc,GAAGA,cAHL,CAFe;AAO7BI,EAAAA,YAAY,EAAE,CAAC,MAAMN,cAAP,EAAuB,MAAMC,cAA7B,EAA6C,MAAMC,cAAnD,CAPe;AAQ7BK,EAAAA,mBAAmB,EAAE,CACnB,OAAOP,cAAc,GAAGA,cAAxB,CADmB,EAEnB,OAAOC,cAAc,GAAGA,cAAxB,CAFmB,EAGnB,OAAOC,cAAc,GAAGA,cAAxB,CAHmB,CARQ;AAa7BM,EAAAA,aAAa,EAAEC,IAAI,CAACC,GAAL,CAASV,cAAT,EAAyBC,cAAzB,EAAyCC,cAAzC,CAbc;AAc7BS,EAAAA,sBAAsB,EAAE;AAdK,CAAxB","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nexport const WGS84_RADIUS_X = 6378137.0;\nexport const WGS84_RADIUS_Y = 6378137.0;\nexport const WGS84_RADIUS_Z = 6356752.3142451793;\n\n// Pre-calculated ellipsoid defaults to avoid utils depending on `ellipsoid.js`\n\nexport const WGS84_CONSTANTS = {\n radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],\n radiiSquared: [\n WGS84_RADIUS_X * WGS84_RADIUS_X,\n WGS84_RADIUS_Y * WGS84_RADIUS_Y,\n WGS84_RADIUS_Z * WGS84_RADIUS_Z\n ],\n oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],\n oneOverRadiiSquared: [\n 1.0 / (WGS84_RADIUS_X * WGS84_RADIUS_X),\n 1.0 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),\n 1.0 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)\n ],\n maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),\n centerToleranceSquared: 1e-1 // EPSILON1;\n};\n"],"file":"constants.js"}
1
+ {"version":3,"sources":["../../src/constants.ts"],"names":["WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z","WGS84_CONSTANTS","radii","radiiSquared","oneOverRadii","oneOverRadiiSquared","maximumRadius","Math","max","centerToleranceSquared"],"mappings":";;;;;;AAGO,MAAMA,cAAc,GAAG,SAAvB;;AACA,MAAMC,cAAc,GAAG,SAAvB;;AACA,MAAMC,cAAc,GAAG,kBAAvB;;AAIA,MAAMC,eAAe,GAAG;AAC7BC,EAAAA,KAAK,EAAE,CAACJ,cAAD,EAAiBC,cAAjB,EAAiCC,cAAjC,CADsB;AAE7BG,EAAAA,YAAY,EAAE,CACZL,cAAc,GAAGA,cADL,EAEZC,cAAc,GAAGA,cAFL,EAGZC,cAAc,GAAGA,cAHL,CAFe;AAO7BI,EAAAA,YAAY,EAAE,CAAC,MAAMN,cAAP,EAAuB,MAAMC,cAA7B,EAA6C,MAAMC,cAAnD,CAPe;AAQ7BK,EAAAA,mBAAmB,EAAE,CACnB,OAAOP,cAAc,GAAGA,cAAxB,CADmB,EAEnB,OAAOC,cAAc,GAAGA,cAAxB,CAFmB,EAGnB,OAAOC,cAAc,GAAGA,cAAxB,CAHmB,CARQ;AAa7BM,EAAAA,aAAa,EAAEC,IAAI,CAACC,GAAL,CAASV,cAAT,EAAyBC,cAAzB,EAAyCC,cAAzC,CAbc;AAc7BS,EAAAA,sBAAsB,EAAE;AAdK,CAAxB","sourcesContent":["// This file is derived from the Cesium math library under Apache 2 license\n// See LICENSE.md and https://github.com/AnalyticalGraphicsInc/cesium/blob/master/LICENSE.md\n\nexport const WGS84_RADIUS_X = 6378137.0;\nexport const WGS84_RADIUS_Y = 6378137.0;\nexport const WGS84_RADIUS_Z = 6356752.3142451793;\n\n// Pre-calculated ellipsoid defaults to avoid utils depending on `ellipsoid.js`\n\nexport const WGS84_CONSTANTS = {\n radii: [WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z],\n radiiSquared: [\n WGS84_RADIUS_X * WGS84_RADIUS_X,\n WGS84_RADIUS_Y * WGS84_RADIUS_Y,\n WGS84_RADIUS_Z * WGS84_RADIUS_Z\n ],\n oneOverRadii: [1.0 / WGS84_RADIUS_X, 1.0 / WGS84_RADIUS_Y, 1.0 / WGS84_RADIUS_Z],\n oneOverRadiiSquared: [\n 1.0 / (WGS84_RADIUS_X * WGS84_RADIUS_X),\n 1.0 / (WGS84_RADIUS_Y * WGS84_RADIUS_Y),\n 1.0 / (WGS84_RADIUS_Z * WGS84_RADIUS_Z)\n ],\n maximumRadius: Math.max(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z),\n centerToleranceSquared: 1e-1 // EPSILON1;\n};\n"],"file":"constants.js"}