跳到主要内容

KVector3d 接口

export interface KVector3d 

KVector3d表示一个三维向量。 三维向量包含三个数。 注意:三维向量的三个分量不可变。

The KVector3d class represents a 3D vector. A 3D vector is an ordered triplet of numbers (labeled x, y, and z). NOTE: KVector3d's x, y and z are immutable.

属性

length

readonly length: number;

获得向量的长度。

Get vector's length.

x

readonly x: number;

获得向量的x值。

Get vector's x value.

y

readonly y: number;

获得向量的y值。

Get vector's y value.

z

readonly z: number;

获得向量的z值。

Get vector's z value.

方法

added

added(other: KVector3d): KVector3d;

两向量相加。

Return a new KVector3d which is this vector add the input vector.

参数:

  • other: KVector3d

    被加的另一个向量。

    The vector to add.

返回值: KVector3d

两向量的和。

The new vector.

angle

angle(other: KVector3d): number;

计算两向量的夹角,以弧度计。

Calculate the angle between this vector and the other vector in radians.

参数:

  • other: KVector3d

    要比较的向量。

    The vector to compare this vector with.

返回值: number

两向量的夹角,范围为[0, PI]。

The angle between the two vectors, the range is [0, PI].

angleTo

angleTo(other: KVector3d, vecRef: KVector3d): number;

以特定方向来计算两向量的夹角,以弧度计。

Calculate the angle to other vector, with vecRef as reference.

参数:

  • other: KVector3d

    要比较的向量。

    The vector to compare this vector with.

  • vecRef: KVector3d

    该向量用来决定角度计算的时针方向。

    the reference vec to determine the counter clockwise direction.

返回值: number

两向量的夹角,范围为[0, 2PI]。

The angle between the two vectors, the range is [0, 2PI).

appliedEuler

appliedEuler(euler: KEuler): KVector3d;

对当前向量应用一个由欧拉角定义的旋转变换,得到一个新向量。

Return a new Vector which is the result of this vector transformed by the input euler angles.

参数:

  • euler: KEuler

    欧拉角和欧拉角的顺序

    the input Euler angles and their order.

返回值: KVector3d

得到一个新的向量。

The new vector.

appliedMatrix4

appliedMatrix4(matrix: KMatrix4): KVector3d;

对当前向量应用一个矩阵来进行变换。

Return a new Vector which is the result of this vector transformed by the input matrix.

参数:

  • matrix: KMatrix4

    变换矩阵。

    the input transform matrix.

返回值: KVector3d

得到一个新的向量。

The new vector.

appliedQuaternion

appliedQuaternion(quaternion: KQuaternion): KVector3d;

对当前向量应用一个由四元数定义的旋转变换,得到一个新向量。

Return a new Vector which is the result of this vector transformed by the input quaternion.

参数:

  • quaternion: KQuaternion

    四元数

    the input quaternion which detines the rotation.

返回值: KVector3d

得到一个新的向量。

The new vector.

clone

clone(): KVector3d;

复制一个当前向量。

Return the cloned vector of this.

返回值: KVector3d

复制的向量。

The cloned vector.

cross

cross(other: KVector3d): KVector3d;

两向量的叉积。

Return the cross result of this vector and the input other vector.

参数:

  • other: KVector3d

    被叉积的另一向量。

    The vector to cross.

返回值: KVector3d

两向量叉积的结果。

The cross product of the vectors.

dot

dot(other: KVector3d): number;

两向量的点积。

Return the dot product of this vector and the input other vector.

参数:

  • other: KVector3d

    被点积的另一个向量。

    The vector to dot.

返回值: number

两向量点积的结果。

The dot product of the vectors.

isEqual

isEqual(other: KVector3d, distanceTolerance?: number, cosTolerance?: number): boolean;

在特定容差下,判断两个向量是否相等。 两个向量相等需要满足在距离容差下长度相等和余弦容差下方向相等。

Check whether two vectors are equal with specified tolerances. If the length of two vectors are equal in the distance tolerance and the direction are same in the cosine tolerance, it will return true.

