@math.gl/geospatial 3.5.6 → 3.6.0-alpha.2

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 (53) 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 +142 -0
  7. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts +5 -0
  8. package/dist/ellipsoid/helpers/ellipsoid-transform.d.ts.map +1 -0
  9. package/dist/ellipsoid/helpers/ellipsoid-transform.js +125 -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.map +1 -1
  14. package/dist/es5/ellipsoid/ellipsoid.js +13 -8
  15. package/dist/es5/ellipsoid/ellipsoid.js.map +1 -1
  16. package/dist/es5/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  17. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js +5 -13
  18. package/dist/es5/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  19. package/dist/es5/index.js.map +1 -1
  20. package/dist/es5/type-utils.js +24 -23
  21. package/dist/es5/type-utils.js.map +1 -1
  22. package/dist/esm/constants.js.map +1 -1
  23. package/dist/esm/ellipsoid/ellipsoid.js +23 -8
  24. package/dist/esm/ellipsoid/ellipsoid.js.map +1 -1
  25. package/dist/esm/ellipsoid/helpers/ellipsoid-transform.js.map +1 -1
  26. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js +6 -7
  27. package/dist/esm/ellipsoid/helpers/scale-to-geodetic-surface.js.map +1 -1
  28. package/dist/esm/index.js.map +1 -1
  29. package/dist/esm/type-utils.js +24 -22
  30. package/dist/esm/type-utils.js.map +1 -1
  31. package/dist/index.d.ts +3 -0
  32. package/dist/index.d.ts.map +1 -0
  33. package/dist/index.js +2 -0
  34. package/dist/type-utils.d.ts +24 -0
  35. package/dist/type-utils.d.ts.map +1 -0
  36. package/dist/type-utils.js +96 -0
  37. package/package.json +5 -5
  38. package/src/{constants.js → constants.ts} +0 -0
  39. package/src/ellipsoid/{ellipsoid.js → ellipsoid.ts} +96 -40
  40. package/src/ellipsoid/helpers/{ellipsoid-transform.js → ellipsoid-transform.ts} +18 -13
  41. package/src/ellipsoid/helpers/{scale-to-geodetic-surface.js → scale-to-geodetic-surface.ts} +11 -7
  42. package/src/{index.js → index.ts} +0 -0
  43. package/src/type-utils.ts +154 -0
  44. package/dist/es5/ellipsoid/ellipsoid.d.ts +0 -95
  45. package/dist/es5/index.d.ts +0 -1
  46. package/dist/es5/type-utils.d.ts +0 -55
  47. package/dist/esm/ellipsoid/ellipsoid.d.ts +0 -95
  48. package/dist/esm/index.d.ts +0 -1
  49. package/dist/esm/type-utils.d.ts +0 -55
  50. package/src/ellipsoid/ellipsoid.d.ts +0 -95
  51. package/src/index.d.ts +0 -1
  52. package/src/type-utils.d.ts +0 -55
  53. 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,EACP,OAAO,EAMP,YAAY,EACb,MAAM,eAAe,CAAC;AAkBvB;;;;GAIG;AACH,MAAM,CAAC,OAAO,OAAO,SAAS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,EAAE,MAAM,EAAE,EAAE,MAAM,GAAE,MAAM,EAAc,GAAG,MAAM,EAAE;IAI1F;4DACwD;IACxD,gCAAgC,CAAC,QAAQ,EAAE,MAAM,EAAE,EAAE,MAAM,GAAE,MAAM,EAAc,GAAG,MAAM,EAAE;IAI5F,wFAAwF;IACxF,qCAAqC,CACnC,QAAQ,EAAE,MAAM,EAAE,EAClB,MAAM,GAAE,MAAU,EAClB,MAAM,GAAE,MAAM,EAAc,GAC3B,MAAM,EAAE;CAcZ"}
