@eturnity/eturnity_maths 7.20.0 → 7.24.0
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/.eslintrc.js +28 -0
- package/.prettierrc +7 -0
- package/babel.config.js +2 -2
- package/eslint.config.mjs +10 -0
- package/package.json +5 -3
- package/src/config.js +110 -50
- package/src/coords.js +21 -21
- package/src/geo.js +111 -100
- package/src/geometry.js +920 -819
- package/src/index.js +10 -11
- package/src/intersectionPolygon.js +34 -28
- package/src/lib/concaveman.js +181 -181
- package/src/matrix.js +56 -50
- package/src/miscellaneous.js +45 -0
- package/src/objects/Circle.js +76 -41
- package/src/objects/Line.js +272 -177
- package/src/objects/Point.js +30 -27
- package/src/objects/Polygon.js +324 -243
- package/src/objects/derivedState/AddMargin.js +142 -145
- package/src/objects/derivedState/updateComputedGeometryPolygon.js +274 -253
- package/src/objects/graph/DFS.js +69 -69
- package/src/objects/graph/graphCreation.js +47 -44
- package/src/objects/hydrate.js +26 -26
- package/src/snap.js +24 -18
- package/src/splitMergePolygons.js +585 -521
- package/src/test/maths.test.js +7 -7
- package/src/vector.js +66 -66
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
env: {
|
|
3
|
+
browser: true,
|
|
4
|
+
es2021: true
|
|
5
|
+
},
|
|
6
|
+
extends: 'eslint:recommended',
|
|
7
|
+
overrides: [
|
|
8
|
+
{
|
|
9
|
+
env: {
|
|
10
|
+
node: true
|
|
11
|
+
},
|
|
12
|
+
files: ['.eslintrc.{js,cjs}'],
|
|
13
|
+
parserOptions: {
|
|
14
|
+
sourceType: 'script'
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
parserOptions: {
|
|
19
|
+
ecmaVersion: 'latest',
|
|
20
|
+
sourceType: 'module'
|
|
21
|
+
},
|
|
22
|
+
rules: {
|
|
23
|
+
indent: ['error', 'tab'],
|
|
24
|
+
'linebreak-style': ['error', 'unix'],
|
|
25
|
+
quotes: ['error', 'single'],
|
|
26
|
+
semi: ['error', 'never']
|
|
27
|
+
}
|
|
28
|
+
}
|
package/.prettierrc
ADDED
package/babel.config.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
module.exports = {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
presets: [['@babel/preset-env', { targets: { node: 'current' } }]]
|
|
3
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import globals from "globals";
|
|
2
|
+
import pluginJs from "@eslint/js";
|
|
3
|
+
import pluginVue from "eslint-plugin-vue";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
export default [
|
|
7
|
+
{languageOptions: { globals: globals.browser }},
|
|
8
|
+
pluginJs.configs.recommended,
|
|
9
|
+
...pluginVue.configs["flat/essential"],
|
|
10
|
+
];
|
package/package.json
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eturnity/eturnity_maths",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.24.0",
|
|
4
4
|
"author": "Eturnity Team",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"private": false,
|
|
7
7
|
"scripts": {
|
|
8
|
-
"test": "jest"
|
|
8
|
+
"test": "jest",
|
|
9
|
+
"prettier": "prettier --write \"**/*.js\""
|
|
9
10
|
},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
@@ -27,7 +28,8 @@
|
|
|
27
28
|
"@babel/core": "7.21.4",
|
|
28
29
|
"@babel/preset-env": "7.21.4",
|
|
29
30
|
"babel-jest": "29.5.0",
|
|
30
|
-
"jest": "29.5.0"
|
|
31
|
+
"jest": "29.5.0",
|
|
32
|
+
"prettier": "2.8.8"
|
|
31
33
|
},
|
|
32
34
|
"description": ""
|
|
33
35
|
}
|
package/src/config.js
CHANGED
|
@@ -1,72 +1,132 @@
|
|
|
1
1
|
import theme from './assets/theme'
|
|
2
2
|
|
|
3
|
-
export const polygonCloseTolerance=15
|
|
3
|
+
export const polygonCloseTolerance = 15
|
|
4
4
|
export const snapToPointTolerance = 15
|
|
5
5
|
export const snapToIntersectionPointTolerance = 15
|
|
6
6
|
export const snapToLineTolerance = 10
|
|
7
7
|
export const distanceToCloseNode = 70
|
|
8
|
-
export const mmTolerance=1
|
|
9
|
-
export const earthRadius=6371008
|
|
8
|
+
export const mmTolerance = 1
|
|
9
|
+
export const earthRadius = 6371008
|
|
10
10
|
|
|
11
11
|
export const layerColors = {
|
|
12
|
-
construction: {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
12
|
+
construction: {
|
|
13
|
+
fillColor: 'transparent',
|
|
14
|
+
strokeColor: theme.colors.blueElectric,
|
|
15
|
+
strokeWidth: 3
|
|
16
|
+
},
|
|
17
|
+
roof: {
|
|
18
|
+
fillColor: 'rgba(255, 255, 255, 0.1)',
|
|
19
|
+
strokeColor: 'white',
|
|
20
|
+
strokeWidth: 0
|
|
21
|
+
},
|
|
22
|
+
roofInside: {
|
|
23
|
+
fillColor: 'rgba(255, 255, 255, 0.1)',
|
|
24
|
+
strokeColor: 'white',
|
|
25
|
+
strokeWidth: 1
|
|
26
|
+
},
|
|
27
|
+
obstacle: { fillColor: theme.colors.red, strokeColor: 'red', strokeWidth: 1 },
|
|
28
|
+
panel: {
|
|
29
|
+
fillColor: 'rgba(115, 115, 229, 0.1)',
|
|
30
|
+
strokeColor: '#ffffff',
|
|
31
|
+
strokeWidth: 1
|
|
32
|
+
},
|
|
33
|
+
user_deactivated_panel: {
|
|
34
|
+
fillColor: 'rgba(115, 115, 229, 0.1)',
|
|
35
|
+
strokeColor: 'white',
|
|
36
|
+
strokeWidth: 4
|
|
37
|
+
},
|
|
38
|
+
selectedPanel: {
|
|
39
|
+
fillColor: '#0068DE80',
|
|
40
|
+
strokeColor: theme.colors.blue,
|
|
41
|
+
strokeWidth: 1
|
|
42
|
+
},
|
|
19
43
|
snap: { fillColor: 'transparent', strokeColor: 'white' },
|
|
20
|
-
moduleField: {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
moduleField: {
|
|
45
|
+
fillColor: 'rgba(255, 255, 255, 0.1)',
|
|
46
|
+
strokeColor: 'white',
|
|
47
|
+
strokeWidth: 3
|
|
48
|
+
},
|
|
49
|
+
hoveredModuleFieldEdge: { strokeColor: theme.colors.blue, strokeWidth: 6 },
|
|
50
|
+
tmpModuleField: {
|
|
51
|
+
fillColor: 'rgba(115, 115, 229, 0.4)',
|
|
52
|
+
strokeColor: theme.colors.blue,
|
|
53
|
+
strokeWidth: 2
|
|
54
|
+
},
|
|
55
|
+
selectedModuleField: {
|
|
56
|
+
fillColor: '#0068DE80',
|
|
57
|
+
strokeColor: theme.colors.blue,
|
|
58
|
+
strokeWidth: 3
|
|
59
|
+
},
|
|
60
|
+
highlight: {
|
|
61
|
+
fillColor: 'rgba(255, 255, 255, 0.2)',
|
|
62
|
+
strokeColor: 'white',
|
|
63
|
+
strokeWidth: 1
|
|
64
|
+
},
|
|
65
|
+
selectedRoof: {
|
|
66
|
+
fillColor: '#0068DE80',
|
|
67
|
+
strokeColor: 'white',
|
|
68
|
+
strokeWidth: 3
|
|
69
|
+
},
|
|
70
|
+
selectedObstacle: {
|
|
71
|
+
fillColor: '#0068DE80',
|
|
72
|
+
strokeColor: theme.colors.blue,
|
|
73
|
+
strokeWidth: 2
|
|
74
|
+
},
|
|
75
|
+
selectedAndHighlighted: {
|
|
76
|
+
fillColor: '#0068DEA0',
|
|
77
|
+
strokeColor: theme.colors.blue,
|
|
78
|
+
strokeWidth: 3
|
|
79
|
+
},
|
|
80
|
+
flatWarning: {
|
|
81
|
+
fillColor: '#ffff0090',
|
|
82
|
+
strokeColor: 'yellow',
|
|
83
|
+
strokeWidth: 1
|
|
84
|
+
},
|
|
85
|
+
customLength: {
|
|
86
|
+
fillColor: 'transparent',
|
|
87
|
+
strokeColor: theme.colors.blueElectric,
|
|
88
|
+
strokeWidth: 1
|
|
89
|
+
}
|
|
30
90
|
}
|
|
31
91
|
|
|
32
|
-
export const baseEdgeOfModuleField=theme.colors.blueElectric
|
|
33
|
-
export const maximumGapLimit=500
|
|
34
|
-
export const defaultBaseHeight=3000
|
|
35
|
-
export const colorArrayBase=[
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
92
|
+
export const baseEdgeOfModuleField = theme.colors.blueElectric
|
|
93
|
+
export const maximumGapLimit = 500
|
|
94
|
+
export const defaultBaseHeight = 3000
|
|
95
|
+
export const colorArrayBase = [
|
|
96
|
+
'#FF5656',
|
|
97
|
+
'#FDB813',
|
|
98
|
+
'#505CA6',
|
|
99
|
+
'#C84E4E',
|
|
100
|
+
'#8392EE',
|
|
101
|
+
'#6CD5D5',
|
|
102
|
+
'#90A650',
|
|
103
|
+
'#D27CCA',
|
|
104
|
+
'#6276DF'
|
|
45
105
|
]
|
|
46
|
-
export const colorArray=colorArrayBase.map(c=>c+
|
|
47
|
-
export const layerTools={
|
|
48
|
-
map:[],
|
|
49
|
-
roof:[
|
|
50
|
-
obstacle:[
|
|
51
|
-
margin:[
|
|
52
|
-
panel:[
|
|
106
|
+
export const colorArray = colorArrayBase.map((c) => c + 'c0')
|
|
107
|
+
export const layerTools = {
|
|
108
|
+
map: [],
|
|
109
|
+
roof: ['drawRoof', 'selectRoof'],
|
|
110
|
+
obstacle: ['drawObstacle'],
|
|
111
|
+
margin: ['selectMargin'],
|
|
112
|
+
panel: ['selectModuleField']
|
|
53
113
|
}
|
|
54
114
|
//3D visualisation:
|
|
55
|
-
export const beamRadius=0.05
|
|
56
|
-
export const maxMargin=2500
|
|
57
|
-
export const node3DRadius=0.05
|
|
58
|
-
export const beamColor=
|
|
59
|
-
export const node3DColor=
|
|
60
|
-
export const beamOpacity=0.3
|
|
61
|
-
export const node3dOpacity=0.3
|
|
62
|
-
export const dimMarginColor='#ff000020'
|
|
115
|
+
export const beamRadius = 0.05
|
|
116
|
+
export const maxMargin = 2500
|
|
117
|
+
export const node3DRadius = 0.05
|
|
118
|
+
export const beamColor = '#ffffff'
|
|
119
|
+
export const node3DColor = 'white'
|
|
120
|
+
export const beamOpacity = 0.3
|
|
121
|
+
export const node3dOpacity = 0.3
|
|
122
|
+
export const dimMarginColor = '#ff000020'
|
|
63
123
|
export const hitOption = {
|
|
64
124
|
segments: true,
|
|
65
125
|
stroke: true,
|
|
66
126
|
fill: true,
|
|
67
127
|
tolerance: 10
|
|
68
128
|
}
|
|
69
|
-
export const zoomFactor=Math.exp(Math.log(2)/10)
|
|
129
|
+
export const zoomFactor = Math.exp(Math.log(2) / 10)
|
|
70
130
|
export const hitOptionPolygonStrict = {
|
|
71
131
|
segments: false,
|
|
72
132
|
stroke: false,
|
|
@@ -74,4 +134,4 @@ export const hitOptionPolygonStrict = {
|
|
|
74
134
|
tolerance: 0
|
|
75
135
|
}
|
|
76
136
|
|
|
77
|
-
export const dragHeightSensitivity=20
|
|
137
|
+
export const dragHeightSensitivity = 20
|
package/src/coords.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
export function toRealityRefFunction(canvasSize, mmPerPx, layoutOffset) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
2
|
+
return (point) => {
|
|
3
|
+
let realityX = (point.x - layoutOffset.x) * mmPerPx
|
|
4
|
+
// let realityY = -(point.y - layoutOffset.y - (canvasSize.height*layoutOffset.zoom)/(100 * 2)) * mmPerPx
|
|
5
|
+
let realityY = -(point.y - layoutOffset.y) * mmPerPx
|
|
6
|
+
|
|
7
|
+
return { x: realityX, y: realityY, z: point.z }
|
|
9
8
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
let canvasX = layoutOffset.x + point.x / mmPerPx
|
|
20
|
-
let canvasY = layoutOffset.y - point.y / mmPerPx
|
|
21
|
-
|
|
22
|
-
return { x: canvasX, y: canvasY, z: point.z }
|
|
9
|
+
}
|
|
10
|
+
export function toCanvasRefFunction(canvasSize, mmPerPx, layoutOffset) {
|
|
11
|
+
return (point) => {
|
|
12
|
+
if (!point) {
|
|
13
|
+
console.error('no point', point)
|
|
14
|
+
}
|
|
15
|
+
if (!canvasSize) {
|
|
16
|
+
console.error('no canvas Size')
|
|
17
|
+
return null
|
|
23
18
|
}
|
|
24
|
-
|
|
19
|
+
let canvasX = layoutOffset.x + point.x / mmPerPx
|
|
20
|
+
let canvasY = layoutOffset.y - point.y / mmPerPx
|
|
21
|
+
|
|
22
|
+
return { x: canvasX, y: canvasY, z: point.z }
|
|
23
|
+
}
|
|
24
|
+
}
|
package/src/geo.js
CHANGED
|
@@ -1,107 +1,118 @@
|
|
|
1
|
-
import {
|
|
2
|
-
earthRadius
|
|
3
|
-
} from './config'
|
|
1
|
+
import { earthRadius } from './config'
|
|
4
2
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export function
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
3
|
+
export function lon2tile(lon, zoom) {
|
|
4
|
+
return Math.floor(((lon + 180) / 360) * Math.pow(2, zoom))
|
|
5
|
+
}
|
|
6
|
+
export function lat2tile(lat, zoom) {
|
|
7
|
+
return Math.floor(
|
|
8
|
+
((1 -
|
|
9
|
+
Math.log(
|
|
10
|
+
Math.tan((lat * Math.PI) / 180) + 1 / Math.cos((lat * Math.PI) / 180)
|
|
11
|
+
) /
|
|
12
|
+
Math.PI) /
|
|
13
|
+
2) *
|
|
14
|
+
Math.pow(2, zoom)
|
|
15
|
+
)
|
|
16
|
+
}
|
|
17
|
+
export function tile2long(x, z) {
|
|
18
|
+
return (x / Math.pow(2, z)) * 360 - 180
|
|
19
|
+
}
|
|
20
|
+
export function tile2lat(y, z) {
|
|
21
|
+
var n = Math.PI - (2 * Math.PI * y) / Math.pow(2, z)
|
|
22
|
+
return (180 / Math.PI) * Math.atan(0.5 * (Math.exp(n) - Math.exp(-n)))
|
|
23
|
+
}
|
|
24
|
+
export function latLngToTileXY(lat, lng, zoom) {
|
|
25
|
+
const xTile = lon2tile(lng, zoom)
|
|
26
|
+
const yTile = lat2tile(lat, zoom)
|
|
27
|
+
return {
|
|
28
|
+
x: xTile,
|
|
29
|
+
y: yTile
|
|
22
30
|
}
|
|
23
|
-
|
|
24
|
-
export function tileXYZToLatLng(x,y,zoom){
|
|
25
|
-
const longitude=tile2long(x,zoom)
|
|
26
|
-
const latitude=tile2lat(y,zoom)
|
|
27
|
-
return {lat: latitude,lng: longitude};
|
|
28
|
-
}
|
|
31
|
+
}
|
|
29
32
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
y:y_mm-size,
|
|
50
|
-
z:tileAltitude
|
|
51
|
-
}
|
|
52
|
-
let corner3={
|
|
53
|
-
x:x_mm,
|
|
54
|
-
y:y_mm-size,
|
|
55
|
-
z:tileAltitude
|
|
56
|
-
}
|
|
57
|
-
return [
|
|
58
|
-
corner3,
|
|
59
|
-
corner0,
|
|
60
|
-
corner1,
|
|
61
|
-
corner2,
|
|
62
|
-
]
|
|
63
|
-
}
|
|
64
|
-
export function distanceToDeltaLatLng(x, y, latitude) {
|
|
65
|
-
//x,y,z in ENU coords
|
|
66
|
-
let lat = (180 / Math.PI) * (y / 1000) / earthRadius
|
|
67
|
-
let lng =((180 / Math.PI) * (x / 1000) / earthRadius)/(Math.cos(((latitude) * Math.PI) / 180))
|
|
68
|
-
return { lat, lng }
|
|
69
|
-
}
|
|
70
|
-
export function deltaLatLngToDistance(deltaLat, deltaLng, latitude) {
|
|
71
|
-
//x,y,z in ENU coords
|
|
72
|
-
let y=earthRadius * deltaLat *1000/(180 / Math.PI)
|
|
73
|
-
let x=earthRadius* deltaLng * 1000 *(Math.cos(((latitude) * Math.PI) / 180))/(180 / Math.PI)
|
|
74
|
-
return { x, y }
|
|
33
|
+
export function tileXYZToLatLng(x, y, zoom) {
|
|
34
|
+
const longitude = tile2long(x, zoom)
|
|
35
|
+
const latitude = tile2lat(y, zoom)
|
|
36
|
+
return { lat: latitude, lng: longitude }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function tileToCorners(x, y, zoom, lat, lng) {
|
|
40
|
+
const tileAltitude = 0
|
|
41
|
+
const tileLatLng = tileXYZToLatLng(x, y, zoom)
|
|
42
|
+
const deltaLat = tileLatLng.lat - lat
|
|
43
|
+
const deltaLng = tileLatLng.lng - lng
|
|
44
|
+
let { x: x_mm, y: y_mm } = deltaLatLngToDistance(deltaLat, deltaLng, lat)
|
|
45
|
+
let size =
|
|
46
|
+
((earthRadius * 2000 * Math.PI) / Math.pow(2.0, zoom)) *
|
|
47
|
+
Math.cos((lat * Math.PI) / 180)
|
|
48
|
+
let corner0 = {
|
|
49
|
+
x: x_mm,
|
|
50
|
+
y: y_mm,
|
|
51
|
+
z: tileAltitude
|
|
75
52
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
//const d = earthRadius * arccos[(sin(lat1) * sin(lat2)) + cos(lat1) * cos(lat2) * cos(lng2 – lng1)]
|
|
81
|
-
const averageLat = (lat1 + lat2) / 2
|
|
82
|
-
const x =
|
|
83
|
-
1000 *
|
|
84
|
-
earthRadius *
|
|
85
|
-
arccos(
|
|
86
|
-
sin(averageLat) * sin(averageLat) +
|
|
87
|
-
cos(averageLat) * cos(averageLat) * cos(lng2 - lng1)
|
|
88
|
-
)
|
|
89
|
-
const y =
|
|
90
|
-
1000 * earthRadius * arccos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2))
|
|
91
|
-
|
|
92
|
-
// const x = longitude * earthOrigin / 180.0;
|
|
93
|
-
// let y = Math.log(Math.tan((90 + latitude) * Math.PI / 360.0)) / (Math.PI / 180.0);
|
|
94
|
-
|
|
95
|
-
// y = y * earthOrigin / 180.0;
|
|
96
|
-
|
|
97
|
-
return { x, y }
|
|
53
|
+
let corner1 = {
|
|
54
|
+
x: x_mm + size,
|
|
55
|
+
y: y_mm,
|
|
56
|
+
z: tileAltitude
|
|
98
57
|
}
|
|
99
|
-
|
|
100
|
-
|
|
58
|
+
let corner2 = {
|
|
59
|
+
x: x_mm + size,
|
|
60
|
+
y: y_mm - size,
|
|
61
|
+
z: tileAltitude
|
|
101
62
|
}
|
|
102
|
-
|
|
103
|
-
|
|
63
|
+
let corner3 = {
|
|
64
|
+
x: x_mm,
|
|
65
|
+
y: y_mm - size,
|
|
66
|
+
z: tileAltitude
|
|
104
67
|
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
68
|
+
return [corner3, corner0, corner1, corner2]
|
|
69
|
+
}
|
|
70
|
+
export function distanceToDeltaLatLng(x, y, latitude) {
|
|
71
|
+
//x,y,z in ENU coords
|
|
72
|
+
let lat = ((180 / Math.PI) * (y / 1000)) / earthRadius
|
|
73
|
+
let lng =
|
|
74
|
+
((180 / Math.PI) * (x / 1000)) /
|
|
75
|
+
earthRadius /
|
|
76
|
+
Math.cos((latitude * Math.PI) / 180)
|
|
77
|
+
return { lat, lng }
|
|
78
|
+
}
|
|
79
|
+
export function deltaLatLngToDistance(deltaLat, deltaLng, latitude) {
|
|
80
|
+
//x,y,z in ENU coords
|
|
81
|
+
let y = (earthRadius * deltaLat * 1000) / (180 / Math.PI)
|
|
82
|
+
let x =
|
|
83
|
+
(earthRadius * deltaLng * 1000 * Math.cos((latitude * Math.PI) / 180)) /
|
|
84
|
+
(180 / Math.PI)
|
|
85
|
+
return { x, y }
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export function datum2spherical(lat1, lat2, lng1, lng2) {
|
|
89
|
+
const earthOrigin = Math.PI * earthRadius
|
|
90
|
+
|
|
91
|
+
//const d = earthRadius * arccos[(sin(lat1) * sin(lat2)) + cos(lat1) * cos(lat2) * cos(lng2 – lng1)]
|
|
92
|
+
const averageLat = (lat1 + lat2) / 2
|
|
93
|
+
const x =
|
|
94
|
+
1000 *
|
|
95
|
+
earthRadius *
|
|
96
|
+
arccos(
|
|
97
|
+
sin(averageLat) * sin(averageLat) +
|
|
98
|
+
cos(averageLat) * cos(averageLat) * cos(lng2 - lng1)
|
|
99
|
+
)
|
|
100
|
+
const y =
|
|
101
|
+
1000 * earthRadius * arccos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2))
|
|
102
|
+
|
|
103
|
+
// const x = longitude * earthOrigin / 180.0;
|
|
104
|
+
// let y = Math.log(Math.tan((90 + latitude) * Math.PI / 360.0)) / (Math.PI / 180.0);
|
|
105
|
+
|
|
106
|
+
// y = y * earthOrigin / 180.0;
|
|
107
|
+
|
|
108
|
+
return { x, y }
|
|
109
|
+
}
|
|
110
|
+
function cos(deg) {
|
|
111
|
+
return Math.cos((deg * Math.PI) / 180)
|
|
112
|
+
}
|
|
113
|
+
function sin(deg) {
|
|
114
|
+
return Math.sin((deg * Math.PI) / 180)
|
|
115
|
+
}
|
|
116
|
+
function arccos(val) {
|
|
117
|
+
return Math.acos(val)
|
|
118
|
+
}
|