@wemap/geo 0.1.2 → 0.1.4

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/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import Attitude from './src/rotations/Attitude';
1
2
  import Constants from './src/Constants';
2
3
  import Edge from './src/graph/Edge';
3
4
  import Itinerary from './src/graph/Itinerary';
@@ -7,6 +8,7 @@ import WGS84 from './src/coordinates/WGS84';
7
8
  import WGS84UserPosition from './src/coordinates/WGS84UserPosition';
8
9
 
9
10
  export {
11
+ Attitude,
10
12
  Constants,
11
13
  Edge,
12
14
  Itinerary,
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/geo"
13
13
  },
14
14
  "name": "@wemap/geo",
15
- "version": "0.1.2",
15
+ "version": "0.1.4",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-utils-js/issues"
18
18
  },
@@ -26,5 +26,5 @@
26
26
  "wemap"
27
27
  ],
28
28
  "license": "ISC",
29
- "gitHead": "83e0fae1464d1b856962f1b1c8cb8e5c085be797"
29
+ "gitHead": "991a53f06eed6adb872fad2cbd70a4edf7ee9cf9"
30
30
  }
@@ -1,10 +1,12 @@
1
- import { Utils, Vector3, Quaternion } from '@wemap/maths';
1
+ import {
2
+ Utils, Vector3, Quaternion
3
+ } from '@wemap/maths';
2
4
  import Constants from '../Constants';
3
5
 
4
6
 
5
7
  class WGS84 {
6
8
 
7
- constructor(lat, lng, alt = 0) {
9
+ constructor(lat, lng, alt) {
8
10
  this._lat = lat;
9
11
  this._lng = lng;
10
12
  this._alt = alt;
@@ -208,12 +210,20 @@ class WGS84 {
208
210
 
209
211
  const G = Vector3.cross(a, b);
210
212
  const F = Vector3.cross(c, G);
211
- let t = Vector3.normalize(Vector3.cross(G, F));
213
+ const t = Vector3.normalize(Vector3.cross(G, F));
212
214
 
213
- t = Vector3.multiplyScalar(t, this.getEarthRadiusAtPosition());
215
+ const posECEF = Vector3.multiplyScalar(t, this.getEarthRadiusAtPosition());
216
+ const poseWGS84 = WGS84.fromECEF(posECEF);
217
+
218
+ // poseWGS84.alt is not 0 here due to the ECEF transformation residual.
219
+ // So if p1.alt and p2.alt are defined we take the middle elevation between p1 and p2.
220
+ // Otherwise we remove alt from projection because the residual has no sense.
221
+ let alt;
222
+ if (typeof p1.alt !== 'undefined' && typeof p2.alt !== 'undefined') {
223
+ alt = (p1.alt + p2.alt) / 2;
224
+ }
225
+ const projection = new WGS84(poseWGS84.lat, poseWGS84.lng, alt);
214
226
 
215
- const projection = WGS84.fromECEF(t);
216
- projection.alt = p1.alt && p2.alt ? (p1.alt + p2.alt) / 2 : 0;
217
227
  if (Math.abs((p1.distanceTo(p2) - p1.distanceTo(projection) - p2.distanceTo(projection))) > 1e-6) {
218
228
  return null;
219
229
  }
@@ -1,7 +1,7 @@
1
- /* eslint complexity: ["error", 21]*/
1
+ /* eslint complexity: ["error", 22]*/
2
2
  /* eslint max-statements: ["error", 45]*/
3
3
 
4
- import { Utils as MathUtils} from '@wemap/maths';
4
+ import { Utils as MathUtils } from '@wemap/maths';
5
5
  import Network from './Network';
6
6
 
7
7
  const rad2deg = MathUtils.rad2deg;
@@ -97,6 +97,8 @@ class MapMatching {
97
97
 
98
98
  if (!projection.projection) {
99
99
  return null;
100
+ } else if (typeof projection.projection.alt === 'undefined') {
101
+ projection.projection.alt = location.alt;
100
102
  }
101
103
 
102
104
  return projection;
@@ -0,0 +1,65 @@
1
+ import {
2
+ Rotations, Utils as MathUtils, Quaternion
3
+ } from '@wemap/maths';
4
+
5
+ const rotxM90 = Quaternion.fromAxisAngle([1, 0, 0], -Math.PI / 2);
6
+
7
+ class Attitude {
8
+
9
+ quaternion = [1, 0, 0, 0];
10
+ quaternionThreeJsV = null;
11
+ headingV = null;
12
+ headingDegreesV = null;
13
+ eulerAnglesV = null;
14
+ eulerAnglesDegreesV = null;
15
+
16
+ constructor(quaternion) {
17
+ this.quaternion = quaternion;
18
+ }
19
+
20
+ get eulerAngles() {
21
+ if (!this.eulerAnglesV) {
22
+ this.eulerAnglesV = Rotations.quaternionToEulerZXY(this.quaternion);
23
+ }
24
+ return this.eulerAnglesV;
25
+ }
26
+
27
+ get eulerAnglesDegrees() {
28
+ if (!this.eulerAnglesDegreesV) {
29
+ this.eulerAnglesDegreesV = Rotations.quaternionToEulerZXYDegrees(this.quaternion);
30
+ }
31
+ return this.eulerAnglesDegreesV;
32
+ }
33
+
34
+ get heading() {
35
+ if (!this.headingV) {
36
+ this.headingV = Rotations.getHeadingFromQuaternion(this.quaternion) + MathUtils.deg2rad(window.orientation || 0);
37
+ }
38
+ return this.headingV;
39
+ }
40
+
41
+ get headingDegrees() {
42
+ if (!this.headingDegreesV) {
43
+ this.headingDegreesV = MathUtils.rad2deg(Rotations.getHeadingFromQuaternion(this.quaternion)) + (window.orientation || 0);
44
+ }
45
+ return this.headingDegreesV;
46
+ }
47
+
48
+ get quaternionThreeJs() {
49
+ if (!this.quaternionThreeJsV) {
50
+ this.quaternionThreeJsV = Quaternion.wxyz2xyzw(Quaternion.multiply(rotxM90, this.quaternion));
51
+ }
52
+ return this.quaternionThreeJsV;
53
+ }
54
+
55
+ toMessage() {
56
+ return this.quaternion;
57
+ }
58
+
59
+ static fromMessage(message) {
60
+ return new Attitude(message);
61
+ }
62
+
63
+ }
64
+
65
+ export default Attitude;