@@ -0,0 +1,142 @@
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
+ /** Scales the provided Cartesian position along the geodetic surface normal
99
+ * so that it is on the surface of this ellipsoid. If the position is
100
+ * at the center of the ellipsoid, this function returns undefined. */
101
+ scaleToGeodeticSurface(cartesian, result) {
102
+ return scaleToGeodeticSurface(cartesian, this, result);
103
+ }
104
+ /** Scales the provided Cartesian position along the geocentric surface normal
105
+ * so that it is on the surface of this ellipsoid. */
106
+ scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {
107
+ scratchPosition.from(cartesian);
108
+ const positionX = scratchPosition.x;
109
+ const positionY = scratchPosition.y;
110
+ const positionZ = scratchPosition.z;
111
+ const oneOverRadiiSquared = this.oneOverRadiiSquared;
112
+ const beta = 1.0 /
113
+ Math.sqrt(positionX * positionX * oneOverRadiiSquared.x +
114
+ positionY * positionY * oneOverRadiiSquared.y +
115
+ positionZ * positionZ * oneOverRadiiSquared.z);
116
+ return scratchPosition.multiplyScalar(beta).to(result);
117
+ }
118
+ /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying
119
+ * its components by the result of `Ellipsoid#oneOverRadii` */
120
+ transformPositionToScaledSpace(position, result = [0, 0, 0]) {
121
+ return scratchPosition.from(position).scale(this.oneOverRadii).to(result);
122
+ }
123
+ /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying
124
+ * its components by the result of `Ellipsoid#radii`. */
125
+ transformPositionFromScaledSpace(position, result = [0, 0, 0]) {
126
+ return scratchPosition.from(position).scale(this.radii).to(result);
127
+ }
128
+ /** Computes a point which is the intersection of the surface normal with the z-axis. */
129
+ getSurfaceNormalIntersectionWithZAxis(position, buffer = 0, result = [0, 0, 0]) {
130
+ // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)
131
+ assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));
132
+ assert(this.radii.z > 0);
133
+ scratchPosition.from(position);
134
+ const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);
135
+ if (Math.abs(z) >= this.radii.z - buffer) {
136
+ return undefined;
137
+ }
138
+ return scratchPosition.set(0.0, 0.0, z).to(result);
139
+ }
140
+ }
141
+ /** An Ellipsoid instance initialized to the WGS84 standard. */
142
+ Ellipsoid.WGS84 = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);
@@ -0,0 +1,5 @@
1
+ import type Ellipsoid from '../ellipsoid';
2
+ declare type Axis = 'up' | 'down' | 'north' | 'east' | 'south' | 'west';
3
+ export default function localFrameToFixedFrame(ellipsoid: Ellipsoid, firstAxis: Axis, secondAxis: Axis, thirdAxis: Axis, cartesianOrigin: number[], result: number[]): number[];
4
+ export {};
5
+ //# 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":"AAEA,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAoE1C,aAAK,IAAI,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,CAAC;AAKhE,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,SAAS,EAAE,SAAS,EACpB,SAAS,EAAE,IAAI,EACf,UAAU,EAAE,IAAI,EAChB,SAAS,EAAE,IAAI,EACf,eAAe,EAAE,MAAM,EAAE,EACzB,MAAM,EAAE,MAAM,EAAE,GACf,MAAM,EAAE,CAwEV"}
@@ -0,0 +1,125 @@
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] &&
67
+ VECTOR_PRODUCT_LOCAL_FRAME[firstAxis][secondAxis];
68
+ // firstAxis and secondAxis must be east, north, up, west, south or down.');
69
+ assert(thirdAxisInferred && (!thirdAxis || thirdAxis === thirdAxisInferred));
70
+ let firstAxisVector;
71
+ let secondAxisVector;
72
+ let thirdAxisVector;
73
+ const origin = scratchOrigin.copy(cartesianOrigin);
74
+ // If x and y are zero, assume origin is at a pole, which is a special case.
75
+ const atPole = equalsEpsilon(origin.x, 0.0, EPSILON14) && equalsEpsilon(origin.y, 0.0, EPSILON14);
76
+ if (atPole) {
77
+ // Look up axis value and adjust
78
+ const sign = Math.sign(origin.z);
79
+ firstAxisVector = scratchVector1.fromArray(degeneratePositionLocalFrame[firstAxis]);
80
+ if (firstAxis !== 'east' && firstAxis !== 'west') {
81
+ firstAxisVector.scale(sign);
82
+ }
83
+ secondAxisVector = scratchVector2.fromArray(degeneratePositionLocalFrame[secondAxis]);
84
+ if (secondAxis !== 'east' && secondAxis !== 'west') {
85
+ secondAxisVector.scale(sign);
86
+ }
87
+ thirdAxisVector = scratchVector3.fromArray(degeneratePositionLocalFrame[thirdAxis]);
88
+ if (thirdAxis !== 'east' && thirdAxis !== 'west') {
89
+ thirdAxisVector.scale(sign);
90
+ }
91
+ }
92
+ else {
93
+ // Calculate all axis
94
+ const { up, east, north } = scratchAxisVectors;
95
+ east.set(-origin.y, origin.x, 0.0).normalize();
96
+ ellipsoid.geodeticSurfaceNormal(origin, up);
97
+ north.copy(up).cross(east);
98
+ const { down, west, south } = scratchAxisVectors;
99
+ down.copy(up).scale(-1);
100
+ west.copy(east).scale(-1);
101
+ south.copy(north).scale(-1);
102
+ // Pick three axis based on desired orientation
103
+ firstAxisVector = scratchAxisVectors[firstAxis];
104
+ secondAxisVector = scratchAxisVectors[secondAxis];
105
+ thirdAxisVector = scratchAxisVectors[thirdAxis];
106
+ }
107
+ // TODO - assuming the result is column-major
108
+ result[0] = firstAxisVector.x;
109
+ result[1] = firstAxisVector.y;
110
+ result[2] = firstAxisVector.z;
111
+ result[3] = 0.0;
112
+ result[4] = secondAxisVector.x;
113
+ result[5] = secondAxisVector.y;
114
+ result[6] = secondAxisVector.z;
115
+ result[7] = 0.0;
116
+ result[8] = thirdAxisVector.x;
117
+ result[9] = thirdAxisVector.y;
118
+ result[10] = thirdAxisVector.z;
119
+ result[11] = 0.0;
120
+ result[12] = origin.x;
121
+ result[13] = origin.y;
122
+ result[14] = origin.z;
123
+ result[15] = 1.0;
124
+ return result;
125
+ }
@@ -0,0 +1,3 @@
1
+ import type Ellipsoid from '../ellipsoid';
2
+ export default function scaleToGeodeticSurface(cartesian: number[], ellipsoid: Ellipsoid, result?: number[]): number[];
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":"AAEA,OAAO,KAAK,SAAS,MAAM,cAAc,CAAC;AAS1C,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAC5C,SAAS,EAAE,MAAM,EAAE,EACnB,SAAS,EAAE,SAAS,EACpB,MAAM,GAAE,MAAM,EAAO,GACpB,MAAM,EAAE,CAuFV"}
@@ -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 = []) {
10
+ const { oneOverRadii, oneOverRadiiSquared, centerToleranceSquared } = ellipsoid;
11
+ scratchVector.from(cartesian);
12
+ const positionX = scratchVector.x;
13
+ const positionY = scratchVector.y;
14
+ const positionZ = scratchVector.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) * scratchVector.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
+ }
@@ -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,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"}
@@ -15,6 +15,8 @@ var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/cl
15
15
 
