Class b2Math

Math utility functions.

Index

Properties

Methods

Properties

public static b2Mat22_identity: b2Mat22

Global instance of a 2x2 identity matrix. Use as read-only.

public static b2Transform_identity: b2Transform

Global instance of an identity transform. Use as read-only.

public static b2Vec2_zero: b2Vec2

Global instance of a zero'ed vector. Use as read-only.

Methods

public static Abs(a: number): number

Creates an ABS number.

Parameters

  • a: number

    Number to ABS.

Returns

number

Absolute value of a.

public static AbsM(A: b2Mat22): b2Mat22

Creates an ABS matrix.

Parameters

  • A: b2Mat22

    Matrix to ABS all values.

Returns

b2Mat22

Matrix with all positive values.

public static AbsV(a: b2Vec2): b2Vec2

Creates an ABS vector.

Parameters

  • a: b2Vec2

    Vector to ABS all values.

Returns

b2Vec2

Vector with all positive values.

public static AddMM(A: b2Mat22, B: b2Mat22): b2Mat22

Parameters

Returns

b2Mat22

public static AddVV(a: b2Vec2, b: b2Vec2): b2Vec2

Adds two vectors.

Parameters

Returns

b2Vec2

a + b.

public static Clamp(a: number, low: number, high: number): number

Clamp a number to the range of low to high.

Parameters

  • a: number

    Number to clamp.

  • low: number

    Low range.

  • high: number

    High range.

Returns

number

Number a clamped to range of low to high.

public static ClampV(a: b2Vec2, low: b2Vec2, high: b2Vec2): b2Vec2

Clamps a vector to the range of low to high.

Parameters

Returns

b2Vec2

Vector a clamped to range of low to high.

public static CrossFV(s: number, a: b2Vec2): b2Vec2

Cross product of s and vector 2.

Parameters

  • s: number

    s value.

  • a: b2Vec2

    Vector 2 to use in cross product.

Returns

b2Vec2

Cross product of s and a.

public static CrossVF(a: b2Vec2, s: number): b2Vec2

Cross product of vector 2 and s.

Parameters

  • a: b2Vec2

    Vector 2 to use in cross product.

  • s: number

    s value.

Returns

b2Vec2

Cross product of a and s.

public static CrossVV(a: b2Vec2, b: b2Vec2): number

Cross product of two vector 2s.

Parameters

  • a: b2Vec2

    Vector 2 to use in cross product.

  • b: b2Vec2

    Vector 2 to use in cross product.

Returns

number

Cross product of a and b.

public static Distance(a: b2Vec2, b: b2Vec2): number

Calculates the distance between two vectors.

Parameters

Returns

number

Distance between a and b.

public static DistanceSquared(a: b2Vec2, b: b2Vec2): number

Calculates the squared distance between two vectors.

Parameters

Returns

number

dist^2 between a and b.

public static Dot(a: b2Vec2, b: b2Vec2): number

Dot product of two vector 2s.

Parameters

  • a: b2Vec2

    Vector 2 to use in dot product.

  • b: b2Vec2

    Vector 2 to use in dot product.

Returns

number

Dot product of a and b.

public static IsPowerOfTwo(x: number): boolean

Check if a number is a power of 2.

Parameters

  • x: number

    Number to check if it is a power of 2.

Returns

boolean

True if x is a power of 2, otherwise false.

public static IsValid(x: number): boolean

Determines if a number is valid. A number is valid if it is finite.

Parameters

  • x: number

    Number to check for validity.

Returns

boolean

True if x is valid, otherwise false.

public static Max(a: number, b: number): number

Determines the max number.

Parameters

  • a: number

    First number.

  • b: number

    Second number.

Returns

number

a or b depending on which is the maximum.

public static MaxV(a: b2Vec2, b: b2Vec2): b2Vec2

Determines the max vector.

Parameters

Returns

b2Vec2

a or b depending on which is the maximum.

public static Min(a: number, b: number): number

Determines the minimum number.

Parameters

  • a: number

    First number.

  • b: number

    Second number.

Returns

number

a or b depending on which is the minimum.

public static MinV(a: b2Vec2, b: b2Vec2): b2Vec2

Determines the minimum vector.

Parameters

Returns

b2Vec2

a or b depending on which is the minimum.

public static MulFV(s: number, a: b2Vec2): b2Vec2

Parameters

Returns

b2Vec2

public static MulMM(A: b2Mat22, B: b2Mat22): b2Mat22

Parameters

Returns

b2Mat22

public static MulMV(A: b2Mat22, v: b2Vec2): b2Vec2

Multiply matrix and vector.

Parameters

Returns

b2Vec2

Result.

public static MulTMM(A: b2Mat22, B: b2Mat22): b2Mat22

Parameters

Returns

b2Mat22

public static MulTMV(A: b2Mat22, v: b2Vec2): b2Vec2

Parameters

Returns

b2Vec2

public static MulX(T: b2Transform, v: b2Vec2): b2Vec2

Parameters

Returns

b2Vec2

public static MulXT(T: b2Transform, v: b2Vec2): b2Vec2

Parameters

Returns

b2Vec2

public static NextPowerOfTwo(x: number): number

Calculates the next power of 2 after the given number.

Parameters

  • x: number

    Number to start search for the next power of 2.

Returns

number

The next number that is a power of 2.

public static Random(): number

Generates a random number.

Returns

number

public static RandomRange(lo: number, hi: number): number

Returns a random number between lo and hi.

Parameters

  • lo: number

    Lowest random number.

  • hi: number

    Highest random number.

Returns

number

Number between lo and hi.

public static SubtractVV(a: b2Vec2, b: b2Vec2): b2Vec2

Subtracts two vectors.

Parameters

Returns

b2Vec2

a - b.

public static Swap(a: any, b: any)

Swaps a and b objects.

Parameters

  • a: any

    a -> b.

  • b: any

    b -> a.