Options
All
  • Public
  • Public/Protected
  • All
Menu

Class Vec2

二维向量。

Hierarchy

Index

Constructors

constructor

  • newVec2(other: Vec2): Vec2
  • newVec2(x?: undefined | number, y?: undefined | number): Vec2

Properties

x

x: number

x 分量。

y

y: number

y 分量。

Static NEGONE

NEGONE: {} = Object.freeze(new Vec2(-1, -1))

Type declaration

Static ONE

ONE: {} = Object.freeze(new Vec2(1, 1))

Type declaration

Static UNITX

UNITX: {} = Object.freeze(new Vec2(1, 0))

Type declaration

Static UNITY

UNITY: {} = Object.freeze(new Vec2(0, 1))

Type declaration

Static ZERO

ZERO: {} = Object.freeze(new Vec2(0, 0))

Type declaration

Methods

add

  • add(other: Vec2): this

add2f

  • add2f(x: number, y: number): this
  • 向量加法。将当前向量与指定分量的向量相加

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

angle

  • angle(other: Vec2): number
  • 获取当前向量和指定向量之间的角度。

    Parameters

    • other: Vec2

      specified vector

    Returns number

    The angle between the current vector and the specified vector (in radians); if there are zero vectors in the current vector and the specified vector, 0 is returned.

clampf

  • clampf(minInclusive: Vec2, maxInclusive: Vec2): this
  • 设置当前向量的值,使其各个分量都处于指定的范围内。

    Parameters

    • minInclusive: Vec2

      Minimum value allowed

    • maxInclusive: Vec2

      Maximum value allowed

    Returns this

    this

clone

cross

  • cross(other: Vec2): number

divide

  • divide(other: Vec2): this
  • 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。

    Parameters

    • other: Vec2

      specified vector

    Returns this

divide2f

  • divide2f(x: number, y: number): this
  • 向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

dot

  • dot(other: Vec2): number
  • 向量点乘。

    Parameters

    • other: Vec2

      specified vector

    Returns number

    The result of calculates the dot product with another vector

equals

  • equals(other: Vec2, epsilon?: number): boolean
  • 判断当前向量是否在误差范围内与指定向量相等。

    Parameters

    • other: Vec2

      Specified vector

    • Default value epsilon: number = EPSILON

      The error allowed. It`s should be a non-negative number.

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

equals2f

  • equals2f(x: number, y: number, epsilon?: number): boolean
  • 判断当前向量是否在误差范围内与指定分量的向量相等。

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    • Default value epsilon: number = EPSILON

      The error allowed. It`s should be a non-negative number.

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

length

  • length(): number

lengthSqr

  • lengthSqr(): number

lerp

  • lerp(to: Vec2, ratio: number): this
  • 根据指定的插值比率,从当前向量到目标向量之间做插值。

    Parameters

    • to: Vec2

      Target vector

    • ratio: number

      The interpolation coefficient.The range is [0,1].

    Returns this

multiply

  • multiply(other: Vec2): this
  • 向量乘法。将当前向量乘以与指定向量的结果赋值给当前向量。

    Parameters

    • other: Vec2

      specified vector

    Returns this

multiply2f

  • multiply2f(x: number, y: number): this
  • 向量乘法。将当前向量与指定分量的向量相乘的结果赋值给当前向量。

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

multiplyScalar

  • multiplyScalar(scalar: number): this
  • 向量数乘。将当前向量数乘指定标量

    Parameters

    • scalar: number

      scalar number

    Returns this

negative

  • negative(): this

normalize

  • normalize(): this

project

  • project(other: Vec2): this

rotate

  • rotate(radians: number): this

set

  • set(other: Vec2): any
  • set(x?: undefined | number, y?: undefined | number): any

signAngle

  • signAngle(other: Vec2): number
  • 获取当前向量和指定向量之间的有符号角度。
    有符号角度的取值范围为 (-180, 180],当前向量可以通过逆时针旋转有符号角度与指定向量同向。

    Parameters

    • other: Vec2

      specified vector

    Returns number

    The signed angle between the current vector and the specified vector (in radians); if there is a zero vector in the current vector and the specified vector, 0 is returned.

strictEquals

  • strictEquals(other: Vec2): boolean
  • 判断当前向量是否与指定向量相等。

    Parameters

    • other: Vec2

      specified vector

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

