Skip to main content

KVector2d

kds-plugin-document / Exports / KVector2d

Interface: KVector2d

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

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

Table of contents

Properties

Methods

Properties

length

Readonly length: number

获得向量的长度。

Get vector's length.

Defined in

api.d.ts:10429


x

Readonly x: number

获得向量的x值。

Get vector's x value.

Defined in

api.d.ts:10417


y

Readonly y: number

获得向量的y值。

Get vector's y value.

Defined in

api.d.ts:10423

Methods

added

added(other): KVector2d

两向量相加。

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

Parameters

NameTypeDescription
otherKVector2d被加的另一个向量。 The vector to add.

Returns

KVector2d

两向量的和。

The new vector.

Defined in

api.d.ts:10598


angle

angle(other): number

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

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

Parameters

NameTypeDescription
otherKVector2d要比较的向量。 The vector to compare this vector with.

Returns

number

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

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

Defined in

api.d.ts:10570


angleTo

angleTo(other): number

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

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

Parameters

NameTypeDescription
otherKVector2d要比较的向量。 The vector to compare this vector with.

Returns

number

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

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

Defined in

api.d.ts:10584


appliedMatrix3

appliedMatrix3(matrix): KVector2d

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

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

Parameters

NameTypeDescription
matrixKMatrix3变换矩阵。 the input transform matrix.

Returns

KVector2d

得到一个新的向量。

The new vector.

Defined in

api.d.ts:10754


clone

clone(): KVector2d

复制一个当前向量。

Return the cloned vector of this.

Returns

KVector2d

复制的向量。

The cloned vector.

Defined in

api.d.ts:10650


cross

cross(other): number

两向量的叉积。

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

Parameters

NameTypeDescription
otherKVector2d被叉积的另一向量。 The vector to cross.

Returns

number

两向量叉积的结果。

The cross product of the vectors.

Defined in

api.d.ts:10640


dot

dot(other): number

两向量的点积。

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

Parameters

NameTypeDescription
otherKVector2d被点积的另一个向量。 The vector to dot.

Returns

number

两向量点积的结果。

The dot product of the vectors.

Defined in

api.d.ts:10626


isEqual

isEqual(other, distanceTolerance?, cosTolerance?): 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.

Parameters

NameTypeDescription
otherKVector2d被比较的向量。 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.

Returns

boolean

相等则返回true。

Return true if equal, otherwise return false.

Defined in

api.d.ts:10488


isOnSameSide

isOnSameSide(other, distanceTolerance?, cosTolerance?, checkFuzzyZeroVec?): 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.

Parameters

NameTypeDescription
otherKVector2d被比较的另外一向量。 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.

Returns

boolean

相同则返回true。

Return true if same, otherwise return false.

Defined in

api.d.ts:10710


isOpposite

isOpposite(other, distanceTolerance?, cosTolerance?, checkFuzzyZeroVec?): 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.

Parameters

NameTypeDescription
otherKVector2d被比较的另外一向量。 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.

Returns

boolean

相反则返回true。

Return true if opposite, otherwise return false.

Defined in

api.d.ts:10740


isParallel

isParallel(other, tolerance?, checkFuzzyZeroVec?): 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.

Parameters

NameTypeDescription
otherKVector2d要比较的向量。 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.

Returns

boolean

如果平行则返回true。

Return true if parallel, otherwise return false.

Defined in

api.d.ts:10540


isPerpendicular

isPerpendicular(other, tolerance?, checkFuzzyZeroVec?): 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.

Parameters

NameTypeDescription
otherKVector2d要比较的向量。 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.

Returns

boolean

如果垂直则返回true。

Return true if perpendicular, otherwise return false.

Defined in

api.d.ts:10514


isSameDirection

isSameDirection(other, distanceTolerance?, cosTolerance?, checkFuzzyZeroVec?): 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.

Parameters

NameTypeDescription
otherKVector2d被比较的另外一向量。 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.

Returns

boolean

相同则返回true。

Return true if same, otherwise return false.

Defined in

api.d.ts:10680


isZero

isZero(tolerance?): boolean

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

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

Parameters

NameTypeDescription
tolerance?number指定的容差。默认值是1e-6。 The specified tolerance.The default value is 1e-6.

Returns

boolean

如果为零向量。

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

Defined in

api.d.ts:10556


multiplied

multiplied(scale): KVector2d

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

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

Parameters

NameTypeDescription
scalenumber乘数。 The scale factor.

Returns

KVector2d

倍乘后的向量。

a new multiplied vector.

Defined in

api.d.ts:10463


normalized

normalized(): KVector2d

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

Return this vector's normalized vector.

Returns

KVector2d

一个新的单位向量。

a new normalized vector.

Defined in

api.d.ts:10439


reversed

reversed(): KVector2d

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

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

Returns

KVector2d

一个新的翻转向量。

a new reversed vector.

Defined in

api.d.ts:10449


subtracted

subtracted(other): KVector2d

两向量相减。

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

Parameters

NameTypeDescription
otherKVector2d被减的另一个向量。 The vector to subtract.

Returns

KVector2d

两向量的差。

The new vector.

Defined in

api.d.ts:10612