参数:

  • other: KVector3d

    被比较的向量。

    The vector to compare this vector with.

  • distanceTolerance: number

    距离容差,默认值是1e-6。

    It will provide distance tolerance when the length of vectors are measured.The default value is 1e-6.

  • cosTolerance: number

    余弦容差,默认值是1e-6。

    It will provide cosine tolerance when the direction of vectors are measured.The default value is 1e-6.

返回值: boolean

相等则返回true。

Return true if equal, otherwise return false.

isOnSameSide

isOnSameSide(other: KVector3d, distanceTolerance?: number, cosTolerance?: number, checkFuzzyZeroVec?: boolean): boolean;

检查两个向量在特定容差下是否为相同侧,相同侧意味着夹角小于九十度。 当checkFuzzyZeroVec为真时,如果两个向量中的任意一个长度在容差内接近零,结果直接为false。 当checkFuzzyZeroVec为假时,如果两个向量中的任意一个长度精确的等于零,结果直接为false。

Check if the directions of two vectors are equal within specified tolerance. If checkFuzzyZeroVec is true, any vector's length is nearly zero within the tolerance, false will be returned directly. If checkFuzzyZeroVec if false, only when any vector's length is exact 0, false will be returned directly.

参数:

  • other: KVector3d

    被比较的另外一向量。

    The vector to compare this vector with.

  • distanceTolerance: number

    距离容差,默认值是1e-6。

    It will provide distance tolerance when the length of vectors are measured.The default value is 1e-6.

  • cosTolerance: number

    余弦容差,默认值是1e-6。

    It will provide cosine tolerance when the direction of vectors are measured.The default value is 1e-6.

  • checkFuzzyZeroVec: boolean

    默认checkFuzzyZeroVec是真。

    The default value is true.

返回值: boolean

相同则返回true。

Return true if same, otherwise return false.

isOpposite

isOpposite(other: KVector3d, distanceTolerance?: number, cosTolerance?: number, checkFuzzyZeroVec?: boolean): boolean;

检查两个向量的方向在特定容差下是否相反。 当checkFuzzyZeroVec为真时,如果两个向量中的任意一个长度在容差内接近零,结果直接为false。 当checkFuzzyZeroVec为假时,如果两个向量中的任意一个长度精确的等于零,结果直接为false。

Check if this vector is opposite with other vector with specified tolerance. If checkFuzzyZeroVec is true, any vector's length is nearly zero within the tolerance, false will be returned directly. If checkFuzzyZeroVec if false, only when any vector's length is exact 0, false will be returned directly.

参数:

  • other: KVector3d

    被比较的另外一向量。

    The vector to compare this vector with.

  • distanceTolerance: number

    距离容差,默认值是1e-6。

    It will provide distance tolerance when the length of vectors are measured.The default value is 1e-6.

  • cosTolerance: number

    余弦容差,默认值是1e-6。

    It will provide cosine tolerance when the direction of vectors are measured.The default value is 1e-6.

  • checkFuzzyZeroVec: boolean

    默认checkFuzzyZeroVec是真。

    The default value is true.

返回值: boolean

相反则返回true。

Return true if opposite, otherwise return false.

isParallel

isParallel(other: KVector3d, tolerance?: number, checkFuzzyZeroVec?: boolean): boolean;

在特定容差下判断两个向量是否平行。 当checkFuzzyZeroVec为真时,如果两个向量中的任意一个长度在容差内接近零,结果直接为false。 当checkFuzzyZeroVec为假时,如果两个向量中的任意一个长度精确的等于零,结果直接为false。

Check if this vector is parallel with other vector with specified tolerance. If checkFuzzyZeroVec is true and any vector's length is nearly zero with the tolerance, false will be return directly. If checkFuzzyZeroVec if false, only when any vector's length is exact 0, false will be returned directly.

参数:

  • other: KVector3d

    要比较的向量。

    The vector to compare this vector with.

  • tolerance: number

    指定的容差。默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

  • checkFuzzyZeroVec: boolean

    默认checkFuzzyZeroVec是真。

    The default value is true.

