SkillAgentSearch skills...

Xyzw

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

Install / Use

/learn @chkt/Xyzw
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Tests Version Node Dependencies Licence Language Size

xyzw

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

Install

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.

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.

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).

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

assert.strictEqual(u, v);
assert.notStrictEqual(w, v);

Modules

complex

./source/complex.ts

Functions

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 extends Vector2>(r:R, v:Vector2) : R;  // r⃗ = z̅
function divide<R extends Vector2>(r:R, z:Vector2, w:Vector2) : R;  // r⃗ = zw̅ / ww̅, z = a + bi, w = c = di
function inverse<R extends Vector2>(r:R, z:Vector2) : R;  // r⃗ = z⁻¹
function multiply<R extends Vector2>(r:R, z:Vector2, w:Vector2) : R;  // r⃗ = zw, z = a + bi, w = c + di
function power<R extends Iterable<undefined | Vector2, R>>(r:R, z:Vector2, n:number) : R;  // r⃗₍ₖ₎ = zⁿ₍ₖ₎

index

./source/index.ts

References

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

Interfaces

interface Matrix2 {
  r00 : number;
  r01 : number;
  r10 : number;
  r11 : number;
}

Functions

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 extends Matrix2>(r:R, a:Matrix2, b:Matrix2) : R;  // Mᵣ = A+B
function addAssign<R extends Matrix2>(a:R, b:Matrix2) : R;  // A = A+B
function concat<R extends Matrix2>(r:R, a:Matrix2, b:Matrix2) : R;  // Mᵣ = AB
function copy<R extends Matrix2>(r:R, m:Matrix2) : R;
function determinant(m:Matrix2) : number;  // |M|
function identity<R extends Matrix2>(r:R) : R;  // Mᵣ = Î
function inverse<R extends Matrix2>(r:R, m:Matrix2) : R | undefined;  // Mᵣ = M⁻¹
function rotation<R extends Matrix2>(r:R, rad:number) : R;  // Mᵣ = R(θ)
function rotationVector2<R extends Matrix2>(r:R, v:Vector2) : R;  // Mᵣ = [ v⃗  v⃗⊥ ]
function scale<R extends Matrix2>(r:R, v:Vector2) : R;  // Mᵣ = [ x̂v⃗₀  ŷv⃗₁ ]
function shear<R extends Matrix2>(r:R, x:Vector2, y:Vector2) : R;  // Mᵣ = [ x⃗  y⃗ ]
// @deprecated alias of copy()
function shearMatrix3<R extends Matrix2>(r:R, m:Matrix2) : R;  // Mᵣ = [ m⁰ m¹ ]
function subtract<R extends Matrix2>(r:R, a:Matrix2, b:Matrix2) : R;  // Mᵣ = A-B
function subtractAssign<R extends Matrix2>(a:R, b:Matrix2) : R;  // A = A-B
function transpose<R extends Matrix2>(r:R, m:Matrix2) : R;  // Mᵣ = Mᵀ

matrix3

./source/matrix3.ts

Interfaces

interface Matrix3 extends Matrix2 {
  r02 : number;
  r12 : number;
  r20 : number;
  r21 : number;
  r22 : number;
}

Functions

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 extends Matrix3>(r:R, a:Matrix3, b:Matrix3) : R;  // Mᵣ = A+B
function addAssign<R extends Matrix3>(a:R, b:Matrix3) : R;  // A = A+B
function concat<R extends Matrix3>(r:R, a:Matrix3, b:Matrix3) : R;  // Mᵣ = AB
function concat2x3<R extends Matrix3>(r:R, a:Matrix3, b:Matrix3) : R;  // Mᵣ = AB₂ₓ₃
function concatMatrix2<R extends Matrix3>(r:R, a:Matrix3, b:Matrix2) : R;  // Mᵣ = AB₂ₓ₂
function concatScaleVector2<R extends Matrix3>(r:R, m:Matrix3, v:Vector2) : R;  // Mᵣ = M[ x̂v⃗₀  ŷv⃗₁  ẑ ]
function concatTranslation<R extends Matrix3>(r:R, m:Matrix3, v:Vector2) : R;  // Mᵣ = M[ x̂  ŷ  v⃗ ]
function copy<R extends Matrix3>(r:R, m:Matrix3) : R;
function determinant(m:Matrix3) : number;  // |M|
function equals(a:Matrix3, b:Matrix3, e:number = epsilon) : boolean;
function eulerXYZ<R extends Matrix3>(r:R, v:Vector3) : R;  // Mᵣ = R(x̂, v⃗₀)R(ŷ, v⃗₁)R(ẑ, v⃗₂)
function eulerYXZ<R extends Matrix3>(r:R, v:Vector3) : R;  // Mᵣ = R(ŷ, v⃗₁)R(x̂, v⃗₀)R(ẑ, v⃗₂)
function eulerZXY<R extends Matrix3>(r:R, v:Vector3) : R;  // Mᵣ = R(ẑ, v⃗₂)R(x̂, v⃗₀)R(ŷ, v⃗₁)
function identity<R extends Matrix3>(r:R) : R;  // Mᵣ = Î
function inverse<R extends Matrix3>(r:R, m:Matrix3) : R | undefined;  // Mᵣ = M⁻¹
function quaternion<R extends Matrix3>(r:R, q:Vector4) : R;  // Mᵣ = R(q̂)
function rotationAxis<R extends Matrix3>(r:R, v:Vector3, rad:number) : R;  // Mᵣ = R(v⃗, θ)
function rotationVector3<R extends Matrix3>(r:R, x:Vector3, y:Vector3) : R;  // Mᵣ = [ x⃗  y⃗  x⃗×y⃗ ]
function rotationX<R extends Matrix3>(r:R, rad:number) : R;  // Mᵣ = R(x̂, θ)
function rotationY<R extends Matrix3>(r:R, rad:number) : R;  // Mᵣ = R(ŷ, θ)
function rotationZ<R extends Matrix3>(r:R, rad:number) : R;  // Mᵣ = R(ẑ, θ)
function rotationZMatrix2<R extends Matrix3>(r:R, m:Matrix2) : R;  // Mᵣ = [ m⁰ m¹ ẑ ]
function rotationZVector2<R extends Matrix3>(r:R, x:Vector2) : R;  // Mᵣ
View on GitHub
GitHub Stars15
CategoryDevelopment
Updated8mo ago
Forks3

Languages

TypeScript

Security Score

72/100

Audited on Jul 22, 2025

No findings