16
16
  var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
17
17
 
18
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
19
+
18
20
  var _core = require("@math.gl/core");
19
21
 
20
22
  var vec3 = _interopRequireWildcard(require("gl-matrix/vec3"));
@@ -45,6 +47,15 @@ var Ellipsoid = function () {
45
47
  var y = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
46
48
  var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0.0;
47
49
  (0, _classCallCheck2.default)(this, Ellipsoid);
50
+ (0, _defineProperty2.default)(this, "radii", void 0);
51
+ (0, _defineProperty2.default)(this, "radiiSquared", void 0);
52
+ (0, _defineProperty2.default)(this, "radiiToTheFourth", void 0);
53
+ (0, _defineProperty2.default)(this, "oneOverRadii", void 0);
54
+ (0, _defineProperty2.default)(this, "oneOverRadiiSquared", void 0);
55
+ (0, _defineProperty2.default)(this, "minimumRadius", void 0);
56
+ (0, _defineProperty2.default)(this, "maximumRadius", void 0);
57
+ (0, _defineProperty2.default)(this, "centerToleranceSquared", _core._MathUtils.EPSILON1);
58
+ (0, _defineProperty2.default)(this, "squaredXOverSquaredZ", void 0);
48
59
  (0, _core.assert)(x >= 0.0);
49
60
  (0, _core.assert)(y >= 0.0);
50
61
  (0, _core.assert)(z >= 0.0);
@@ -55,7 +66,6 @@ var Ellipsoid = function () {
55
66
  this.oneOverRadiiSquared = new _core.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));
