0.5.0 • Published 11 months ago

@ishikawa-masashi/math v0.5.0

Weekly downloads
-
License
-
Repository
github
Last release
11 months ago

@ishikawa-masashi/math: A Typescript vector and matrix math library

@ishikawa-masashi/math is a collection of vector, matrix and quaternion classes written in Typescript with no dependencies.

How to install it

Using npm or yarn

npm install --save ts-matrix
yarn add ts-matrix

Or add the unpkg cdn link to your html

<script src="https://unpkg.com/ts-matrix">

The library is built as an ECMAScript module (.mjs file), but it also exports a UMD version if needed.

Usage

Import the module, from Typescript or ES6 javascript.

import { Vector3, Matrix } from '@ishikawa-masashi/math';

Then use the methods as you want :)

const v1 = new Vector([1, 2]);
const v2 = new Vector([3, 1]);
v1.add(v2);
// ==> [4, 3]

Most operation return a new Vector instance.

If you use typescript, the declarations files are available with self documentation.


Documentation

Vectors

Instance methods

methoddescription
at(row: number)Get the value of a cell
rows()Returns Vector's size
values()Returns Vector values as an array
reset()Sets all matrix values to 0
addAValue()Add a new 0 to the Vector
addARow()Add a new empty row to the Matrix
equals(vector: Vector)Checks equality between two vectors
negate()Negates the Vector (change all cells arithmetic sign). Returns a new instance.
length()Returns the vectors length
squaredLength()Returns the vectors squared length
add(vector: Vector)Adds all given values to the current Vector instance. Both vectors must have the same dimension. Mutates current instance.
substract(vector: Vector)Substracts all given values to the current Vector instance. Both vectors must have the same dimension. Mutates current instance.
multiply(vector: Vector)Multiplies all given values to the current Vector instance. Both vectors must have the same dimension. Mutates current instance.
divide(vector: Vector)Divides all given values to the current Vector instance. Both vectors must have the same dimension. Mutates current instance.
scale(scale: number)Multiply all vector values by the given scale. Mutates current instance.
normalize(scale: number)Computes the normalized Vector. Mutates current instance.
dot(vector: Vector)Computes the dot product between two Vectors.
cross(vector: Vector)Computes the cross product between two Vectors. Returns new instance
mix(vector: Vector, time: number)Computes the mix product between two Vectors. Returns new instance

Static methods

methoddescription
get360angle(VectorA: Vector, VectorB: Vector)Compute the angle between two Vectors. Both vectors must be of dimension 3 exactly. The returned angle is signed, thus -180º < angle < 180º

Matrices

Instance methods

methoddescription
at(row: number, col: number)Get the value of a cell
rows()Returns matrix rows as an array
cols()Returns matrix columns as an array
values()Returns matrix values as a bi-dimentional array
reset()Sets all matrix values to 0
addAColumn()Add a new empty column to the Matrix
addARow()Add a new empty row to the Matrix
equals(matrix: Matrix)Checks equality between two matrices
setAsIdentity()Fills a squared matrix with the identity values (diagnonal 1)
multiply(matrix: Matrix)Multiply two matrices. Returns a new instance.
determinantCompute the determinant of the matrix.
getCofactor(row: number, col: number)Compute the cofactor of the matrix. Returns a new instance.
transpose()Transpose the matrix. Returns a new instance.
inverse()Inverse the matrix. Returns a new instance.

Static methods

methoddescription
identity(dimension: number)Returns a new squared identity Matrix

Contributing

Any contribution is welcome, whether it is an issue, PullRequest, or just a comment!

Made with love by Florent Catiau-Tristant (@kapcash)

0.4.9

11 months ago

0.4.8

11 months ago

0.5.0

11 months ago

0.4.7

1 year ago

0.4.6

1 year ago

0.3.9

1 year ago

0.3.10

1 year ago

0.4.5

1 year ago

0.3.6

1 year ago

0.4.4

1 year ago

0.3.5

1 year ago

0.3.8

1 year ago

0.3.7

1 year ago

0.4.1

1 year ago

0.4.0

1 year ago

0.4.3

1 year ago

0.3.4

1 year ago

0.4.2

1 year ago

0.3.3

1 year ago

0.1.0

2 years ago

0.3.0

2 years ago

0.1.2

2 years ago

0.2.0

2 years ago

0.1.1

2 years ago

0.2.7

2 years ago

0.1.8

2 years ago

0.0.9

2 years ago

0.2.6

2 years ago

0.0.8

2 years ago

0.2.9

2 years ago

0.2.8

2 years ago

0.1.9

2 years ago

0.3.2

2 years ago

0.2.3

2 years ago

0.1.4

2 years ago

0.3.1

2 years ago

0.2.2

2 years ago

0.1.3

2 years ago

0.2.5

2 years ago

0.1.6

2 years ago

0.0.7

2 years ago

0.2.4

2 years ago

0.1.5

2 years ago

0.0.6

2 years ago

0.0.5

2 years ago

0.0.4

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago