Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/chkt/xyzw

Vector, Matrix, Quaternion, Euler Angles, SLERPs, Projections, Transforms
https://github.com/chkt/xyzw

complex gauss-jordan javascript lerp math matrix slerp typescript vector

Last synced: 3 months ago
JSON representation

Vector, Matrix, Quaternion, Euler Angles, SLERPs, Projections, Transforms

Awesome Lists containing this project

README

        

[![Tests](https://github.com/chkt/xyzw/workflows/tests/badge.svg)](https://github.com/chkt/onceupon/actions)
[![Version](https://img.shields.io/npm/v/xyzw)](https://www.npmjs.com/package/@chkt/onceupon)
![Node](https://img.shields.io/node/v/xyzw)
![Dependencies](https://img.shields.io/librariesio/release/npm/xyzw)
![Licence](https://img.shields.io/npm/l/xyzw)
![Language](https://img.shields.io/github/languages/top/chkt/xyzw)
![Size](https://img.shields.io/bundlephobia/min/xyzw)

# xyzw

A functional, performance oriented, comprehensive and dependencyless typescript vector algebra library.

## Install

```sh
yarn install xyzw
```

## Use

All included vector algebra objects are implemented as plain object literals.

All operations yielding a non-primitive value have a capitalized *non-mutating* variant returning a new instance containing the result.

```ts
const vec2 = vector2.Rotation(0.5 * Math.PI); // { x : 0.0, y : 1.0 }
const vec3 = vector3.AxisX(); // { x : 1.0, y : 0.0, z : 0.0 }
const vec4 = vector4.Create(); // { x : 0.0, y : 0.0, z : 0.0, w : 1.0 }
const mat2 = matrix2.Rotation(0.5 * Math.PI); // { r00 : 0.0, r01 : 1.0, r10 : -1.0, r11 : 0.0 }
const mat3 = matrix3.RotationZ(0.5 * Math.PI); // { r00 : 0.0, r01 : 1.0, r02 : 0.0, … }
const mat4 = matrix4.Identity(); // …

const v = vector2.Copy(vec2);

assert.notStrictEqual(vec2, v);
```

Likewise all operations yielding a non-primitive value have a same-name non-capitalized *mutating* variant taking an instance of the result type as their first argument.
The first argument is also the return value of the operation.

```ts
vector2.rotation(vec2, 1.0 * Math.PI); // { x : -1.0, y : 0.0 }
vector3.axisX(vec3, 2.0); // { x : 2.0, y : 0.0, z : 0.0 }
vector4.assign(vec4, 1.0); // { x : 1.0, y : 0.0, z : 0.0, w : 1.0 }
matrix2.rotation(mat2, 1.0 * Math.PI); // { r00 : -1.0, r01 : 0.0, r10 : 0.0, r11 : -1.0 }
matrix3.rotationZ(mat3, 1.0 * Math.PI); // { r00 : -1.0, r01 : 1.0, r02 : 0.0, … }
matrix4.identity(mat4); // …

const w = vector2.copy(v, vec2);

assert.strictEqual(w, v);
assert.notStrictEqual(vec2, v);
```

The fastest operations additionally have an assignment form roughly equivalent to primitive type assignment operations (`a += b`).

```ts
const u = vector2.addAssign(v, w); // v += w

assert.strictEqual(u, v);
assert.notStrictEqual(w, v);
```
# Modules
## complex
[`./source/complex.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/complex.ts#L1)
### Functions
```ts
function Conjugate(z:Vector2) : Vector2; // z̅
function Divide(z:Vector2, w:Vector2) : Vector2; // zw̅ / ww̅, z = a + bi, w = c = di
function Inverse(z:Vector2) : Vector2; // z⁻¹
function Multiply(z:Vector2, w:Vector2) : Vector2; // zw, z = a + bi, w = c + di
function Power(z:Vector2, n:number) : Vector2[]; // zⁿ₍ₖ₎
function argument(z:Vector2) : number; // φ
function conjugate(r:R, v:Vector2) : R; // r⃗ = z̅
function divide(r:R, z:Vector2, w:Vector2) : R; // r⃗ = zw̅ / ww̅, z = a + bi, w = c = di
function inverse(r:R, z:Vector2) : R; // r⃗ = z⁻¹
function multiply(r:R, z:Vector2, w:Vector2) : R; // r⃗ = zw, z = a + bi, w = c + di
function power>(r:R, z:Vector2, n:number) : R; // r⃗₍ₖ₎ = zⁿ₍ₖ₎
```
## index
[`./source/index.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/index.ts#L1)
### References
```ts
export * as complex from "./complex";
export * as matrix2 from "./matrix2";
export * as matrix3 from "./matrix3";
export * as matrix4 from "./matrix4";
export * as matrix4Frustrum from "./matrix4Frustrum";
export * as matrix4Ortho from "./matrix4Ortho";
export * as vector2 from "./vector2";
export * as vector3 from "./vector3";
export * as vector4 from "./vector4";
```
## matrix2
[`./source/matrix2.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/matrix2.ts#L1)
### Interfaces
```ts
interface Matrix2 {
r00 : number;
r01 : number;
r10 : number;
r11 : number;
}
```
### Functions
```ts
function Add(a:Matrix2, b:Matrix2) : Matrix2; // A+B
function Concat(a:Matrix2, b:Matrix2) : Matrix2; // AB
function Copy(m:Matrix2) : Matrix2;
function Identity() : Matrix2; // Î
function Inverse(m:Matrix2) : Matrix2 | undefined; // M⁻¹
function Rotation(rad:number) : Matrix2; // R(θ)
function RotationVector2(v:Vector2) : Matrix2; // [ v⃗ v⃗⊥ ]
function Scale(v:Vector2) : Matrix2; // [ x̂v⃗₀ ŷv⃗₁ ]
function Shear(x:Vector2, y:Vector2) : Matrix2; // [ x⃗ y⃗ ]
// @deprecated alias of Copy()
function ShearMatrix3(m:Matrix2) : Matrix2; // [ m⁰ m¹ ]
function Subtract(a:Matrix2, b:Matrix2) : Matrix2; // A-B
function Transpose(m:Matrix2) : Matrix2; // Mᵀ
function add(r:R, a:Matrix2, b:Matrix2) : R; // Mᵣ = A+B
function addAssign(a:R, b:Matrix2) : R; // A = A+B
function concat(r:R, a:Matrix2, b:Matrix2) : R; // Mᵣ = AB
function copy(r:R, m:Matrix2) : R;
function determinant(m:Matrix2) : number; // |M|
function identity(r:R) : R; // Mᵣ = Î
function inverse(r:R, m:Matrix2) : R | undefined; // Mᵣ = M⁻¹
function rotation(r:R, rad:number) : R; // Mᵣ = R(θ)
function rotationVector2(r:R, v:Vector2) : R; // Mᵣ = [ v⃗ v⃗⊥ ]
function scale(r:R, v:Vector2) : R; // Mᵣ = [ x̂v⃗₀ ŷv⃗₁ ]
function shear(r:R, x:Vector2, y:Vector2) : R; // Mᵣ = [ x⃗ y⃗ ]
// @deprecated alias of copy()
function shearMatrix3(r:R, m:Matrix2) : R; // Mᵣ = [ m⁰ m¹ ]
function subtract(r:R, a:Matrix2, b:Matrix2) : R; // Mᵣ = A-B
function subtractAssign(a:R, b:Matrix2) : R; // A = A-B
function transpose(r:R, m:Matrix2) : R; // Mᵣ = Mᵀ
```
## matrix3
[`./source/matrix3.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/matrix3.ts#L1)
### Interfaces
```ts
interface Matrix3 extends Matrix2 {
r02 : number;
r12 : number;
r20 : number;
r21 : number;
r22 : number;
}
```
### Functions
```ts
function Add(a:Matrix3, b:Matrix3) : Matrix3; // A+B
function Concat(a:Matrix3, b:Matrix3) : Matrix3; // AB
function Concat2x3(a:Matrix3, b:Matrix3) : Matrix3; // AB₂ₓ₃
function ConcatMatrix2(a:Matrix3, b:Matrix2) : Matrix3; // AB₂ₓ₂
function ConcatScaleVector2(m:Matrix3, v:Vector2) : Matrix3; // M[ x̂v⃗₀ ŷv⃗₁ ẑ ]
function ConcatTranslation(m:Matrix3, v:Vector2) : Matrix3; // M[ x̂ ŷ v⃗ ]
function Copy(m:Matrix3) : Matrix3;
function EulerXYZ(v:Vector3) : Matrix3; // R(x̂, v⃗₀)R(ŷ, v⃗₁)R(ẑ, v⃗₂)
function EulerYXZ(v:Vector3) : Matrix3; // R(ŷ, v⃗₁)R(x̂, v⃗₀)R(ẑ, v⃗₂)
function EulerZXY(v:Vector3) : Matrix3; // R(ẑ, v⃗₂)R(x̂, v⃗₀)R(ŷ, v⃗₁)
function Identity() : Matrix3; // Î
function Inverse(m:Matrix3) : Matrix3 | undefined; // M⁻¹
function Quaternion(q:Vector4) : Matrix3; // R(q̂)
function RotationAxis(v:Vector3, rad:number) : Matrix3; // R(v⃗, θ)
function RotationVector3(x:Vector3, y:Vector3) : Matrix3; // [ x⃗ y⃗ x⃗×y⃗ ]
function RotationX(rad:number) : Matrix3; // R(x̂, θ)
function RotationY(rad:number) : Matrix3; // R(ŷ, θ)
function RotationZ(rad:number) : Matrix3; // R(ẑ, θ)
function RotationZMatrix2(m:Matrix2) : Matrix3; // [ m⁰ m¹ ẑ ]
function RotationZVector2(x:Vector2) : Matrix3; // [ x⃗ x⃗⊥ ẑ ]
function Scale(v:Vector3) : Matrix3; // [ x̂v⃗₀ ŷv⃗₁ ẑv⃗₂ ]
function ScaleVector2(v:Vector2) : Matrix3; // [ x̂v⃗₀ ŷv⃗₁ ẑ ]
function Shear(x:Vector3, y:Vector3, z:Vector3) : Matrix3; // [ x⃗ y⃗ z⃗ ]
// @deprecated alias of Copy()
function ShearMatrix4(m:Matrix3) : Matrix3; // [ m⁰ m¹ m² ]
function ShearTranslation(x:Vector2, y:Vector2, t:Vector2) : Matrix3; // [ x⃗ y⃗ ẑ+t⃗ ]
function ShearVector2(x:Vector2, y:Vector2) : Matrix3; // [ x⃗ y⃗ ẑ ]
function Subtract(a:Matrix3, b:Matrix3) : Matrix3; // A-B
function Translation(v:Vector2) : Matrix3; // [ x̂ ŷ ẑ+v⃗ ]
function Transpose(m:Matrix3) : Matrix3; // Mᵀ
function add(r:R, a:Matrix3, b:Matrix3) : R; // Mᵣ = A+B
function addAssign(a:R, b:Matrix3) : R; // A = A+B
function concat(r:R, a:Matrix3, b:Matrix3) : R; // Mᵣ = AB
function concat2x3(r:R, a:Matrix3, b:Matrix3) : R; // Mᵣ = AB₂ₓ₃
function concatMatrix2(r:R, a:Matrix3, b:Matrix2) : R; // Mᵣ = AB₂ₓ₂
function concatScaleVector2(r:R, m:Matrix3, v:Vector2) : R; // Mᵣ = M[ x̂v⃗₀ ŷv⃗₁ ẑ ]
function concatTranslation(r:R, m:Matrix3, v:Vector2) : R; // Mᵣ = M[ x̂ ŷ v⃗ ]
function copy(r:R, m:Matrix3) : R;
function determinant(m:Matrix3) : number; // |M|
function equals(a:Matrix3, b:Matrix3, e:number = epsilon) : boolean;
function eulerXYZ(r:R, v:Vector3) : R; // Mᵣ = R(x̂, v⃗₀)R(ŷ, v⃗₁)R(ẑ, v⃗₂)
function eulerYXZ(r:R, v:Vector3) : R; // Mᵣ = R(ŷ, v⃗₁)R(x̂, v⃗₀)R(ẑ, v⃗₂)
function eulerZXY(r:R, v:Vector3) : R; // Mᵣ = R(ẑ, v⃗₂)R(x̂, v⃗₀)R(ŷ, v⃗₁)
function identity(r:R) : R; // Mᵣ = Î
function inverse(r:R, m:Matrix3) : R | undefined; // Mᵣ = M⁻¹
function quaternion(r:R, q:Vector4) : R; // Mᵣ = R(q̂)
function rotationAxis(r:R, v:Vector3, rad:number) : R; // Mᵣ = R(v⃗, θ)
function rotationVector3(r:R, x:Vector3, y:Vector3) : R; // Mᵣ = [ x⃗ y⃗ x⃗×y⃗ ]
function rotationX(r:R, rad:number) : R; // Mᵣ = R(x̂, θ)
function rotationY(r:R, rad:number) : R; // Mᵣ = R(ŷ, θ)
function rotationZ(r:R, rad:number) : R; // Mᵣ = R(ẑ, θ)
function rotationZMatrix2(r:R, m:Matrix2) : R; // Mᵣ = [ m⁰ m¹ ẑ ]
function rotationZVector2(r:R, x:Vector2) : R; // Mᵣ = [ x⃗ x⃗⊥ ẑ ]
function scale(r:R, v:Vector3) : R; // Mᵣ = [ x̂v⃗₀ ŷv⃗₁ ẑv⃗₂ ]
function scaleVector2(r:R, v:Vector2) : R; // Mᵣ = [ x̂v⃗₀ ŷv⃗₁ ẑ ]
function shear(r:R, x:Vector3, y:Vector3, z:Vector3) : R; // Mᵣ = [ x⃗ y⃗ z⃗ ]
// @deprecated alias of copy()
function shearMatrix4(r:R, m:Matrix3) : R; // Mᵣ = [ m⁰ m¹ m² ]
function shearTranslation(r:R, x:Vector2, y:Vector2, t:Vector2) : R; // Mᵣ = [ x⃗ y⃗ ẑ+t⃗ ]
function shearVector2(r:R, x:Vector2, y:Vector2) : R; // Mᵣ = [ x⃗ y⃗ ẑ ]
function subtract(r:R, a:Matrix3, b:Matrix3) : R; // Mᵣ = A-B
function subtractAssign(a:R, b:Matrix3) : R; // A = A-B
function translation(r:R, v:Vector2) : R; // Mᵣ = [ x̂ ŷ ẑ+v⃗ ]
function transpose(r:R, m:Matrix3) : R; // Mᵣ = Mᵀ
```
## matrix4
[`./source/matrix4.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/matrix4.ts#L1)
### Interfaces
```ts
interface Matrix4 extends Matrix3 {
r03 : number;
r13 : number;
r23 : number;
r30 : number;
r31 : number;
r32 : number;
r33 : number;
}
```
### Functions
```ts
function Add(a:Matrix4, b:Matrix4) : Matrix4; // A+B
function ColumnF32(n:Float32Array) : Matrix4;
function ColumnF64(n:Float64Array) : Matrix4;
function Concat(a:Matrix4, b:Matrix4) : Matrix4; // AB
function Concat3x4(a:Matrix4, b:Matrix4) : Matrix4; // AB₃ₓ₄
function ConcatMatrix3(a:Matrix4, b:Matrix3) : Matrix4; // AB₃ₓ₃
function ConcatScale(m:Matrix4, v:Vector3) : Matrix4; // M[ x̂v⃗₀ ŷv⃗₁ ẑv⃗₂ ŵ ]
function ConcatTranslation(m:Matrix4, v:Vector3) : Matrix4; // M[ x̂ ŷ ẑ ŵ+v⃗ ]
function Copy(m:Matrix4) : Matrix4;
function Identity() : Matrix4; // Î
function Inverse(m:Matrix4) : Matrix4 | undefined; // M⁻¹ (using the determinant)
function Inverse3x4(m:Matrix4) : Matrix4 | undefined; // [ m⁰ m¹ m² ŵ+m³ ]⁻¹
function InverseGauss(m:Matrix4) : Matrix4 | undefined; // M⁻¹ (using Gauss-Jordon elimination)
function ShearMatrix3(m:Matrix3) : Matrix4; // [ m⁰ m¹ m² ŵ ]
// @deprecated alias of ShearTranslationAxes()
function ShearTranslation(x:Vector3, y:Vector3, z:Vector3, t:Vector3) : Matrix4; // [ x⃗ y⃗ z⃗ ŵ+t⃗ ]
function ShearTranslationAxes(x:Vector3, y:Vector3, z:Vector3, t:Vector3) : Matrix4; // [ x⃗ y⃗ z⃗ ŵ+t⃗ ]
function ShearTranslationMatrix3(m:Matrix3, t:Vector3) : Matrix4; // [ m⁰ m¹ m² ŵ+t⃗ ]
function Subtract(a:Matrix4, b:Matrix4) : Matrix4; // A-B
function Translation(v:Vector3) : Matrix4; // [ x̂ ŷ ẑ ŵ+v⃗ ]
function Transpose(m:Matrix4) : Matrix4; // Mᵀ
function add(r:R, a:Matrix4, b:Matrix4) : R; // Mᵣ = A+B
function addAssign(a:R, b:Matrix4) : R; // A = A+B
function assignColumnF32(r:Float32Array, m:Matrix4) : Float32Array;
function assignColumnF64(r:Float64Array, m:Matrix4) : Float64Array;
function columnF32(r:R, n:Float32Array) : R;
function columnF64(r:R, n:Float64Array) : R;
function concat(r:R, a:Matrix4, b:Matrix4) : R; // Mᵣ = AB
function concat3x4(r:R, a:Matrix4, b:Matrix4) : R; // Mᵣ = AB₃ₓ₄
function concatMatrix3(r:R, a:Matrix4, b:Matrix3) : R; // Mᵣ = AB₃ₓ₃
function concatScale(r:R, m:Matrix4, v:Vector3) : R; // Mᵣ = M[ x̂v⃗₀ ŷv⃗₁ ẑv⃗₂ ŵ ]
function concatTranslation(r:R, m:Matrix4, v:Vector3) : R; // Mᵣ = M[ x̂ ŷ ẑ ŵ+v⃗ ]
function copy(r:R, m:Matrix4) : R;
function determinant(m:Matrix4) : number; // |M|
function equals(a:Matrix4, b:Matrix4, e:number = epsilon) : boolean;
function identity(r:R) : R; // Mᵣ = Î
function inverse(r:R, m:Matrix4) : R | undefined; // Mᵣ = M⁻¹ (using the determinant)
function inverse3x4(r:R, m:Matrix4) : R | undefined; // Mᵣ = [ m⁰ m¹ m² ŵ+m³ ]⁻¹
function inverseGauss(r:R, m:Matrix4) : R | undefined; // Mᵣ = M⁻¹ (using Gauss-Jordan elimination)
function shearMatrix3(r:R, m:Matrix3) : R; // Mᵣ = [ m⁰ m¹ m² ŵ ]
// @deprecated alias of shearTranslationAxes()
function shearTranslation(r:R, x:Vector3, y:Vector3, z:Vector3, t:Vector3) : R; // Mᵣ = [ x⃗ y⃗ z⃗ ŵ+t⃗ ]
function shearTranslationAxes(r:R, x:Vector3, y:Vector3, z:Vector3, t:Vector3) : R;
function shearTranslationMatrix3(r:R, m:Matrix3, t:Vector3) : R; // Mᵣ = [ m⁰ m¹ m² ŵ+t⃗ ]
function subtract(r:R, a:Matrix4, b:Matrix4) : R; // Mᵣ = A-B
function subtractAssign(a:R, b:Matrix4) : R; // A = A-B
function toColumnF32(m:Matrix4) : Float32Array;
function toColumnF64(m:Matrix4) : Float64Array;
function translation(r:R, v:Vector3) : R; // Mᵣ = [ x̂ ŷ ẑ ŵ+v⃗ ]
function transpose(r:R, m:Matrix4) : R; // Mᵣ = Mᵀ
```
## matrix4Frustrum
[`./source/matrix4Frustrum.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/matrix4Frustrum.ts#L1)
### Interfaces
```ts
interface PerspectiveLens {
readonly aspect : number;
readonly far : number;
readonly fov : number;
readonly near : number;
}
```
### Functions
```ts
function Frustrum(lens:PerspectiveLens) : Matrix4;
function frustrum(r:R, lens:PerspectiveLens) : R;
```
## matrix4Ortho
[`./source/matrix4Ortho.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/matrix4Ortho.ts#L1)
### Interfaces
```ts
interface OrthographicLens {
readonly aspect : number;
readonly extend : number;
readonly far : number;
readonly near : number;
}
```
### Functions
```ts
function Ortho(lens:OrthographicLens) : Matrix4;
function ortho(r:R, lens:OrthographicLens) : R;
```
## strings
[`./source/strings.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/strings.ts#L1)
### Interfaces
```ts
interface StringifyOptions extends StringifyOptionsCommon {
readonly clampMax : VectorRecord;
readonly clampMin : VectorRecord;
}
```
### Type Aliases
```ts
type stringify = (v:VectorRecord) => string;
```
### Variables
```ts
const PRECISION_SAFE:number;
const stringifyDefaultsCommon:StringifyOptionsCommon;
```
### Functions
```ts
function stringify(opts:StringifyOptions, v:VectorRecord) : string;
```
## vector2
[`./source/vector2.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/vector2.ts#L1)
### Interfaces
```ts
interface Vector2 {
x : number;
y : number;
}
```
### Functions
```ts
function Add(v:Vector2, w:Vector2) : Vector2; // v⃗+w⃗
function AxisX(s:number = 1.0) : Vector2; // sx̂
function AxisY(s:number = 1.0) : Vector2; // sŷ
function BarycentricUV(vx0:Vector2, vx1:Vector2, vx2:Vector2, u:number, v:number) : Vector2; // Return the point represented by barycentric coordinates (u, v) in ↻ triangle (vx0, vx1, vx2)
function Copy(v:Vector2) : Vector2;
function Create(x:number = 0.0, y:number = 0.0) : Vector2;
function Hadamard(v:Vector2, w:Vector2) : Vector2; // v⃗⊙w⃗
function HadamardInvert(v:Vector2) : Vector2; // 1⁄v⃗
function Lerp(v:Vector2, w:Vector2, t:number) : Vector2; // v⃗ + ( w⃗ - v⃗ ) * t
function Multiply2x3Matrix3(m:Matrix3, v:Vector2) : Vector2; // M₂ₓ₃v⃗
function MultiplyMatrix2(m:Matrix2, v:Vector2) : Vector2; // M₂ₓ₂v⃗
function MultiplyMatrix3(m:Matrix3, v:Vector2) : Vector2; // M₃ₓ₃v⃗
function MultiplyScalar(v:Vector2, n:number) : Vector2; // nv⃗
function Negate(v:Vector2) : Vector2; // -v⃗
function Normalize(v:Vector2) : Vector2; // v̂
function Perpendicular(v:Vector2) : Vector2; // v⃗⊥
function Project(v:Vector2, w:Vector2) : Vector2; // Return the projection of w⃗ onto v⃗, (v⃗w⃗ / ‖ v⃗ ‖²)v⃗
function Reflect(v:Vector2, w:Vector2) : Vector2; // Return the reflection of w⃗ against v⃗, 2(v⃗⋅w⃗ )w⃗-v⃗
function Rotation(rad:number) : Vector2;
function Subtract(v:Vector2, w:Vector2) : Vector2; // v⃗-w⃗
function add(r:R, v:Vector2, w:Vector2) : R; // r⃗ = v⃗+w⃗
function addAssign(v:R, w:Vector2) : R; // v⃗ = v⃗+w⃗
function assign(r:R, x:number = 0.0, y:number = 0.0) : R;
function axisX(r:R, s:number = 1.0) : R; // r⃗ = sx̂
function axisY(r:R, s:number = 1.0) : R; // r⃗ = sŷ
function barycentricUV(r:R, vx0:Vector2, vx1:Vector2, vx2:Vector2, u:number, v:number) : R; // Assign the point represented by barycentric coordinates (u, v) in ↻ triangle (vx0, vx1, vx2) to r⃗
function copy(r:R, v:Vector2) : R;
function createStringifier(opts?:Partial>) : stringify;
function cross(v:Vector2, w:Vector2) : number; // v⃗×w⃗
function dot(v:Vector2, w:Vector2) : number; // v⃗⋅w⃗
function equals(v:Vector2, w:Vector2, e:number = epsilon) : boolean;
function hadamard(r:R, v:Vector2, w:Vector2) : R; // r⃗ = v⃗⊙w⃗
function hadamardAssign(v:R, w:Vector2) : R; // v⃗ = v⃗⊙w⃗
function hadamardInvert(r:R, v:Vector2) : R; // r⃗ = 1⁄v⃗
function isNormEqual(v:Vector2, n:number, e:number = epsilon) : boolean; // ‖ v⃗ ‖ - n < ϵ
function isNormGt(v:Vector2, n:number) : boolean; // ‖ v⃗ ‖ > n
function isNormLt(v:Vector2, n:number) : boolean; // ‖ v⃗ ‖ < n
function lerp(r:R, v:Vector2, w:Vector2, t:number) : R; // r⃗ = v⃗ + (w⃗ - v⃗ ) * t
function lerpAssign(v:R, w:Vector2, t:number) : R; // v⃗ = v⃗ + (w⃗ - v⃗ ) * t
function multiply2x3Matrix3(r:R, m:Matrix3, v:Vector2) : R; // r⃗ = M₂ₓ₃v⃗
function multiplyAssignScalar(v:R, n:number) : R; // v⃗ = nv⃗
function multiplyMatrix2(r:R, m:Matrix2, v:Vector2) : R; // r⃗ = M₂ₓ₂v⃗
function multiplyMatrix3(r:R, m:Matrix3, v:Vector2) : R; // r⃗ = M₃ₓ₃v⃗
function multiplyScalar(r:R, v:Vector2, n:number) : R; // r⃗ = nv⃗
function negate(r:R, v:Vector2) : R; // r⃗ = -v⃗
function negateAssign(v:R) : R; // v⃗ = -v⃗
function norm(v:Vector2) : number; // ‖ v⃗ ‖
function normSquared(v:Vector2) : number; // ‖ v⃗ ‖²
function normalize(r:R, v:Vector2) : R; // r⃗ = v̂
function perpendicular(r:R, v:Vector2) : R; // r⃗ = v⃗⊥
function project(r:R, v:Vector2, w:Vector2) : R; // Assign the projection of w⃗ onto v⃗ to r⃗, r⃗ = (v⃗w⃗ / ‖ v⃗ ‖²)v⃗
function radians(v:Vector2, w:Vector2) : number; // acos(v⃗⋅w⃗ )
function reflect(r:R, v:Vector2, w:Vector2) : R; // Assign the reflection of w⃗ against v⃗, r⃗ = 2(v⃗⋅w⃗ )w⃗-v⃗
function rotation(r:R, rad:number) : R;
function subtract(r:R, v:Vector2, w:Vector2) : R; // r⃗ = v⃗-w⃗
function subtractAssign(v:R, w:Vector2) : R; // v⃗ = v⃗-w⃗
```
## vector3
[`./source/vector3.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/vector3.ts#L1)
### Interfaces
```ts
interface Vector3 extends Vector2 {
z : number;
}
```
### Functions
```ts
function Add(v:Vector3, w:Vector3) : Vector3; // v⃗+w⃗
function AxisX(s:number = 1.0) : Vector3; // sx̂
function AxisY(s:number = 1.0) : Vector3; // sŷ
function AxisZ(s:number = 1.0) : Vector3; // sẑ
function BarycentricUV(vx0:Vector3, vx1:Vector3, vx2:Vector3, u:number, v:number) : Vector3; // Return the point represented by barycentric coordinates (u, v) in ↻ triangle (vx0, vx1, vx2)
// @deprecated use same function in xyzw-rgba instead
function ClampScalar(v:Vector3, a:number, b:number) : Vector3; // min(max(v⃗, min(a, b)), max(a, b))
function Copy(v:Vector3) : Vector3;
function Create(x:number = 0.0, y:number = 0.0, z:number = 0.0) : Vector3;
function Cross(v:Vector3, w:Vector3) : Vector3; // v⃗×w⃗
function EulerXYZ(m:Matrix3) : Vector3;
function EulerYXZ(m:Matrix3) : Vector3;
function EulerZXY(m:Matrix3) : Vector3;
function F32(n:Float32Array, offset:number = 0) : Vector3;
function F64(n:Float64Array, offset:number = 0) : Vector3;
function Hadamard(v:Vector3, w:Vector3) : Vector3; // v⃗⊙w⃗
function HadamardInvert(v:Vector3) : Vector3; // 1⁄v⃗
function Lerp(v:Vector3, w:Vector3, t:number) : Vector3; // v⃗ + ( w⃗ - v⃗ ) * t
// @deprecated use same function in xyzw-rgba instead
function MaxScalar(v:Vector3, n:number) : Vector3; // max(v⃗, n)
// @deprecated use same function in xyzw-rgba instead
function MinScalar(v:Vector3, n:number) : Vector3; // min(v⃗, n)
function Multiply3x4Matrix4(m:Matrix4, v:Vector3) : Vector3; // M₃ₓ₄v⃗
function MultiplyMatrix3(m:Matrix3, v:Vector3) : Vector3; // M₃ₓ₃v⃗
function MultiplyMatrix4(m:Matrix4, v:Vector3) : Vector3; // M₄ₓ₄v⃗
function MultiplyScalar(v:Vector3, n:number) : Vector3; // nv⃗
function Negate(v:Vector3) : Vector3; // -v⃗
function Normalize(v:Vector3) : Vector3; // v̂
function OrthoNormalize(v:Vector3, w:Vector3) : Vector3; // w⃗ - (w⃗⋅v⃗ )v⃗
function Project(v:Vector3, w:Vector3) : Vector3; // Return the projection of w⃗ onto v⃗, (v⃗w⃗ / ‖ v⃗ ‖²)v⃗
function Reflect(v:Vector3, w:Vector3) : Vector3; // Return the reflection of w⃗ against v⃗, 2(v⃗⋅w⃗ )w⃗-v⃗
function Subtract(v:Vector3, w:Vector3) : Vector3; // v⃗-w⃗
function add(r:R, v:Vector3, w:Vector3) : R; // r⃗ = v⃗+w⃗
function addAssign(v:R, w:Vector3) : R; // v⃗ = v⃗+w⃗
function assign(r:R, x:number = 0.0, y:number = 0.0, z:number = 0.0) : R;
function assignF32(r:Float32Array, v:Vector3, offset:number = 0) : Float32Array;
function assignF64(r:Float64Array, v:Vector3, offset:number = 0) : Float64Array;
function axisX(r:R, s:number = 1.0) : R; // r⃗ = sx̂
function axisY(r:R, s:number = 1.0) : R; // r⃗ = sŷ
function axisZ(r:R, s:number = 1.0) : R; // r⃗ = sẑ
function azimuth(v:Vector3, w:Vector3, z:Vector3) : number; // Return the cosine of azimuth angle ϕ between v̂ and ŵ against polar axis ẑ, ( (v̂ - (v̂⋅ẑ)ẑ) / ‖ v̂ - (v̂⋅ẑ)ẑ ‖ )⋅( (ŵ - (ŵ⋅ẑ)ẑ) / ‖ ŵ - (ŵ⋅ẑ)ẑ ‖ )
function barycentricUV(r:R, vx0:Vector3, vx1:Vector3, vx2:Vector3, u:number, v:number) : R; // Assign the point represented by barycentric coordinates (u, v) in ↻ triangle (vx0, vx1, vx2) to r⃗
// @deprecated use same function in xyzw-rgba instead
function clampScalar(r:R, v:Vector3, a:number, b:number) : R; // r⃗ = min(max(v⃗, min(a, b)), max(a, b))
function copy(r:R, v:Vector3) : R;
function createStringifier(opts?:Partial>) : stringify;
function cross(r:R, v:Vector3, w:Vector3) : R; // r⃗ = v⃗×w⃗
function dot(v:Vector3, w:Vector3) : number; // v⃗⋅w⃗
function equals(v:Vector3, w:Vector3, e:number = epsilon) : boolean;
function eulerXYZ(r:R, m:Matrix3) : R;
function eulerYXZ(r:R, m:Matrix3) : R;
function eulerZXY(r:R, m:Matrix3) : R;
function f32(r:R, n:Float32Array, offset:number = 0) : R;
function f64(r:R, n:Float64Array, offset:number = 0) : R;
function hadamard(r:R, v:Vector3, w:Vector3) : R; // r⃗ = v⃗⊙w⃗
function hadamardAssign(v:R, w:Vector3) : R; // v⃗ = v⃗⊙w⃗
function hadamardInvert(r:R, v:Vector3) : R; // r⃗ = 1⁄v⃗
function isNormEqual(v:Vector3, n:number, e:number = epsilon) : boolean; // ‖ v⃗ ‖ - n < ϵ
function isNormGt(v:Vector3, n:number) : boolean; // ‖ v⃗ ‖ > n
function isNormLt(v:Vector3, n:number) : boolean; // ‖ v⃗ ‖ < n
function lerp(r:R, v:Vector3, w:Vector3, t:number) : R; // r⃗ = v⃗ + (w⃗ - v⃗ ) * t
function lerpAssign(v:R, w:Vector3, t:number) : R; // v⃗ = v⃗ + (w⃗ - v⃗ ) * t
// @deprecated use same function in xyzw-rgba instead
function maxScalar(r:R, v:Vector3, n:number) : R; // r⃗ = max(v⃗, n)
// @deprecated use same function in xyzw-rgba instead
function minScalar(r:R, v:Vector3, n:number) : R; // r⃗ = min(v⃗, n)
function multiply3x4Matrix4(r:R, m:Matrix4, v:Vector3) : R; // r⃗ = M₃ₓ₄v⃗
function multiplyAssignScalar(v:R, n:number) : R; // v⃗ = nv⃗
function multiplyMatrix3(r:R, m:Matrix3, v:Vector3) : R; // r⃗ = M₃ₓ₃v⃗
function multiplyMatrix4(r:R, m:Matrix4, v:Vector3) : R; // r⃗ = M₄ₓ₄v⃗
function multiplyScalar(r:R, v:Vector3, n:number) : R; // r⃗ = nv⃗
function negate(r:R, v:Vector3) : R; // r⃗ = -v⃗
function negateAssign(v:R) : R; // v⃗ = -v⃗
function norm(v:Vector3) : number; // ‖ v⃗ ‖
function normSquared(v:Vector3) : number; // ‖ v⃗ ‖²
function normalize(r:R, v:Vector3) : R; // r⃗ = v̂
function orthoNormalize(r:R, v:Vector3, w:Vector3) : R; // r⃗ = w⃗ - (w⃗⋅v⃗ )v⃗
function project(r:R, v:Vector3, w:Vector3) : R; // Assign the projection of w⃗ onto v⃗ to r⃗, r⃗ = (v⃗w⃗ / ‖ v⃗ ‖²)v⃗
function reflect(r:R, v:Vector3, w:Vector3) : R; // Assign the reflection of w⃗ against v⃗, r⃗ = 2(v⃗⋅w⃗ )w⃗-v⃗
function subtract(r:R, v:Vector3, w:Vector3) : R; // r⃗ = v⃗-w⃗
function subtractAssign(v:R, w:Vector3) : R; // v⃗ = v⃗-w⃗
function toF32(v:Vector3) : Float32Array;
function toF64(v:Vector3) : Float64Array;
```
## vector4
[`./source/vector4.ts`](https://github.com/chkt/xyzw/blob/1b87a06/source/vector4.ts#L1)
### Interfaces
```ts
interface Vector4 extends Vector3 {
w : number;
}
```
### Functions
```ts
function Add(v:Vector4, w:Vector4) : Vector4; // v⃗+w⃗
function Conjugate(v:Vector4) : Vector4; // q⃗′
function Copy(v:Vector4) : Vector4;
function Create(x:number = 0.0, y:number = 0.0, z:number = 0.0, w:number = 1.0) : Vector4;
function F32(n:Float32Array, offset:number = 0) : Vector4;
function F64(n:Float64Array, offset:number = 0) : Vector4;
function Hadamard(v:Vector4, w:Vector4) : Vector4; // v⃗⊙w⃗
function Inverse(v:Vector4) : Vector4 | undefined; // q⃗⁻¹
function MultiplyScalar(v:Vector4, n:number) : Vector4; // nv⃗
function Normalize(v:Vector4) : Vector4; // v̂
function Outer(v:Vector4, w:Vector4) : Vector4; // v⃗w⃗
function RotationAxis(v:Vector3, rad:number) : Vector4; // q̂(v⃗, θ)
function RotationMatrix3(m:Matrix3) : Vector4; // q̂(M)
function RotationSlerp(v:Vector4, w:Vector4, t:number) : Vector4; // v̂(ŵ⁻¹v̂)ᵗ
function Subtract(v:Vector4, w:Vector4) : Vector4; // v⃗-w⃗
function Vector3(v:Vector3, w:number = 1.0) : Vector4; // ŵ+v⃗
function add(r:R, v:Vector4, w:Vector4) : R; // r⃗ = v⃗+w⃗
function addAssign(v:R, w:Vector4) : R; // v⃗ = v⃗+w⃗
function assign(r:R, x:number = 0.0, y:number = 0.0, z:number = 0.0, w:number = 1.0) : R;
function assignF32(r:Float32Array, v:Vector4, offset:number = 0) : Float32Array;
function assignF64(r:Float64Array, v:Vector4, offset:number = 0) : Float64Array;
function conjugate(r:R, v:Vector4) : R; // r⃗ = q⃗′
function copy(r:R, v:Vector4) : R;
function createStringifier(opts?:Partial>) : stringify;
function dot(v:Vector4, w:Vector4) : number; // v⃗⋅w⃗
function equals(v:Vector4, w:Vector4, e:number = epsilon) : boolean;
function f32(r:R, n:Float32Array, offset:number = 0) : R;
function f64(r:R, n:Float64Array, offset:number = 0) : R;
function hadamard(r:R, v:Vector4, w:Vector4) : R; // r⃗ = v⃗⊙w⃗
function hadamardAssign(v:R, w:Vector4) : R; // v⃗ = v⃗⊙w⃗
function inverse(r:R, v:Vector4) : R | undefined; // r⃗ = q⃗⁻¹
function multiplyAssignScalar(v:R, n:number) : R; // v⃗ = nv⃗
function multiplyScalar(r:R, v:Vector4, n:number) : R; // r⃗ = nv⃗
function norm(v:Vector4) : number; // ‖ v⃗ ‖
function normSquared(v:Vector4) : number; // ‖ v⃗ ‖²
function normalize(r:R, v:Vector4) : R; // r⃗ = v̂
function outer(r:R, v:Vector4, w:Vector4) : R; // r⃗ = v⃗w⃗
function rotationAxis(r:R, v:Vector3, rad:number) : R; // r⃗ = q̂(v⃗, θ)
function rotationMatrix3(r:R, m:Matrix3) : R; // r⃗ = q̂(M)
function rotationSlerp(r:R, v:Vector4, w:Vector4, t:number) : R; // r⃗ = v̂(ŵ⁻¹v̂)ᵗ
function subtract(r:R, v:Vector4, w:Vector4) : R; // r⃗ = v⃗-w⃗
function subtractAssign(v:R, w:Vector4) : R; // v⃗ = v⃗-w⃗
function toF32(v:Vector4) : Float32Array;
function toF64(v:Vector4) : Float64Array;
function vector3(r:R, v:Vector3, w:number = 1.0) : R; // r⃗ = ŵ+v⃗
```