You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Quaternion.js is a well tested JavaScript library for 3D rotations. Quaternions can be used everywhere, from the rotation calculation of your mobile phone over computer games to the rotation of satellites and all by avoiding the [Gimbal lock](https://en.wikipedia.org/wiki/Gimbal_lock). The library comes with examples to make you get started much quicker without worrying about the math behind.
6
+
Quaternion.js is a well tested JavaScript library for 3D rotations. Quaternions can be used everywhere, from the rotation calculation of your mobile phone over computer games to the rotation of satellites and all by avoiding the [Gimbal lock](https://en.wikipedia.org/wiki/Gimbal_lock). The library comes with examples to make you get started much quicker without worrying about the math behind. But if you care, have a look at the [Quaternion Introduction](https://raw.org/book/algebra/quaternions/).
Any function (see below) as well as the constructor of the *Quaternion* class parses its input like this.
41
41
@@ -100,8 +100,8 @@ new Quaternion("i");
100
100
```
101
101
102
102
103
-
Functions
104
-
===
103
+
## Functions
104
+
105
105
106
106
Every stated parameter *n* in the following list of functions behaves in the same way as the constructor examples above
107
107
@@ -223,7 +223,7 @@ Clones the actual object
223
223
224
224
Array rotateVector(v)
225
225
---
226
-
Rotates a 3 component vector, represented as an array by the current quaternion
226
+
Rotates a 3 component vector, represented as an array by the current quaternion in an [efficient manner](https://raw.org/proof/vector-rotation-using-quaternions/).
Euler angles are probably the reason to use quaternions. The definition is mostly sloppy and you can only decide how it was defined based on the matrix representation. A `ZXY` in one definition is the multiplication order read from right to left and in another the execution order from left to right. Quaternion.js provides two functions, `fromEulerLogical()`, where the angles and order are applied from left to right (logical application order) and `fromEuler()` which reverses the order of the argument list (technical multiplication order).
245
245
246
-
So for `fromEulerLogical(ϕ, θ, ψ, "ZXY")`, for example means first rotate around Z by ϕ then around X by θ and then around Y by ψ (`RotY(ψ)RotX(θ)RotZ(ϕ)`).
246
+
So for `fromEulerLogical(ϕ, θ, ψ, "ZXY")`, for example means first rotate around Z axis by ϕ then around X axis by θ and then around axis Y by ψ (`RotY(ψ)RotX(θ)RotZ(ϕ)`).
247
247
248
248
The order of `fromEuler()` can take the string value `ZXY (default), XYZ / RPY, YXZ, ZYX / YPR, YZX, XZY, ZYZ, ZXZ, YXY, YZY, XYX, XZX`.
249
249
@@ -262,18 +262,16 @@ The order of `fromEuler()` can take the string value `ZXY (default), XYZ / RPY,
262
262
-`fromEuler(x, y, z, 'XZY') = ThreeJSfromEuler(x, z, y, 'XZY')`
263
263
264
264
265
-
266
-
267
265
Quaternion.fromBetweenVectors(u, v)
268
266
---
269
-
Calculates the quaternion to rotate vector `u` onto vector `v`, represented as 3 element arrays.
267
+
Calculates the quaternion to rotate vector `u` onto vector `v`, represented as 3 element arrays, which can be done [elegantly using quaternions](https://raw.org/proof/quaternion-from-two-vectors/).
270
268
271
269
Quaternion.random()
272
270
---
273
271
Gets a spherical random number
274
272
275
-
Constants
276
-
===
273
+
## Constants
274
+
277
275
278
276
Quaternion.ZERO
279
277
---
@@ -298,53 +296,47 @@ An imaginary number k instance
298
296
299
297
300
298
301
-
Installation
302
-
===
303
-
Installing Quaternion.js is as easy as cloning this repo or use one of the following commands:
299
+
## Installation
304
300
305
-
```
306
-
bower install quaternion
307
-
```
308
-
or
301
+
Installing Quaternion.js is as easy as cloning this repo or use one of the following command:
309
302
310
-
```
303
+
304
+
```bash
311
305
npm install quaternion
312
306
```
313
307
314
-
Using Quaternion.js with the browser
315
-
===
316
-
```html
317
-
<scriptsrc="quaternion.js"></script>
318
-
<script>
319
-
console.log(Quaternion("1 + 2i - 3j + 4k"));
320
-
</script>
321
-
```
308
+
## Using Quaternion.js with the browser
322
309
323
-
Using Quaternion.js with require.js
324
-
===
325
310
```html
326
-
<scriptsrc="require.js"></script>
311
+
<scriptsrc="quaternion.min.js"></script>
327
312
<script>
328
-
requirejs(['quaternion.js'],
329
-
function(Quaternion) {
330
313
console.log(Quaternion("1 + 2i - 3j + 4k"));
331
-
});
332
314
</script>
333
315
```
334
-
Coding Style
335
-
===
316
+
317
+
318
+
##Coding Style
319
+
336
320
As every library I publish, Quaternion.js is also built to be as small as possible after compressing it with Google Closure Compiler in advanced mode. Thus the coding style orientates a little on maxing-out the compression rate. Please make sure you keep this style if you plan to extend the library.
337
321
338
-
Testing
339
-
===
340
-
If you plan to enhance the library, make sure you add test cases and all the previous tests are passing. You can test the library with
322
+
##Building the library
323
+
324
+
After cloning the Git repository run:
325
+
326
+
```
327
+
npm install
328
+
npm run build
329
+
```
330
+
331
+
##Run a test
332
+
333
+
Testing the source against the shipped test suite is as easy as
0 commit comments