56
67
  this.minimumRadius = Math.min(x, y, z);
57
68
  this.maximumRadius = Math.max(x, y, z);
58
- this.centerToleranceSquared = _core._MathUtils.EPSILON1;
59
69
 
60
70
  if (this.radiiSquared.z !== 0) {
61
71
  this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;
@@ -178,7 +188,7 @@ var Ellipsoid = function () {
178
188
  }, {
179
189
  key: "getSurfaceNormalIntersectionWithZAxis",
180
190
  value: function getSurfaceNormalIntersectionWithZAxis(position) {
181
- var buffer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.0;
191
+ var buffer = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
182
192
  var result = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [0, 0, 0];
183
193
  (0, _core.assert)((0, _core.equals)(this.radii.x, this.radii.y, _core._MathUtils.EPSILON15));
184
194
  (0, _core.assert)(this.radii.z > 0);
@@ -191,15 +201,10 @@ var Ellipsoid = function () {
191
201
 
192
202
  return scratchPosition.set(0.0, 0.0, z).to(result);
193
203
  }
194
- }], [{
195
- key: "WGS84",
196
- get: function get() {
197
- wgs84 = wgs84 || new Ellipsoid(_constants.WGS84_RADIUS_X, _constants.WGS84_RADIUS_Y, _constants.WGS84_RADIUS_Z);
198
- return wgs84;
199
- }
200
204
  }]);
201
205
  return Ellipsoid;
202
206
  }();
203
207
 
204
208
  exports.default = Ellipsoid;
209
+ (0, _defineProperty2.default)(Ellipsoid, "WGS84", new Ellipsoid(_constants.WGS84_RADIUS_X, _constants.WGS84_RADIUS_Y, _constants.WGS84_RADIUS_Z));
205
210
  //# sourceMappingURL=ellipsoid.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/ellipsoid/ellipsoid.js"],"names":["scratchVector","Vector3","scratchNormal","scratchK","scratchPosition","scratchHeight","scratchCartesian","wgs84","Ellipsoid","x","y","z","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","centerToleranceSquared","_MathUtils","EPSILON1","squaredXOverSquaredZ","Object","freeze","right","Boolean","equals","toString","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesian","from","point","scaleToGeodeticSurface","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","vec3","length","origin","Matrix4","firstAxis","secondAxis","thirdAxis","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","positionX","positionY","positionZ","beta","multiplyScalar","position","buffer","EPSILON15","abs","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z"],"mappings":";;;;;;;;;;;;;;;;;AAIA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;;;;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AACA,IAAME,QAAQ,GAAG,IAAIF,aAAJ,EAAjB;AACA,IAAMG,eAAe,GAAG,IAAIH,aAAJ,EAAxB;AACA,IAAMI,aAAa,GAAG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CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAC7D,aAAO7B,eAAe,CAAC0C,IAAhB,CAAqB8B,QAArB,EAA+BrC,KAA/B,CAAqC,KAAK3B,KAA1C,EAAiDgC,EAAjD,CAAoDX,MAApD,CAAP;AACD;;;WAGD,+CAAsC2C,QAAtC,EAAkF;AAAA,UAAlCC,MAAkC,uEAAzB,GAAyB;AAAA,UAApB5C,MAAoB,uEAAX,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAW;AAEhF,wBAAO,kBAAO,KAAKrB,KAAL,CAAWH,CAAlB,EAAqB,KAAKG,KAAL,CAAWF,CAAhC,EAAmCa,iBAAWuD,SAA9C,CAAP;AACA,wBAAO,KAAKlE,KAAL,CAAWD,CAAX,GAAe,CAAtB;AAEAP,MAAAA,eAAe,CAAC0C,IAAhB,CAAqB8B,QAArB;AACA,UAAMjE,CAAC,GAAGP,eAAe,CAACO,CAAhB,IAAqB,IAAI,KAAKc,oBAA9B,CAAV;;AAEA,UAAIP,IAAI,CAAC6D,GAAL,CAASpE,CAAT,KAAe,KAAKC,KAAL,CAAWD,CAAX,GAAekE,MAAlC,EAA0C;AACxC,eAAO5B,SAAP;AACD;;AAED,aAAO7C,eAAe,CAACiE,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8B1D,CAA9B,EAAiCiC,EAAjC,CAAoCX,MAApC,CAAP;AACD;;;SA1LD,eAAmB;AACjB1B,MAAAA,KAAK,GAAGA,KAAK,IAAI,IAAIC,SAAJ,CAAcwE,yBAAd,EAA8BC,yBAA9B,EAA8CC,yBAA9C,CAAjB;AACA,aAAO3E,KAAP;AACD","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\n/* eslint-disable */\nimport {Vector3, Matrix4, toRadians, toDegrees, assert, equals, _MathUtils} from '@math.gl/core';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\nconst scratchCartesian = new Vector3();\n\nlet wgs84;\n\n// A quadratic surface defined in Cartesian coordinates by the equation\n// <code>(x / a)^2 + (y / b)^2 + (z / c)^2 = 1</code>. Primarily used\n// to represent the shape of planetary bodies.\nexport default class Ellipsoid {\n // An Ellipsoid instance initialized to the WGS84 standard.\n static get WGS84() {\n wgs84 = wgs84 || new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n return wgs84;\n }\n\n // Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions.\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n this.centerToleranceSquared = _MathUtils.EPSILON1;\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n // Compares this Ellipsoid against the provided Ellipsoid componentwise and returns\n equals(right) {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n // Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'.\n toString() {\n return this.radii.toString();\n }\n\n // Converts the provided cartographic to Cartesian representation.\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n // Converts the provided cartesian to cartographic (lng/lat/z) representation.\n // The cartesian is undefined at the center of the ellipsoid.\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n scratchCartesian.from(cartesian);\n const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(scratchCartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n // centered at the provided origin to the provided ellipsoid's fixed reference frame.\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n // Computes the unit vector directed from the center of this ellipsoid toward\n // the provided Cartesian position.\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector.from(cartesian).normalize().to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at provided position.\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n // Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position.\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);\n }\n\n // Scales the provided Cartesian position along the geodetic surface normal\n // so that it is on the surface of this ellipsoid. If the position is\n // at the center of the ellipsoid, this function returns undefined.\n scaleToGeodeticSurface(cartesian, result) {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n // Scales the provided Cartesian position along the geocentric surface normal\n // so that it is on the surface of this ellipsoid.\n scaleToGeocentricSurface(cartesian, result = [0, 0, 0]) {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#oneOverRadii`\n transformPositionToScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition.from(position).scale(this.oneOverRadii).to(result);\n }\n\n // Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n // its components by the result of `Ellipsoid#radii`.\n transformPositionFromScaledSpace(position, result = [0, 0, 0]) {\n return scratchPosition.from(position).scale(this.radii).to(result);\n }\n\n // Computes a point which is the intersection of the surface normal with the z-axis.\n getSurfaceNormalIntersectionWithZAxis(position, buffer = 0.0, result = [0, 0, 0]) {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}