返回值: boolean

如果平行则返回true。

Return true if parallel, otherwise return false.

isPerpendicular

isPerpendicular(other: KVector3d, tolerance?: number, checkFuzzyZeroVec?: boolean): boolean;

在特定容差下判断两个向量是否垂直。 当checkFuzzyZeroVec为真时,如果两个向量中的任意一个长度在容差内接近零,结果直接为false。 当checkFuzzyZeroVec为假时,如果两个向量中的任意一个长度精确的等于零,结果直接为false。

Check if this vector is perpendicular with other vector with specified tolerance. If checkFuzzyZeroVec is true, any vector's length is nearly zero within the tolerance, false will be returned directly. If checkFuzzyZeroVec is false, only when any vector's length is exact 0, false will be returned directly.

参数:

  • other: KVector3d

    要比较的向量。

    The vector to compare this vector with.

  • tolerance: number

    指定的容差。默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

  • checkFuzzyZeroVec: boolean

    默认checkFuzzyZeroVec是真。

    The default value is true.

返回值: boolean

如果垂直则返回true。

Return true if perpendicular, otherwise return false.

isSameDirection

isSameDirection(other: KVector3d, distanceTolerance?: number, cosTolerance?: number, checkFuzzyZeroVec?: boolean): boolean;

检查两个向量在特定容差下是否方向相同。 当checkFuzzyZeroVec为真时,如果两个向量中的任意一个长度在容差内接近零,结果直接为false。 当checkFuzzyZeroVec为假时,如果两个向量中的任意一个长度精确的等于零,结果直接为false。

Check if the directions of two vectors are equal within specified tolerance. If checkFuzzyZeroVec is true, any vector's length is nearly zero within the tolerance, false will be returned directly. If checkFuzzyZeroVec if false, only when any vector's length is exact 0, false will be returned directly.

参数:

  • other: KVector3d

    被比较的另外一向量。

    The vector to compare this vector with.

  • distanceTolerance: number

    距离容差,默认值是1e-6。

    It will provide distance tolerance when the length of vectors are measured.The default value is 1e-6.

  • cosTolerance: number

    余弦容差,默认值是1e-6。

    It will provide cosine tolerance when the direction of vectors are measured.The default value is 1e-6.

  • checkFuzzyZeroVec: boolean

    默认checkFuzzyZeroVec是真。

    The default value is true.

返回值: boolean

相同则返回true。

Return true if same, otherwise return false.

isZero

isZero(tolerance?: number): boolean;

检查当前向量是否为零向量。 注意:零向量是指向量的长度在容差范围内等于零。

Check whether a vector is zero vector. NOTE: A vector is zero vector if its length is 0 with specified tolerance.

参数:

  • tolerance: number

    指定的容差。默认值是1e-6。

    The specified tolerance.The default value is 1e-6.

返回值: boolean

如果为零向量。

Return true if the vector is zero vector, otherwise return false.

multiplied

multiplied(scale: number): KVector3d;

返回一个新的向量,该新向量为当前向量的倍乘。

Return a new vector which is the scaler result of this vector.

参数:

  • scale: number

    乘数。

    The scale factor.

返回值: KVector3d

倍乘后的向量。

a new multiplied vector.

normalized

normalized(): KVector3d;

返回当前向量的单位向量。

Return this vector's normalized vector.

返回值: KVector3d

一个新的单位向量。

a new normalized vector.

reversed

reversed(): KVector3d;

返回一个新的向量,该新向量为当前向量的翻转。

Return a new vector which is the reverse of this vector.

返回值: KVector3d

一个新的翻转向量。

a new reversed vector.

subtracted

subtracted(other: KVector3d): KVector3d;

两向量相减。

Return a new KVector3d which is this vector subtract the input vector.

参数:

  • other: KVector3d

    被减的另一个向量。

    The vector to subtract.

返回值: KVector3d

两向量的差。

The new vector.