@pirireis/webglobeplugins 0.10.11-alpha → 0.10.12-alpha
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/Math/methods.js
CHANGED
|
@@ -1,133 +1,52 @@
|
|
|
1
1
|
import { WORLD_RADIUS_3D, WORLD_RADIUS_MERCATOR } from './constants';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
* @typedef {Array<number>} wgs84 [long, lat]
|
|
8
|
-
*/
|
|
9
|
-
// *********************************************************
|
|
10
|
-
// **************** VECTOR OPERATIONS **********************
|
|
11
|
-
// *********************************************************
|
|
12
|
-
const RADIANS = Math.PI / 180;
|
|
13
|
-
/**
|
|
14
|
-
* @param {vec3} a
|
|
15
|
-
* @returns {vec3}
|
|
16
|
-
*/
|
|
17
|
-
const normalize3 = (a) => {
|
|
18
|
-
const len = length3(a);
|
|
19
|
-
return [a[0] / len, a[1] / len, a[2] / len];
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* @param {vec3} a
|
|
23
|
-
* @param {vec3} b
|
|
24
|
-
* @returns {number}
|
|
25
|
-
*/
|
|
26
|
-
const dot3 = (a, b) => {
|
|
27
|
-
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
28
|
-
};
|
|
29
|
-
/**
|
|
30
|
-
* @param {vec3} a
|
|
31
|
-
* @returns {number}
|
|
32
|
-
*/
|
|
33
|
-
const length3 = (a) => {
|
|
34
|
-
return Math.sqrt(dot3(a, a));
|
|
35
|
-
};
|
|
36
|
-
// *********************************************************
|
|
37
|
-
// **************** TRANSFORMATIONS ************************
|
|
38
|
-
// *********************************************************
|
|
39
|
-
/**
|
|
40
|
-
* @param {vec3} cartesian
|
|
41
|
-
* @returns {vec2} long lat in radians
|
|
42
|
-
*/
|
|
43
|
-
const cartesian3dToRadian = (cartesian) => {
|
|
2
|
+
import { dot as dot3, copy as copy3 } from './vec3';
|
|
3
|
+
export const RADIANS = Math.PI / 180;
|
|
4
|
+
const _0vec3 = [0, 0, 0];
|
|
5
|
+
const _0vec2 = [0, 0];
|
|
6
|
+
export const cartesian3dToRadian = (output, cartesian) => {
|
|
44
7
|
const x = cartesian[0];
|
|
45
8
|
const y = cartesian[1];
|
|
46
9
|
const z = cartesian[2];
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const lat = Math.asin(z); // length);
|
|
50
|
-
return [long, lat];
|
|
10
|
+
output[0] = Math.atan2(y, x); // longitude
|
|
11
|
+
output[1] = Math.asin(z); // latitude
|
|
51
12
|
};
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
return [WORLD_RADIUS_MERCATOR * xy[0], WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + xy[1] / 2))];
|
|
13
|
+
export const radianToMercator = (xy) => {
|
|
14
|
+
return [
|
|
15
|
+
WORLD_RADIUS_MERCATOR * xy[0],
|
|
16
|
+
WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + xy[1] / 2))
|
|
17
|
+
];
|
|
58
18
|
};
|
|
59
|
-
|
|
60
|
-
* @param {vec2} xy long lat radians
|
|
61
|
-
* @returns {vec3} cartesian
|
|
62
|
-
*/
|
|
63
|
-
const radianToCartesian3d = (xy) => {
|
|
19
|
+
export const radianToCartesian3d = (xy) => {
|
|
64
20
|
const x = Math.cos(xy[1]) * Math.cos(xy[0]);
|
|
65
21
|
const y = Math.cos(xy[1]) * Math.sin(xy[0]);
|
|
66
22
|
const z = -Math.sin(xy[1]);
|
|
67
23
|
return [x, y, z];
|
|
68
24
|
};
|
|
69
|
-
|
|
70
|
-
// ***************** INTERPOLATIONS ************************
|
|
71
|
-
// *********************************************************
|
|
72
|
-
/**
|
|
73
|
-
* @param {vec3} normalizedA
|
|
74
|
-
* @param {vec3} normalizedB
|
|
75
|
-
* @param {fraction} ratio
|
|
76
|
-
* @returns {vec3}
|
|
77
|
-
*/
|
|
78
|
-
const sphericalLinearInterpolation_UnitVector = (normalizedA, normalizedB, ratio) => {
|
|
25
|
+
export const sphericalLinearInterpolation_UnitVector = (output, normalizedA, normalizedB, ratio) => {
|
|
79
26
|
const theta = Math.acos(dot3(normalizedA, normalizedB));
|
|
80
|
-
if (theta < 0.000001)
|
|
81
|
-
|
|
27
|
+
if (theta < 0.000001) {
|
|
28
|
+
copy3(output, normalizedA);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
82
31
|
const sinTheta = Math.sin(theta);
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
*
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
*/
|
|
96
|
-
const sphericalLinearInterpolation_Mercator = (normalizedA, normalizedB, ratio) => {
|
|
97
|
-
const unitVector = sphericalLinearInterpolation_UnitVector(normalizedA, normalizedB, ratio);
|
|
98
|
-
const angles = cartesian3dToRadian(unitVector);
|
|
99
|
-
return radianToMercator(angles);
|
|
100
|
-
};
|
|
101
|
-
/**
|
|
102
|
-
* @param {vec4} a vec3 unit vector and length
|
|
103
|
-
* @param {vec4} b vec3 unit vector and length
|
|
104
|
-
* @param {fraction} ratio
|
|
105
|
-
*/
|
|
106
|
-
const sphericalLinearInterpolation_Cartesian3d = (a, b, ratio) => {
|
|
107
|
-
const unitVector = sphericalLinearInterpolation_UnitVector(a, b, ratio);
|
|
32
|
+
output[0] = (Math.sin((1.0 - ratio) * theta) * normalizedA[0] + Math.sin(ratio * theta) * normalizedB[0]) / sinTheta;
|
|
33
|
+
output[1] = (Math.sin((1.0 - ratio) * theta) * normalizedA[1] + Math.sin(ratio * theta) * normalizedB[1]) / sinTheta;
|
|
34
|
+
output[2] = (Math.sin((1.0 - ratio) * theta) * normalizedA[2] + Math.sin(ratio * theta) * normalizedB[2]) / sinTheta;
|
|
35
|
+
};
|
|
36
|
+
export const sphericalLinearInterpolation_Mercator = (output, normalizedA, normalizedB, ratio) => {
|
|
37
|
+
sphericalLinearInterpolation_UnitVector(_0vec3, normalizedA, normalizedB, ratio);
|
|
38
|
+
cartesian3dToRadian(_0vec2, _0vec3);
|
|
39
|
+
output[0] = WORLD_RADIUS_MERCATOR * _0vec2[0];
|
|
40
|
+
output[1] = WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + _0vec2[1] / 2));
|
|
41
|
+
};
|
|
42
|
+
export const sphericalLinearInterpolation_Cartesian3d = (output, a, b, ratio) => {
|
|
43
|
+
sphericalLinearInterpolation_UnitVector(_0vec3, [a[0], a[1], a[2]], [b[0], b[1], b[2]], ratio);
|
|
108
44
|
const height = a[3] + (b[3] - a[3]) * ratio;
|
|
109
|
-
|
|
45
|
+
output[0] = _0vec3[0] * height;
|
|
46
|
+
output[1] = _0vec3[1] * height;
|
|
47
|
+
output[2] = _0vec3[2] * height;
|
|
110
48
|
};
|
|
111
|
-
|
|
112
|
-
*
|
|
113
|
-
* @param {wgs84} coordinates
|
|
114
|
-
* @returns {vec3}
|
|
115
|
-
*/
|
|
116
|
-
const wgs84ToUnitVector = (coordinates) => {
|
|
117
|
-
const long = coordinates[0] * RADIANS;
|
|
118
|
-
const lat = coordinates[1] * RADIANS;
|
|
119
|
-
const x = Math.cos(lat) * Math.cos(long);
|
|
120
|
-
const y = Math.cos(lat) * Math.sin(long);
|
|
121
|
-
const z = Math.sin(lat);
|
|
122
|
-
return [x, y, z];
|
|
123
|
-
};
|
|
124
|
-
/**
|
|
125
|
-
* @param {number} long wgs84
|
|
126
|
-
* @param {number} lat wgs84
|
|
127
|
-
* @param {number} height
|
|
128
|
-
* @returns {vec3} cartesian3D
|
|
129
|
-
*/
|
|
130
|
-
const wgs84ToCartesian3d = (long, lat, height) => {
|
|
49
|
+
export const wgs84ToCartesian3d = (long, lat, height) => {
|
|
131
50
|
const longRad = long * RADIANS;
|
|
132
51
|
const latRad = lat * RADIANS;
|
|
133
52
|
const x = Math.cos(latRad) * Math.cos(longRad);
|
|
@@ -136,29 +55,23 @@ const wgs84ToCartesian3d = (long, lat, height) => {
|
|
|
136
55
|
const radius = WORLD_RADIUS_3D + height;
|
|
137
56
|
return [x * radius, y * radius, z * radius];
|
|
138
57
|
};
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
|
|
144
|
-
const wgs84ToMercator = (long, lat) => {
|
|
145
|
-
return [WORLD_RADIUS_MERCATOR * long * RADIANS, WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + lat * RADIANS / 2))];
|
|
58
|
+
export const wgs84ToMercator = (long, lat) => {
|
|
59
|
+
return [
|
|
60
|
+
WORLD_RADIUS_MERCATOR * long * RADIANS,
|
|
61
|
+
WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + lat * RADIANS / 2))
|
|
62
|
+
];
|
|
146
63
|
};
|
|
147
|
-
|
|
148
|
-
* @param {vec2} pixelXY
|
|
149
|
-
* @returns {vec2} long lat in radians
|
|
150
|
-
*/
|
|
151
|
-
const pixelXYToRadians = (pixelXY) => {
|
|
64
|
+
export const pixelXYToRadians = (pixelXY) => {
|
|
152
65
|
const long = (2.0 * pixelXY[0] - 1.0) * Math.PI;
|
|
153
66
|
const lat = (2.0 * pixelXY[1] - 1.0) * Math.PI / 2.0;
|
|
154
67
|
return [long, lat];
|
|
155
68
|
};
|
|
156
|
-
const pixelXYLenghtToUnitVectorWithHeight = (pixelXYHeight) => {
|
|
157
|
-
const [long, lat] = pixelXYToRadians(pixelXYHeight);
|
|
69
|
+
export const pixelXYLenghtToUnitVectorWithHeight = (pixelXYHeight) => {
|
|
70
|
+
const [long, lat] = pixelXYToRadians([pixelXYHeight[0], pixelXYHeight[1]]);
|
|
158
71
|
const radius = WORLD_RADIUS_3D + pixelXYHeight[2];
|
|
159
|
-
return radianToCartesian3d([long, lat])
|
|
72
|
+
return [...radianToCartesian3d([long, lat]), radius];
|
|
160
73
|
};
|
|
161
|
-
const globe3Dcoordinates = (globe, height = 0) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
74
|
+
export const globe3Dcoordinates = (globe, height = 0) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
162
75
|
const len = longlats.length / 2;
|
|
163
76
|
const result = new Float32Array(len * 3 + paddingCount * 3).fill(paddingValue);
|
|
164
77
|
for (let i = 0; i < len; i++) {
|
|
@@ -169,7 +82,7 @@ const globe3Dcoordinates = (globe, height = 0) => (longlats, { paddingCount = 0,
|
|
|
169
82
|
}
|
|
170
83
|
return result;
|
|
171
84
|
};
|
|
172
|
-
const globe2Dcoordinates = (globe) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
85
|
+
export const globe2Dcoordinates = (globe) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
173
86
|
const len = longlats.length / 2;
|
|
174
87
|
const result = new Float32Array(len * 2 + paddingCount * 2).fill(paddingValue);
|
|
175
88
|
for (let i = 0; i < len; i++) {
|
|
@@ -180,4 +93,3 @@ const globe2Dcoordinates = (globe) => (longlats, { paddingCount = 0, paddingValu
|
|
|
180
93
|
}
|
|
181
94
|
return result;
|
|
182
95
|
};
|
|
183
|
-
export { RADIANS, normalize3, dot3, length3, cartesian3dToRadian, radianToMercator, radianToCartesian3d, sphericalLinearInterpolation_UnitVector, sphericalLinearInterpolation_Mercator, sphericalLinearInterpolation_Cartesian3d, wgs84ToUnitVector, wgs84ToCartesian3d, wgs84ToMercator, pixelXYLenghtToUnitVectorWithHeight, globe3Dcoordinates, globe2Dcoordinates, };
|
package/Math/methods1.js
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { WORLD_RADIUS_3D, WORLD_RADIUS_MERCATOR } from './constants';
|
|
2
|
+
/**
|
|
3
|
+
* @typedef {Array<number>} vec3 [x, y, z]
|
|
4
|
+
* @typedef {Array<number>} vec2 [x, y]
|
|
5
|
+
* @typedef {Array<number>} vec4 [x, y, z, w]
|
|
6
|
+
* @typedef {number} fraction a number between 0 and 1
|
|
7
|
+
* @typedef {Array<number>} wgs84 [long, lat]
|
|
8
|
+
*/
|
|
9
|
+
// *********************************************************
|
|
10
|
+
// **************** VECTOR OPERATIONS **********************
|
|
11
|
+
// *********************************************************
|
|
12
|
+
const RADIANS = Math.PI / 180;
|
|
13
|
+
/**
|
|
14
|
+
* @param {vec3} a
|
|
15
|
+
* @returns {vec3}
|
|
16
|
+
*/
|
|
17
|
+
const normalize3 = (a) => {
|
|
18
|
+
const len = length3(a);
|
|
19
|
+
return [a[0] / len, a[1] / len, a[2] / len];
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* @param {vec3} a
|
|
23
|
+
* @param {vec3} b
|
|
24
|
+
* @returns {number}
|
|
25
|
+
*/
|
|
26
|
+
const dot3 = (a, b) => {
|
|
27
|
+
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* @param {vec3} a
|
|
31
|
+
* @returns {number}
|
|
32
|
+
*/
|
|
33
|
+
const length3 = (a) => {
|
|
34
|
+
return Math.sqrt(dot3(a, a));
|
|
35
|
+
};
|
|
36
|
+
// *********************************************************
|
|
37
|
+
// **************** TRANSFORMATIONS ************************
|
|
38
|
+
// *********************************************************
|
|
39
|
+
/**
|
|
40
|
+
* @param {vec3} cartesian
|
|
41
|
+
* @returns {vec2} long lat in radians
|
|
42
|
+
*/
|
|
43
|
+
const cartesian3dToRadian = (cartesian) => {
|
|
44
|
+
const x = cartesian[0];
|
|
45
|
+
const y = cartesian[1];
|
|
46
|
+
const z = cartesian[2];
|
|
47
|
+
// const length = Math.sqrt(x * x + y * y + z * z);
|
|
48
|
+
const long = Math.atan2(y, x);
|
|
49
|
+
const lat = Math.asin(z); // length);
|
|
50
|
+
return [long, lat];
|
|
51
|
+
};
|
|
52
|
+
/**
|
|
53
|
+
* @param {vec2} xy long lat in radians
|
|
54
|
+
* @returns {vec2} long lat in mercator meters
|
|
55
|
+
*/
|
|
56
|
+
const radianToMercator = (xy) => {
|
|
57
|
+
return [WORLD_RADIUS_MERCATOR * xy[0], WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + xy[1] / 2))];
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* @param {vec2} xy long lat radians
|
|
61
|
+
* @returns {vec3} cartesian
|
|
62
|
+
*/
|
|
63
|
+
const radianToCartesian3d = (xy) => {
|
|
64
|
+
const x = Math.cos(xy[1]) * Math.cos(xy[0]);
|
|
65
|
+
const y = Math.cos(xy[1]) * Math.sin(xy[0]);
|
|
66
|
+
const z = -Math.sin(xy[1]);
|
|
67
|
+
return [x, y, z];
|
|
68
|
+
};
|
|
69
|
+
// *********************************************************
|
|
70
|
+
// ***************** INTERPOLATIONS ************************
|
|
71
|
+
// *********************************************************
|
|
72
|
+
/**
|
|
73
|
+
* @param {vec3} normalizedA
|
|
74
|
+
* @param {vec3} normalizedB
|
|
75
|
+
* @param {fraction} ratio
|
|
76
|
+
* @returns {vec3}
|
|
77
|
+
*/
|
|
78
|
+
const sphericalLinearInterpolation_UnitVector = (normalizedA, normalizedB, ratio) => {
|
|
79
|
+
const theta = Math.acos(dot3(normalizedA, normalizedB));
|
|
80
|
+
if (theta < 0.000001)
|
|
81
|
+
return normalizedA; // CALIBRATE?
|
|
82
|
+
const sinTheta = Math.sin(theta);
|
|
83
|
+
const result = [
|
|
84
|
+
(Math.sin((1.0 - ratio) * theta) * normalizedA[0] + Math.sin(ratio * theta) * normalizedB[0]) / sinTheta,
|
|
85
|
+
(Math.sin((1.0 - ratio) * theta) * normalizedA[1] + Math.sin(ratio * theta) * normalizedB[1]) / sinTheta,
|
|
86
|
+
(Math.sin((1.0 - ratio) * theta) * normalizedA[2] + Math.sin(ratio * theta) * normalizedB[2]) / sinTheta
|
|
87
|
+
];
|
|
88
|
+
return result;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* @param {vec3} normalizedA
|
|
92
|
+
* @param {vec3} normalizedB
|
|
93
|
+
* @param {fraction} ratio
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
const sphericalLinearInterpolation_Mercator = (normalizedA, normalizedB, ratio) => {
|
|
97
|
+
const unitVector = sphericalLinearInterpolation_UnitVector(normalizedA, normalizedB, ratio);
|
|
98
|
+
const angles = cartesian3dToRadian(unitVector);
|
|
99
|
+
return radianToMercator(angles);
|
|
100
|
+
};
|
|
101
|
+
/**
|
|
102
|
+
* @param {vec4} a vec3 unit vector and length
|
|
103
|
+
* @param {vec4} b vec3 unit vector and length
|
|
104
|
+
* @param {fraction} ratio
|
|
105
|
+
*/
|
|
106
|
+
const sphericalLinearInterpolation_Cartesian3d = (a, b, ratio) => {
|
|
107
|
+
const unitVector = sphericalLinearInterpolation_UnitVector(a, b, ratio);
|
|
108
|
+
const height = a[3] + (b[3] - a[3]) * ratio;
|
|
109
|
+
return [unitVector[0] * height, unitVector[1] * height, unitVector[2] * height];
|
|
110
|
+
};
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
* @param {wgs84} coordinates
|
|
114
|
+
* @returns {vec3}
|
|
115
|
+
*/
|
|
116
|
+
const wgs84ToUnitVector = (coordinates) => {
|
|
117
|
+
const long = coordinates[0] * RADIANS;
|
|
118
|
+
const lat = coordinates[1] * RADIANS;
|
|
119
|
+
const x = Math.cos(lat) * Math.cos(long);
|
|
120
|
+
const y = Math.cos(lat) * Math.sin(long);
|
|
121
|
+
const z = Math.sin(lat);
|
|
122
|
+
return [x, y, z];
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* @param {number} long wgs84
|
|
126
|
+
* @param {number} lat wgs84
|
|
127
|
+
* @param {number} height
|
|
128
|
+
* @returns {vec3} cartesian3D
|
|
129
|
+
*/
|
|
130
|
+
const wgs84ToCartesian3d = (long, lat, height) => {
|
|
131
|
+
const longRad = long * RADIANS;
|
|
132
|
+
const latRad = lat * RADIANS;
|
|
133
|
+
const x = Math.cos(latRad) * Math.cos(longRad);
|
|
134
|
+
const y = Math.cos(latRad) * Math.sin(longRad);
|
|
135
|
+
const z = Math.sin(latRad);
|
|
136
|
+
const radius = WORLD_RADIUS_3D + height;
|
|
137
|
+
return [x * radius, y * radius, z * radius];
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* @param {number} long
|
|
141
|
+
* @param {number} lat
|
|
142
|
+
* @returns {vec2} mercator
|
|
143
|
+
*/
|
|
144
|
+
const wgs84ToMercator = (long, lat) => {
|
|
145
|
+
return [WORLD_RADIUS_MERCATOR * long * RADIANS, WORLD_RADIUS_MERCATOR * Math.log(Math.tan(Math.PI / 4 + lat * RADIANS / 2))];
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* @param {vec2} pixelXY
|
|
149
|
+
* @returns {vec2} long lat in radians
|
|
150
|
+
*/
|
|
151
|
+
const pixelXYToRadians = (pixelXY) => {
|
|
152
|
+
const long = (2.0 * pixelXY[0] - 1.0) * Math.PI;
|
|
153
|
+
const lat = (2.0 * pixelXY[1] - 1.0) * Math.PI / 2.0;
|
|
154
|
+
return [long, lat];
|
|
155
|
+
};
|
|
156
|
+
const pixelXYLenghtToUnitVectorWithHeight = (pixelXYHeight) => {
|
|
157
|
+
const [long, lat] = pixelXYToRadians(pixelXYHeight);
|
|
158
|
+
const radius = WORLD_RADIUS_3D + pixelXYHeight[2];
|
|
159
|
+
return radianToCartesian3d([long, lat]).concat(radius);
|
|
160
|
+
};
|
|
161
|
+
const globe3Dcoordinates = (globe, height = 0) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
162
|
+
const len = longlats.length / 2;
|
|
163
|
+
const result = new Float32Array(len * 3 + paddingCount * 3).fill(paddingValue);
|
|
164
|
+
for (let i = 0; i < len; i++) {
|
|
165
|
+
const long = longlats[i * 2];
|
|
166
|
+
const lat = longlats[i * 2 + 1];
|
|
167
|
+
const xyz = globe.api_GetCartesian3DPoint(long, lat, height, 0);
|
|
168
|
+
result.set(xyz, i * 3);
|
|
169
|
+
}
|
|
170
|
+
return result;
|
|
171
|
+
};
|
|
172
|
+
const globe2Dcoordinates = (globe) => (longlats, { paddingCount = 0, paddingValue = NaN }) => {
|
|
173
|
+
const len = longlats.length / 2;
|
|
174
|
+
const result = new Float32Array(len * 2 + paddingCount * 2).fill(paddingValue);
|
|
175
|
+
for (let i = 0; i < len; i++) {
|
|
176
|
+
const long = longlats[i * 2];
|
|
177
|
+
const lat = longlats[i * 2 + 1];
|
|
178
|
+
const xyz = globe.api_GetMercator2DPoint(long, lat);
|
|
179
|
+
result.set(xyz, i * 2);
|
|
180
|
+
}
|
|
181
|
+
return result;
|
|
182
|
+
};
|
|
183
|
+
export { RADIANS, normalize3, dot3, length3, cartesian3dToRadian, radianToMercator, radianToCartesian3d, sphericalLinearInterpolation_UnitVector, sphericalLinearInterpolation_Mercator, sphericalLinearInterpolation_Cartesian3d, wgs84ToUnitVector, wgs84ToCartesian3d, wgs84ToMercator, pixelXYLenghtToUnitVectorWithHeight, globe3Dcoordinates, globe2Dcoordinates, };
|
|
@@ -5,7 +5,7 @@ import { ElementGlobeSufaceGlowCache } from '../programs/point-on-globe/element-
|
|
|
5
5
|
import { LineOnGlobeCache } from '../programs/line-on-globe/naive-accurate-flexible.js';
|
|
6
6
|
import { BufferOrchestrator, BufferManager } from "../util/account";
|
|
7
7
|
import { PickerDisplayer } from '../util/picking/picker-displayer.js';
|
|
8
|
-
import { wgs84ToCartesian3d, wgs84ToMercator } from '../Math/methods
|
|
8
|
+
import { wgs84ToCartesian3d, wgs84ToMercator } from '../Math/methods';
|
|
9
9
|
import { constraintFloat, opacityCheck } from '../util/check/typecheck.js';
|
|
10
10
|
import { createBufferAndReadInfo } from '../util/gl-util/buffer/attribute-loader';
|
|
11
11
|
import { CameraUniformBlockTotemCache } from '../programs/totems/camerauniformblock.js';
|
|
@@ -13,6 +13,8 @@ import { CameraUniformBlockTotemCache } from '../programs/totems/camerauniformbl
|
|
|
13
13
|
* is used with depth we can create a line from surface to the point.
|
|
14
14
|
*/
|
|
15
15
|
const glowOverSize = 1.35; // 1.25 is the default value in the shader
|
|
16
|
+
const _0vec6 = [0, 0, 0, 0, 0, 0];
|
|
17
|
+
const _0vec3 = [0, 0, 0];
|
|
16
18
|
class PointGlowLineToEarthPlugin {
|
|
17
19
|
constructor({ isGlowPointOn = true, isGlowSurfaceOn = true }) {
|
|
18
20
|
this.globe = null;
|
|
@@ -51,7 +53,14 @@ class PointGlowLineToEarthPlugin {
|
|
|
51
53
|
this._bufferManagersMap = new Map([
|
|
52
54
|
['pos3D', {
|
|
53
55
|
bufferManager: new BufferManager(gl, 6, { bufferType, initialCapacity }),
|
|
54
|
-
adaptor: (item) =>
|
|
56
|
+
adaptor: (item) => {
|
|
57
|
+
wgs84ToCartesian3d(_0vec6, item.long, item.lat, item.altitude / 1000);
|
|
58
|
+
wgs84ToCartesian3d(_0vec3, item.long, item.lat, 0 / 1000);
|
|
59
|
+
_0vec6[3] = _0vec3[0];
|
|
60
|
+
_0vec6[4] = _0vec3[1];
|
|
61
|
+
_0vec6[5] = _0vec3[2];
|
|
62
|
+
new Float32Array(_0vec6);
|
|
63
|
+
}
|
|
55
64
|
}],
|
|
56
65
|
['pos2D', {
|
|
57
66
|
bufferManager: new BufferManager(gl, 2, { bufferType, initialCapacity }),
|
package/package.json
CHANGED
package/timetracks/index.js
CHANGED
|
@@ -1,3 +1 @@
|
|
|
1
|
-
|
|
2
|
-
import { addCuttingPointLineStrip, featuresToLineStringData, fillSliceOfFloat32ArrayLineStrip, latLongToPixelXY } from './adaptors-line-strip';
|
|
3
|
-
export { Adaptor, fillSliceOfFloat32Array, createFloat32Array, TimeTracks, TimeTracksLineStrip, addCuttingPointLineStrip, featuresToLineStringData, fillSliceOfFloat32ArrayLineStrip, latLongToPixelXY };
|
|
1
|
+
"use strict";
|
|
@@ -7,6 +7,7 @@ import { sphericalLinearInterpolation_Cartesian3d, sphericalLinearInterpolation_
|
|
|
7
7
|
* @typedef {number} fraction a number between 0 and 1
|
|
8
8
|
* @typedef {Array<number>} wgs84 [long, lat]
|
|
9
9
|
*/
|
|
10
|
+
const _0vec3 = [0, 0, 0];
|
|
10
11
|
const GEOMETRY = Object.freeze({
|
|
11
12
|
CARTESIAN3D: 0,
|
|
12
13
|
MERCATOR: 1,
|
|
@@ -57,10 +58,13 @@ class TimeTrackInterpolator {
|
|
|
57
58
|
continue;
|
|
58
59
|
}
|
|
59
60
|
const timeFraction = (time - times[timeIndex]) / (times[timeIndex + 1] - times[timeIndex]);
|
|
60
|
-
|
|
61
|
-
sphericalLinearInterpolation_Cartesian3d(coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction)
|
|
62
|
-
|
|
63
|
-
|
|
61
|
+
if (geometry === GEOMETRY.CARTESIAN3D) {
|
|
62
|
+
sphericalLinearInterpolation_Cartesian3d(_0vec3, coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
sphericalLinearInterpolation_Mercator(_0vec3, coordinates[timeIndex], coordinates[timeIndex + 1], timeFraction);
|
|
66
|
+
}
|
|
67
|
+
resultArray.push(..._0vec3);
|
|
64
68
|
}
|
|
65
69
|
return new Float32Array(resultArray);
|
|
66
70
|
}
|