1
+ {"version":3,"sources":["../../../src/ellipsoid/ellipsoid.ts"],"names":["scratchVector","Vector3","scratchNormal","scratchK","scratchPosition","scratchHeight","scratchCartesian","wgs84","Ellipsoid","x","y","z","_MathUtils","EPSILON1","radii","radiiSquared","radiiToTheFourth","oneOverRadii","oneOverRadiiSquared","minimumRadius","Math","min","maximumRadius","max","squaredXOverSquaredZ","Object","freeze","right","Boolean","equals","toString","cartographic","result","normal","k","height","geodeticSurfaceNormalCartographic","copy","scale","gamma","sqrt","dot","add","to","cartesian","from","point","scaleToGeodeticSurface","undefined","geodeticSurfaceNormal","h","subtract","longitude","atan2","latitude","asin","sign","vec3","length","origin","Matrix4","firstAxis","secondAxis","thirdAxis","normalize","cartographicVectorRadians","cosLatitude","cos","set","sin","positionX","positionY","positionZ","beta","multiplyScalar","position","buffer","EPSILON15","abs","WGS84_RADIUS_X","WGS84_RADIUS_Y","WGS84_RADIUS_Z"],"mappings":";;;;;;;;;;;;;;;;;;;AAIA;;AAUA;;AAEA;;AACA;;AAEA;;AACA;;;;;;AAEA,IAAMA,aAAa,GAAG,IAAIC,aAAJ,EAAtB;AACA,IAAMC,aAAa,GAAG,IAAID,aAAJ,EAAtB;AACA,IAAME,QAAQ,GAAG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B,CAAqC,KAAKrB,YAA1C,EAAwD0B,EAAxD,CAA2DX,MAA3D,CAAP;AACD;;;WAID,0CAAiC2C,QAAjC,EAA6F;AAAA,UAAxC3C,MAAwC,uEAArB,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CAAqB;AAC3F,aAAO5B,eAAe,CAACyC,IAAhB,CAAqB8B,QAArB,EAA+BrC,KAA/B,CAAqC,KAAKxB,KAA1C,EAAiD6B,EAAjD,CAAoDX,MAApD,CAAP;AACD;;;WAGD,+CACE2C,QADF,EAIY;AAAA,UAFVC,MAEU,uEAFO,CAEP;AAAA,UADV5C,MACU,uEADS,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,CACT;AAEV,wBAAO,kBAAO,KAAKlB,KAAL,CAAWL,CAAlB,EAAqB,KAAKK,KAAL,CAAWJ,CAAhC,EAAmCE,iBAAWiE,SAA9C,CAAP;AACA,wBAAO,KAAK/D,KAAL,CAAWH,CAAX,GAAe,CAAtB;AAEAP,MAAAA,eAAe,CAACyC,IAAhB,CAAqB8B,QAArB;AACA,UAAMhE,CAAC,GAAGP,eAAe,CAACO,CAAhB,IAAqB,IAAI,KAAKa,oBAA9B,CAAV;;AAEA,UAAIJ,IAAI,CAAC0D,GAAL,CAASnE,CAAT,KAAe,KAAKG,KAAL,CAAWH,CAAX,GAAeiE,MAAlC,EAA0C;AACxC,eAAO5B,SAAP;AACD;;AAED,aAAO5C,eAAe,CAACgE,GAAhB,CAAoB,GAApB,EAAyB,GAAzB,EAA8BzD,CAA9B,EAAiCgC,EAAjC,CAAoCX,MAApC,CAAP;AACD;;;;;;8BAzOkBxB,S,WAEgB,IAAIA,SAAJ,CAAcuE,yBAAd,EAA8BC,yBAA9B,EAA8CC,yBAA9C,C","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\n/* eslint-disable */\nimport {\n Vector3,\n Matrix4,\n toRadians,\n toDegrees,\n assert,\n equals,\n _MathUtils,\n NumericArray\n} from '@math.gl/core';\nimport * as vec3 from 'gl-matrix/vec3';\n\nimport {WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z} from '../constants';\nimport {fromCartographicToRadians, toCartographicFromRadians} from '../type-utils';\n\nimport scaleToGeodeticSurface from './helpers/scale-to-geodetic-surface';\nimport localFrameToFixedFrame from './helpers/ellipsoid-transform';\n\nconst scratchVector = new Vector3();\nconst scratchNormal = new Vector3();\nconst scratchK = new Vector3();\nconst scratchPosition = new Vector3();\nconst scratchHeight = new Vector3();\nconst scratchCartesian = new Vector3();\n\nlet wgs84;\n\n/**\n * A quadratic surface defined in Cartesian coordinates by the equation\n * `(x / a)^2 + (y / b)^2 + (z / c)^2 = 1`. Primarily used\n * to represent the shape of planetary bodies.\n */\nexport default class Ellipsoid {\n /** An Ellipsoid instance initialized to the WGS84 standard. */\n static readonly WGS84: Ellipsoid = new Ellipsoid(WGS84_RADIUS_X, WGS84_RADIUS_Y, WGS84_RADIUS_Z);\n\n readonly radii: Vector3;\n readonly radiiSquared: Vector3;\n readonly radiiToTheFourth: Vector3;\n readonly oneOverRadii: Vector3;\n readonly oneOverRadiiSquared: Vector3;\n readonly minimumRadius: number;\n readonly maximumRadius: number;\n readonly centerToleranceSquared: number = _MathUtils.EPSILON1;\n readonly squaredXOverSquaredZ: number;\n\n /** Creates an Ellipsoid from a Cartesian specifying the radii in x, y, and z directions. */\n constructor(x: number, y: number, z: number);\n constructor();\n\n constructor(x = 0.0, y = 0.0, z = 0.0) {\n assert(x >= 0.0);\n assert(y >= 0.0);\n assert(z >= 0.0);\n\n this.radii = new Vector3(x, y, z);\n\n this.radiiSquared = new Vector3(x * x, y * y, z * z);\n\n this.radiiToTheFourth = new Vector3(x * x * x * x, y * y * y * y, z * z * z * z);\n\n this.oneOverRadii = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / x,\n y === 0.0 ? 0.0 : 1.0 / y,\n z === 0.0 ? 0.0 : 1.0 / z\n );\n\n this.oneOverRadiiSquared = new Vector3(\n x === 0.0 ? 0.0 : 1.0 / (x * x),\n y === 0.0 ? 0.0 : 1.0 / (y * y),\n z === 0.0 ? 0.0 : 1.0 / (z * z)\n );\n\n this.minimumRadius = Math.min(x, y, z);\n\n this.maximumRadius = Math.max(x, y, z);\n\n if (this.radiiSquared.z !== 0) {\n this.squaredXOverSquaredZ = this.radiiSquared.x / this.radiiSquared.z;\n }\n\n Object.freeze(this);\n }\n\n /** Compares this Ellipsoid against the provided Ellipsoid componentwise */\n equals(right: Ellipsoid): boolean {\n return this === right || Boolean(right && this.radii.equals(right.radii));\n }\n\n /** Creates a string representing this Ellipsoid in the format '(radii.x, radii.y, radii.z)'. */\n toString(): string {\n return this.radii.toString();\n }\n\n /** Converts the provided cartographic to Cartesian representation. */\n cartographicToCartesian(cartographic: number[], result: Vector3): Vector3;\n cartographicToCartesian(cartographic: number[], result?: number[]): number[];\n\n cartographicToCartesian(cartographic, result = [0, 0, 0]) {\n const normal = scratchNormal;\n const k = scratchK;\n\n const [, , height] = cartographic;\n this.geodeticSurfaceNormalCartographic(cartographic, normal);\n k.copy(this.radiiSquared).scale(normal);\n\n const gamma = Math.sqrt(normal.dot(k));\n k.scale(1 / gamma);\n\n normal.scale(height);\n\n k.add(normal);\n\n return k.to(result);\n }\n\n /** Converts the provided cartesian to cartographic (lng/lat/z) representation.\n * The cartesian is undefined at the center of the ellipsoid. */\n cartesianToCartographic(cartesian: number[], result: Vector3): Vector3;\n cartesianToCartographic(cartesian: number[], result?: number[]): number[];\n\n cartesianToCartographic(cartesian, result = [0, 0, 0]) {\n scratchCartesian.from(cartesian);\n const point = this.scaleToGeodeticSurface(scratchCartesian, scratchPosition);\n\n if (!point) {\n return undefined;\n }\n\n const normal = this.geodeticSurfaceNormal(point, scratchNormal);\n\n const h = scratchHeight;\n h.copy(scratchCartesian).subtract(point);\n\n const longitude = Math.atan2(normal.y, normal.x);\n const latitude = Math.asin(normal.z);\n const height = Math.sign(vec3.dot(h, scratchCartesian)) * vec3.length(h);\n\n return toCartographicFromRadians([longitude, latitude, height], result);\n }\n\n /** Computes a 4x4 transformation matrix from a reference frame with an east-north-up axes\n * centered at the provided origin to the provided ellipsoid's fixed reference frame. */\n eastNorthUpToFixedFrame(origin: number[], result?: Matrix4): Matrix4;\n eastNorthUpToFixedFrame(origin: number[], result: number[]): number[];\n\n eastNorthUpToFixedFrame(origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, 'east', 'north', 'up', origin, result);\n }\n\n /** Computes a 4x4 transformation matrix from a reference frame centered at\n * the provided origin to the ellipsoid's fixed reference frame.\n */\n localFrameToFixedFrame(\n firstAxis: string,\n secondAxis: string,\n thirdAxis: string,\n origin: Readonly<NumericArray>,\n result?: Matrix4\n ): Matrix4;\n localFrameToFixedFrame<Matrix4T>(\n firstAxis: string,\n secondAxis: string,\n thirdAxis: string,\n origin: Readonly<NumericArray>,\n result: number[]\n ): number[];\n\n // Computes a 4x4 transformation matrix from a reference frame centered at\n // the provided origin to the ellipsoid's fixed reference frame.\n localFrameToFixedFrame(firstAxis, secondAxis, thirdAxis, origin, result = new Matrix4()) {\n return localFrameToFixedFrame(this, firstAxis, secondAxis, thirdAxis, origin, result);\n }\n\n /** Computes the unit vector directed from the center of this ellipsoid toward\n * the provided Cartesian position. */\n geocentricSurfaceNormal(cartesian: number[], result?: number[]): number[];\n geocentricSurfaceNormal<NumArray>(cartesian: number[], result: NumArray): NumArray;\n geocentricSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector.from(cartesian).normalize().to(result);\n }\n\n /** Computes the normal of the plane tangent to the surface of the ellipsoid at provided position. */\n geodeticSurfaceNormalCartographic<NumArray>(cartographic: number[], result: NumArray): NumArray;\n geodeticSurfaceNormalCartographic(cartographic: number[]): number[];\n geodeticSurfaceNormalCartographic(cartographic, result = [0, 0, 0]) {\n const cartographicVectorRadians = fromCartographicToRadians(cartographic);\n\n const longitude = cartographicVectorRadians[0];\n const latitude = cartographicVectorRadians[1];\n\n const cosLatitude = Math.cos(latitude);\n\n scratchVector\n .set(cosLatitude * Math.cos(longitude), cosLatitude * Math.sin(longitude), Math.sin(latitude))\n .normalize();\n\n return scratchVector.to(result);\n }\n\n /** Computes the normal of the plane tangent to the surface of the ellipsoid at the provided position. */\n geodeticSurfaceNormal<NumArrayT>(cartesian: number[], result: NumArrayT): NumArrayT;\n geodeticSurfaceNormal(cartesian: number[]): number[];\n geodeticSurfaceNormal(cartesian, result = [0, 0, 0]) {\n return scratchVector.from(cartesian).scale(this.oneOverRadiiSquared).normalize().to(result);\n }\n\n /** Scales the provided Cartesian position along the geodetic surface normal\n * so that it is on the surface of this ellipsoid. If the position is\n * at the center of the ellipsoid, this function returns undefined. */\n scaleToGeodeticSurface(cartesian: number[], result?: number[]): number[] {\n return scaleToGeodeticSurface(cartesian, this, result);\n }\n\n /** Scales the provided Cartesian position along the geocentric surface normal\n * so that it is on the surface of this ellipsoid. */\n scaleToGeocentricSurface(cartesian: number[], result: number[] = [0, 0, 0]): number[] {\n scratchPosition.from(cartesian);\n\n const positionX = scratchPosition.x;\n const positionY = scratchPosition.y;\n const positionZ = scratchPosition.z;\n const oneOverRadiiSquared = this.oneOverRadiiSquared;\n\n const beta =\n 1.0 /\n Math.sqrt(\n positionX * positionX * oneOverRadiiSquared.x +\n positionY * positionY * oneOverRadiiSquared.y +\n positionZ * positionZ * oneOverRadiiSquared.z\n );\n\n return scratchPosition.multiplyScalar(beta).to(result);\n }\n\n /** Transforms a Cartesian X, Y, Z position to the ellipsoid-scaled space by multiplying\n * its components by the result of `Ellipsoid#oneOverRadii` */\n transformPositionToScaledSpace(position: number[], result: number[] = [0, 0, 0]): number[] {\n return scratchPosition.from(position).scale(this.oneOverRadii).to(result);\n }\n\n /** Transforms a Cartesian X, Y, Z position from the ellipsoid-scaled space by multiplying\n * its components by the result of `Ellipsoid#radii`. */\n transformPositionFromScaledSpace(position: number[], result: number[] = [0, 0, 0]): number[] {\n return scratchPosition.from(position).scale(this.radii).to(result);\n }\n\n /** Computes a point which is the intersection of the surface normal with the z-axis. */\n getSurfaceNormalIntersectionWithZAxis(\n position: number[],\n buffer: number = 0,\n result: number[] = [0, 0, 0]\n ): number[] {\n // Ellipsoid must be an ellipsoid of revolution (radii.x == radii.y)\n assert(equals(this.radii.x, this.radii.y, _MathUtils.EPSILON15));\n assert(this.radii.z > 0);\n\n scratchPosition.from(position);\n const z = scratchPosition.z * (1 - this.squaredXOverSquaredZ);\n\n if (Math.abs(z) >= this.radii.z - buffer) {\n return undefined;\n }\n\n return scratchPosition.set(0.0, 0.0, z).to(result);\n }\n}\n"],"file":"ellipsoid.js"}