strictEquals2f

  • strictEquals2f(x: number, y: number): boolean
  • 判断当前向量是否与指定分量的向量相等。

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns boolean

    Returns true when the components of both vectors are equal within the specified range of error; otherwise it returns false.

subtract

  • subtract(other: Vec2): this

subtract2f

  • subtract2f(x: number, y: number): this
  • 向量减法。将当前向量减去指定分量的向量

    Parameters

    • x: number

      The x value of specified vector

    • y: number

      The y value of specified vector

    Returns this

toString

  • toString(): string

transformMat4

  • transformMat4(matrix: Mat4): this
  • 将当前向量视为 z 分量为 0、w 分量为 1 的四维向量,
    应用四维矩阵变换到当前矩阵

    Parameters

    • matrix: Mat4

      matrix to transform with

    Returns this

Static add

  • add<Out>(out: Out, a: Out, b: Out): Out

Static angle

  • angle<Out>(a: Out, b: Out): number

Static ceil

  • ceil<Out>(out: Out, a: Out): Out

Static clone

  • clone<Out>(a: Out): Vec2

Static copy

  • copy<Out>(out: Out, a: Out): Out

Static cross

  • cross<Out>(out: Vec3, a: Out, b: Out): Vec3

Static distance

  • distance<Out>(a: Out, b: Out): number

Static divide

  • divide<Out>(out: Out, a: Out, b: Out): Out

Static dot

  • dot<Out>(a: Out, b: Out): number

Static equals

  • equals<Out>(a: Out, b: Out, epsilon?: number): boolean
  • 排除浮点数误差的向量近似等价判断

    Type parameters

    Parameters

    • a: Out
    • b: Out
    • Default value epsilon: number = EPSILON

    Returns boolean

Static floor

  • floor<Out>(out: Out, a: Out): Out

Static fromArray

  • fromArray<Out>(out: Out, arr: IWritableArrayLike<number>, ofs?: number): Out
  • 数组转向量

    Type parameters

    Parameters

    • out: Out
    • arr: IWritableArrayLike<number>
    • Default value ofs: number = 0

      Array Start Offset

    Returns Out

Static inverse

  • inverse<Out>(out: Out, a: Out): Out

Static inverseSafe

  • inverseSafe<Out>(out: Out, a: Out): Out

Static len

  • len<Out>(a: Out): number

Static lengthSqr

  • lengthSqr<Out>(a: Out): number

Static lerp

  • lerp<Out>(out: Out, a: Out, b: Out, t: number): Out

Static max

  • max<Out>(out: Out, a: Out, b: Out): Out

Static min

  • min<Out>(out: Out, a: Out, b: Out): Out

Static multiply

  • multiply<Out>(out: Out, a: Out, b: Out): Out

Static multiplyScalar

  • multiplyScalar<Out>(out: Out, a: Out, b: number): Out

Static negate

  • negate<Out>(out: Out, a: Out): Out

Static normalize

  • normalize<Out, Vec2Like>(out: Out, a: Vec2Like): Out

Static random

  • random<Out>(out: Out, scale?: undefined | number): Out
  • 生成一个在单位圆上均匀分布的随机向量

    Type parameters

    Parameters

    • out: Out
    • Optional scale: undefined | number

      vector length

    Returns Out

Static round

  • round<Out>(out: Out, a: Out): Out

Static scaleAndAdd

  • scaleAndAdd<Out>(out: Out, a: Out, b: Out, scale: number): Out

Static set

  • set<Out>(out: Out, x: number, y: number): Out

Static squaredDistance

  • squaredDistance<Out>(a: Out, b: Out): number

Static str

  • str<Out>(a: Out): string

Static strictEquals

  • strictEquals<Out>(a: Out, b: Out): boolean

Static subtract

  • subtract<Out>(out: Out, a: Out, b: Out): Out

Static toArray

  • toArray<Out>(out: Out, v: IVec2Like, ofs?: number): Out
  • 向量转数组

    Type parameters

    • Out: IWritableArrayLike<number>

    Parameters

    • out: Out
    • v: IVec2Like
    • Default value ofs: number = 0

      Array Start Offset

    Returns Out

Static transformMat3

  • transformMat3<Out, MatLike>(out: Out, a: Out, m: IMat3Like): Out

Static transformMat4

  • transformMat4<Out, MatLike>(out: Out, a: Out, m: IMat4Like): Out

Generated using TypeDoc