npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@kkitahara/quaternion-algebra

v1.0.4

Published

ECMAScript modules for exactly manipulating quaternions of which coefficients are numbers of the form (p / q)sqrt(b).

Downloads

20

Readme

JavaScript Style Guide license pipeline status coverage report version bundle size downloads per month downloads total

QuaternionAlgebra

ECMAScript modules for exactly manipulating quaternions of which coefficients are numbers of the form (p / q)sqrt(b), where p is an integer, q is a positive (non-zero) integer, and b is a positive, square-free integer.

Installation

npm install @kkitahara/quaternion-algebra @kkitahara/real-algebra

Examples

import { ExactRealAlgebra as RealAlgebra } from '@kkitahara/real-algebra'
import { QuaternionAlgebra } from '@kkitahara/quaternion-algebra'
let r = new RealAlgebra()
let h = new QuaternionAlgebra(r)
let q1, q2, q3

Generate a new quaternion

q1 = h.$(1, 2, 3, 4)
q1.toString() // '1 + i(2) + j(3) + k(4)'

q1 = h.$(0, 0, 0, r.$(1, 2, 5))
q1.toString() // 'k((1 / 2)sqrt(5))'

Real and imaginary parts

q1 = h.$(1, 2, 3, 4)
q1.re.toString() // '1'
q1.im instanceof Array // true
q1.im[0].toString() // '2'
q1.im[1].toString() // '3'
q1.im[2].toString() // '4'

Copy (create a new object)

q1 = h.$(1, 2, 3, 4)
q2 = h.copy(q1)
q2.toString() // '1 + i(2) + j(3) + k(4)'

Equality

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, -2, 3, 4)
h.eq(q1, q2) // false

q2 = h.$(1, 2, 3, 4)
h.eq(q1, q2) // true

Inequality

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, -2, 3, 4)
h.ne(q1, q2) // true

q2 = h.$(1, 2, 3, 4)
h.ne(q1, q2) // false

isZero

h.isZero(h.$(0, 0, 0, 0)) // true
h.isZero(h.$(1, 0, 0, 0)) // false
h.isZero(h.$(0, 1, 0, 0)) // false
h.isZero(h.$(0, 0, 1, 0)) // false
h.isZero(h.$(0, 0, 0, 1)) // false

isInteger

h.isInteger(h.$(1, 2, 3, 4)) // true
h.isInteger(h.$(1, r.$(2, 3), 3, 4)) // false
h.isInteger(h.$(1, r.$(4, 2), 3, 4)) // true

Addition

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, 1, 2, 1)
// new object is generated
q3 = h.add(q1, q2)
q3.toString() // '2 + i(3) + j(5) + k(5)'

In-place addition

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, 1, 2, 1)
// new object is not generated
q1 = h.iadd(q1, q2)
q1.toString() // '2 + i(3) + j(5) + k(5)'

Subtraction

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, 1, 2, 1)
// new object is generated
q3 = h.sub(q1, q2)
q3.toString() // 'i(1) + j(1) + k(3)'

In-place subtraction

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, 1, 2, 1)
// new object is not generated
q1 = h.isub(q1, q2)
q1.toString() // 'i(1) + j(1) + k(3)'

Maltiplication

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, -2, -3, -4)
// new object is generated
q3 = h.mul(q1, q2)
q3.toString() // '30'

// some fundametal products
h.mul(h.$(1, 0, 0, 0), h.$(0, 1, 0, 0)).toString() // 'i(1)'
h.mul(h.$(0, 1, 0, 0), h.$(1, 0, 0, 0)).toString() // 'i(1)'
h.mul(h.$(1, 0, 0, 0), h.$(0, 0, 1, 0)).toString() // 'j(1)'
h.mul(h.$(0, 0, 1, 0), h.$(1, 0, 0, 0)).toString() // 'j(1)'
h.mul(h.$(1, 0, 0, 0), h.$(0, 0, 0, 1)).toString() // 'k(1)'
h.mul(h.$(0, 0, 0, 1), h.$(1, 0, 0, 0)).toString() // 'k(1)'
h.mul(h.$(1, 0, 0, 0), h.$(1, 0, 0, 0)).toString() // '1'
h.mul(h.$(0, 1, 0, 0), h.$(0, 1, 0, 0)).toString() // '-1'
h.mul(h.$(0, 0, 1, 0), h.$(0, 0, 1, 0)).toString() // '-1'
h.mul(h.$(0, 0, 0, 1), h.$(0, 0, 0, 1)).toString() // '-1'
h.mul(h.$(0, 1, 0, 0), h.$(0, 0, 1, 0)).toString() // 'k(1)'
h.mul(h.$(0, 0, 1, 0), h.$(0, 1, 0, 0)).toString() // 'k(-1)'
h.mul(h.$(0, 0, 1, 0), h.$(0, 0, 0, 1)).toString() // 'i(1)'
h.mul(h.$(0, 0, 0, 1), h.$(0, 0, 1, 0)).toString() // 'i(-1)'
h.mul(h.$(0, 0, 0, 1), h.$(0, 1, 0, 0)).toString() // 'j(1)'
h.mul(h.$(0, 1, 0, 0), h.$(0, 0, 0, 1)).toString() // 'j(-1)'

In-place multiplication

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, -2, -3, -4)
// new object is not generated
q1 = h.imul(q1, q2)
q1.toString() // '30'

Division

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, 2, 3, 4)
// new object is generated
q3 = h.div(q1, q2)
q3.toString() // '1'

In-place division

q1 = h.$(1, 2, 3, 4)
q2 = h.$(1, 2, 3, 4)
// new object is not generated
q1 = h.idiv(q1, q2)
q1.toString() // '1'

Multiplication by -1

q1 = h.$(1, 2, 3, 4)
// new object is generated
q2 = h.neg(q1)
q2.toString() // '-1 + i(-2) + j(-3) + k(-4)'

In-place multiplication by -1

q1 = h.$(1, 2, 3, 4)
// new object is not generated
q1 = h.ineg(q1)
q1.toString() // '-1 + i(-2) + j(-3) + k(-4)'

Conjugate

q1 = h.$(1, 2, 3, 4)
// new object is generated
q2 = h.cjg(q1)
q2.toString() // '1 + i(-2) + j(-3) + k(-4)'

In-place evaluation of the conjugate

q1 = h.$(1, 2, 3, 4)
// new object is not generated
q1 = h.icjg(q1)
q1.toString() // '1 + i(-2) + j(-3) + k(-4)'

Square of the absolute value

q1 = h.$(1, 2, 3, 4)
let a = h.abs2(q1)
a.toString() // '30'
// return value is not a quaternion (but a real number)
a.re // undefined
a.im // undefined

JSON (stringify and parse)

q1 = h.$(1, 2, 3, 4)
let str = JSON.stringify(q1)
q2 = JSON.parse(str, h.reviver)
h.eq(q1, q2) // true

ESDoc documents

For more examples, see ESDoc documents:

cd node_modules/@kkitahara/quaternion-algebra
npm install --only=dev
npm run doc

and open doc/index.html in your browser.

LICENSE

© 2019 Koichi Kitahara
Apache 2.0