
Security News
Deno 2.2 Improves Dependency Management and Expands Node.js Compatibility
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
@basementuniverse/vec
Advanced tools
A small vector and matrix library
Node:
const { vec, mat } = require('@basementuniverse/vec');
Browser:
<script src="vec.js"></script>
Typescript:
import { vec, mat } from '@basementuniverse/vec';
vec
Create a new vector
mat
Create a new matrix
Object
A 2d vector
number
A function to call on each component of a vector
Object
A matrix
number
A function to call on each entry of a matrix
vec
Create a new vector
Kind: global function
Returns: vec
- A new vector
Param | Type | Description |
---|---|---|
[x] | number | vec | The x component of the vector, or a vector to copy |
[y] | number | The y component of the vector |
Example (Various ways to initialise a vector)
let a = vec(3, 2); // (3, 2)
let b = vec(4); // (4, 4)
let c = vec(a); // (3, 2)
let d = vec(); // (0, 0)
vec
Array.<number>
vec
vec
vec
vec
vec
number
number
vec
number
vec
boolean
number
vec
vec
string
Array.<number>
Get the components of a vector as an array
Kind: static method of vec
Returns: Array.<number>
- The vector components as an array
Param | Type | Description |
---|---|---|
a | vec | The vector to get components from |
vec
Return a unit vector (1, 0)
Kind: static method of vec
Returns: vec
- A unit vector (1, 0)
vec
Return a unit vector (0, 1)
Kind: static method of vec
Returns: vec
- A unit vector (0, 1)
vec
Add vectors
Kind: static method of vec
Returns: vec
- a + b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
vec
Scale a vector
Kind: static method of vec
Returns: vec
- a * b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | number | Scalar b |
vec
Subtract vectors
Kind: static method of vec
Returns: vec
- a - b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
number
Get the length of a vector
Kind: static method of vec
Returns: number
- |a|
Param | Type | Description |
---|---|---|
a | vec | Vector a |
number
Get the length of a vector using taxicab geometry
Kind: static method of vec
Returns: number
- |a|
Param | Type | Description |
---|---|---|
a | vec | Vector a |
vec
Normalise a vector
Kind: static method of vec
Returns: vec
- ^a
Param | Type | Description |
---|---|---|
a | vec | The vector to normalise |
number
Get a dot product of vectors
Kind: static method of vec
Returns: number
- a ∙ b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
vec
Rotate a vector by r radians
Kind: static method of vec
Returns: vec
- A rotated vector
Param | Type | Description |
---|---|---|
a | vec | The vector to rotate |
r | number | The angle to rotate by, measured in radians |
boolean
Check if two vectors are equal
Kind: static method of vec
Returns: boolean
- True if vectors a and b are equal, false otherwise
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
number
Get the angle of a vector
Kind: static method of vec
Returns: number
- The angle of vector a in radians
Param | Type | Description |
---|---|---|
a | vec | Vector a |
vec
Copy a vector
Kind: static method of vec
Returns: vec
- A copy of vector a
Param | Type | Description |
---|---|---|
a | vec | The vector to copy |
vec
Call a function on each component of a vector and build a new vector from the results
Kind: static method of vec
Returns: vec
- Vector a mapped through f
Param | Type | Description |
---|---|---|
a | vec | Vector a |
f | vectorMapCallback | The function to call on each component of the vector |
string
Convert a vector into a string
Kind: static method of vec
Returns: string
- A string representation of the vector
Param | Type | Default | Description |
---|---|---|---|
a | vec | The vector to convert | |
[s] | string | "', '" | The separator string |
mat
Create a new matrix
Kind: global function
Returns: mat
- A new matrix
Param | Type | Default | Description |
---|---|---|---|
[m] | number | 4 | The number of rows |
[n] | number | 4 | The number of columns |
[entries] | Array.<number> | [] | Matrix values in reading order |
mat
mat
number
Array.<number>
Array.<number>
mat
mat
mat
| boolean
mat
mat
mat
| boolean
number
| boolean
mat
| boolean
mat
mat
| boolean
boolean
mat
mat
string
mat
Get an identity matrix of size n
Kind: static method of mat
Returns: mat
- An identity matrix
Param | Type | Description |
---|---|---|
n | number | The size of the matrix |
number
Get an entry from a matrix
Kind: static method of mat
Returns: number
- The value at position (i, j) in matrix a
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
i | number | The row offset |
j | number | The column offset |
Set an entry of a matrix
Kind: static method of mat
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
i | number | The row offset |
j | number | The column offset |
v | number | The value to set in matrix a |
Array.<number>
Get a row from a matrix as an array
Kind: static method of mat
Returns: Array.<number>
- Row m from matrix a
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
m | number | The row offset |
Array.<number>
Get a column from a matrix as an array
Kind: static method of mat
Returns: Array.<number>
- Column n from matrix a
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
n | number | The column offset |
mat
Add matrices
Kind: static method of mat
Returns: mat
- a + b
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
Subtract matrices
Kind: static method of mat
Returns: mat
- a - b
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
| boolean
Multiply matrices
Kind: static method of mat
Returns: mat
| boolean
- ab or false if the matrices cannot be multiplied
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
Scale a matrix
Kind: static method of mat
Returns: mat
- a * b
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | number | Scalar b |
mat
Transpose a matrix
Kind: static method of mat
Returns: mat
- A transposed matrix
Param | Type | Description |
---|---|---|
a | mat | The matrix to transpose |
mat
| boolean
Get the minor of a matrix
Kind: static method of mat
Returns: mat
| boolean
- The (i, j) minor of matrix a or false if the matrix is not square
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
i | number | The row offset |
j | number | The column offset |
number
| boolean
Get the determinant of a matrix
Kind: static method of mat
Returns: number
| boolean
- |a| or false if the matrix is not square
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
mat
| boolean
Normalise a matrix
Kind: static method of mat
Returns: mat
| boolean
- ^a or false if the matrix is not square
Param | Type | Description |
---|---|---|
a | mat | The matrix to normalise |
mat
Get the adjugate of a matrix
Kind: static method of mat
Returns: mat
- The adjugate of a
Param | Type | Description |
---|---|---|
a | mat | The matrix from which to get the adjugate |
mat
| boolean
Get the inverse of a matrix
Kind: static method of mat
Returns: mat
| boolean
- a^-1 or false if the matrix has no inverse
Param | Type | Description |
---|---|---|
a | mat | The matrix to invert |
boolean
Check if two matrices are equal
Kind: static method of mat
Returns: boolean
- True if matrices a and b are identical, false otherwise
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
Copy a matrix
Kind: static method of mat
Returns: mat
- A copy of matrix a
Param | Type | Description |
---|---|---|
a | mat | The matrix to copy |
mat
Call a function on each entry of a matrix and build a new matrix from the results
Kind: static method of mat
Returns: mat
- Matrix a mapped through f
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
f | matrixMapCallback | The function to call on each entry of the matrix |
string
Convert a matrix into a string
Kind: static method of mat
Returns: string
- A string representation of the matrix
Param | Type | Default | Description |
---|---|---|---|
a | mat | The matrix to convert | |
[ms] | string | "', '" | The separator string for columns |
[ns] | string | "'\n'" | The separator string for rows |
Object
A 2d vector
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
x | number | The x component of the vector |
y | number | The y component of the vector |
Object
Array.<number>
vec
vec
vec
vec
vec
number
number
vec
number
vec
boolean
number
vec
vec
string
Array.<number>
Get the components of a vector as an array
Kind: static method of vec
Returns: Array.<number>
- The vector components as an array
Param | Type | Description |
---|---|---|
a | vec | The vector to get components from |
vec
Return a unit vector (1, 0)
Kind: static method of vec
Returns: vec
- A unit vector (1, 0)
vec
Return a unit vector (0, 1)
Kind: static method of vec
Returns: vec
- A unit vector (0, 1)
vec
Add vectors
Kind: static method of vec
Returns: vec
- a + b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
vec
Scale a vector
Kind: static method of vec
Returns: vec
- a * b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | number | Scalar b |
vec
Subtract vectors
Kind: static method of vec
Returns: vec
- a - b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
number
Get the length of a vector
Kind: static method of vec
Returns: number
- |a|
Param | Type | Description |
---|---|---|
a | vec | Vector a |
number
Get the length of a vector using taxicab geometry
Kind: static method of vec
Returns: number
- |a|
Param | Type | Description |
---|---|---|
a | vec | Vector a |
vec
Normalise a vector
Kind: static method of vec
Returns: vec
- ^a
Param | Type | Description |
---|---|---|
a | vec | The vector to normalise |
number
Get a dot product of vectors
Kind: static method of vec
Returns: number
- a ∙ b
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
vec
Rotate a vector by r radians
Kind: static method of vec
Returns: vec
- A rotated vector
Param | Type | Description |
---|---|---|
a | vec | The vector to rotate |
r | number | The angle to rotate by, measured in radians |
boolean
Check if two vectors are equal
Kind: static method of vec
Returns: boolean
- True if vectors a and b are equal, false otherwise
Param | Type | Description |
---|---|---|
a | vec | Vector a |
b | vec | Vector b |
number
Get the angle of a vector
Kind: static method of vec
Returns: number
- The angle of vector a in radians
Param | Type | Description |
---|---|---|
a | vec | Vector a |
vec
Copy a vector
Kind: static method of vec
Returns: vec
- A copy of vector a
Param | Type | Description |
---|---|---|
a | vec | The vector to copy |
vec
Call a function on each component of a vector and build a new vector from the results
Kind: static method of vec
Returns: vec
- Vector a mapped through f
Param | Type | Description |
---|---|---|
a | vec | Vector a |
f | vectorMapCallback | The function to call on each component of the vector |
string
Convert a vector into a string
Kind: static method of vec
Returns: string
- A string representation of the vector
Param | Type | Default | Description |
---|---|---|---|
a | vec | The vector to convert | |
[s] | string | "', '" | The separator string |
number
A function to call on each component of a vector
Kind: global typedef
Returns: number
- The mapped component
Param | Type | Description |
---|---|---|
value | number | The component value |
label | 'x' | 'y' | The component label (x or y) |
Object
A matrix
Kind: global typedef
Properties
Name | Type | Description |
---|---|---|
m | number | The number of rows in the matrix |
n | number | The number of columns in the matrix |
entries | Array.<number> | The matrix values |
Object
mat
number
Array.<number>
Array.<number>
mat
mat
mat
| boolean
mat
mat
mat
| boolean
number
| boolean
mat
| boolean
mat
mat
| boolean
boolean
mat
mat
string
mat
Get an identity matrix of size n
Kind: static method of mat
Returns: mat
- An identity matrix
Param | Type | Description |
---|---|---|
n | number | The size of the matrix |
number
Get an entry from a matrix
Kind: static method of mat
Returns: number
- The value at position (i, j) in matrix a
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
i | number | The row offset |
j | number | The column offset |
Set an entry of a matrix
Kind: static method of mat
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
i | number | The row offset |
j | number | The column offset |
v | number | The value to set in matrix a |
Array.<number>
Get a row from a matrix as an array
Kind: static method of mat
Returns: Array.<number>
- Row m from matrix a
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
m | number | The row offset |
Array.<number>
Get a column from a matrix as an array
Kind: static method of mat
Returns: Array.<number>
- Column n from matrix a
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
n | number | The column offset |
mat
Add matrices
Kind: static method of mat
Returns: mat
- a + b
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
Subtract matrices
Kind: static method of mat
Returns: mat
- a - b
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
| boolean
Multiply matrices
Kind: static method of mat
Returns: mat
| boolean
- ab or false if the matrices cannot be multiplied
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
Scale a matrix
Kind: static method of mat
Returns: mat
- a * b
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | number | Scalar b |
mat
Transpose a matrix
Kind: static method of mat
Returns: mat
- A transposed matrix
Param | Type | Description |
---|---|---|
a | mat | The matrix to transpose |
mat
| boolean
Get the minor of a matrix
Kind: static method of mat
Returns: mat
| boolean
- The (i, j) minor of matrix a or false if the matrix is not square
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
i | number | The row offset |
j | number | The column offset |
number
| boolean
Get the determinant of a matrix
Kind: static method of mat
Returns: number
| boolean
- |a| or false if the matrix is not square
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
mat
| boolean
Normalise a matrix
Kind: static method of mat
Returns: mat
| boolean
- ^a or false if the matrix is not square
Param | Type | Description |
---|---|---|
a | mat | The matrix to normalise |
mat
Get the adjugate of a matrix
Kind: static method of mat
Returns: mat
- The adjugate of a
Param | Type | Description |
---|---|---|
a | mat | The matrix from which to get the adjugate |
mat
| boolean
Get the inverse of a matrix
Kind: static method of mat
Returns: mat
| boolean
- a^-1 or false if the matrix has no inverse
Param | Type | Description |
---|---|---|
a | mat | The matrix to invert |
boolean
Check if two matrices are equal
Kind: static method of mat
Returns: boolean
- True if matrices a and b are identical, false otherwise
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
b | mat | Matrix b |
mat
Copy a matrix
Kind: static method of mat
Returns: mat
- A copy of matrix a
Param | Type | Description |
---|---|---|
a | mat | The matrix to copy |
mat
Call a function on each entry of a matrix and build a new matrix from the results
Kind: static method of mat
Returns: mat
- Matrix a mapped through f
Param | Type | Description |
---|---|---|
a | mat | Matrix a |
f | matrixMapCallback | The function to call on each entry of the matrix |
string
Convert a matrix into a string
Kind: static method of mat
Returns: string
- A string representation of the matrix
Param | Type | Default | Description |
---|---|---|---|
a | mat | The matrix to convert | |
[ms] | string | "', '" | The separator string for columns |
[ns] | string | "'\n'" | The separator string for rows |
number
A function to call on each entry of a matrix
Kind: global typedef
Returns: number
- The mapped entry
Param | Type | Description |
---|---|---|
value | number | The entry value |
index | number | The entry index |
entries | Array.<number> | The array of matrix entries |
FAQs
A small vector and matrix library
The npm package @basementuniverse/vec receives a total of 6 weekly downloads. As such, @basementuniverse/vec popularity was classified as not popular.
We found that @basementuniverse/vec demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Deno 2.2 enhances Node.js compatibility, improves dependency management, adds OpenTelemetry support, and expands linting and task automation for developers.
Security News
React's CRA deprecation announcement sparked community criticism over framework recommendations, leading to quick updates acknowledging build tools like Vite as valid alternatives.
Security News
Ransomware payment rates hit an all-time low in 2024 as law enforcement crackdowns, stronger defenses, and shifting policies make attacks riskier and less profitable.