@wemap/maths 3.1.11 → 3.1.14

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 (2) hide show
  1. package/package.json +2 -2
  2. package/src/Rotations.js +12 -21
package/package.json CHANGED
@@ -12,7 +12,7 @@
12
12
  "directory": "packages/maths"
13
13
  },
14
14
  "name": "@wemap/maths",
15
- "version": "3.1.11",
15
+ "version": "3.1.14",
16
16
  "bugs": {
17
17
  "url": "https://github.com/wemap/wemap-modules-js/issues"
18
18
  },
@@ -26,5 +26,5 @@
26
26
  "wemap"
27
27
  ],
28
28
  "license": "ISC",
29
- "gitHead": "1e72b637bcc6e4d378bdb7c93870228636bdcb35"
29
+ "gitHead": "a79ee51029fda415610ca86a29e7a22d5f3ada60"
30
30
  }
package/src/Rotations.js CHANGED
@@ -1,13 +1,5 @@
1
1
  import Utils from './Utils';
2
2
 
3
- // import Constants from '../../geo/src/Constants';
4
-
5
-
6
- // Shortcuts to avoid reprocessing
7
- // const quatRotX90 = [Math.sqrt(2) / 2, -Math.sqrt(2) / 2, 0, 0];
8
- const rw = Math.sqrt(2) / 2;
9
- const rx = - Math.sqrt(2) / 2;
10
-
11
3
  class Rotations {
12
4
 
13
5
  // ZXY because yaw is around Z axis, pitch around X axis and roll around Y axis.
@@ -91,25 +83,24 @@ class Rotations {
91
83
  // Minus before "yaw" angle is here because ENU attitude is counter-clockwise whereas Coordinates is clockwise.
92
84
 
93
85
  const [qw, qx, qy, qz] = quaternion;
94
- if (Math.asin(2 * qy * qz + 2 * qx * qw) < Math.PI / 4) {
86
+ const qwqx = qw * qx;
87
+ const qyqz = qy * qz;
88
+ const qxqx = qx ** 2;
89
+
90
+ if (Math.asin(2 * qwqx + qyqz) < Math.PI / 4 && (qxqx + qy ** 2) < 0.5) {
95
91
  // Map version
96
- return -Math.atan2(2 * qz * qw - 2 * qy * qx, 1 - 2 * qz * qz - 2 * qx * qx);
92
+ return - Math.atan2(qw * qz - qx * qy, 0.5 - qxqx - qz ** 2);
97
93
  }
98
94
  // AR version
99
- const [pw, px, py, pz] = [
100
- qw * rw - qx * rx,
101
- qw * rx + rw * qx,
102
- rw * qy + qz * rx,
103
- rw * qz - qy * rx
104
- ];
105
- return -Math.atan2(2 * pz * pw - 2 * py * px, 1 - 2 * pz * pz - 2 * px * px);
106
-
107
- // ---- Not optimized version ----
95
+ return - Math.atan2(qx * qz + qw * qy, qwqx - qyqz);
96
+
97
+ // // ---- Not optimized version ----
108
98
  // const eulerAngles = Rotations.quaternionToEulerZXY(quaternion);
109
- // if (eulerAngles[1] < Math.PI / 4) {
99
+ // const eulerAnglesAR = Rotations.quaternionToEulerZXY(Quaternion.multiply(quaternion, quatRotX90));
100
+
101
+ // if (eulerAngles[1] < Math.PI / 4 && eulerAnglesAR[1] < 0) {
110
102
  // return -eulerAngles[0];
111
103
  // }
112
- // const eulerAnglesAR = Rotations.quaternionToEulerZXY(Quaternion.multiply(quaternion, quatRotX90));
113
104
  // return -eulerAnglesAR[0];
114
105
  }
115
106
  }