KVector2d 接口
export 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.
属性
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.
方法
added
added(other: KVector2d): KVector2d;
两向量相加。
Return a new KVector3d which is this vector add the input vector.
参数:
- 
other: KVector2d被加的另一个向量。 The vector to add. 
返回值: KVector2d
两向量的和。
The new vector.
angle
angle(other: KVector2d): number;
计算两向量的夹角,以弧度计。
Calculate the angle between this vector and the other vector in radians.
参数:
- 
other: KVector2d要比较的向量。 The vector to compare this vector with. 
返回值: number
两向量的夹角,范围为[0, PI]。
The angle between the two vectors, the range is [0, PI].
angleTo
angleTo(other: KVector2d): number;
以特定方向来计算两向量的夹角,以弧度计。
Calculate the angle to other vector, with vecRef as reference.
参数:
- 
other: KVector2d要比较的向量。 The vector to compare this vector with. 
返回值: number
两向量的夹角,范围为[0, 2PI]。
The angle between the two vectors, the range is [0, 2PI).
appliedMatrix3
appliedMatrix3(matrix: KMatrix3): KVector2d;
对当前向量应用一个矩阵来进行变换。
Return a new Vector which is the result of this vector transformed by the input matrix.
参数:
- 
matrix: KMatrix3变换矩阵。 the input transform matrix. 
返回值: KVector2d
得到一个新的向量。
The new vector.
clone
clone(): KVector2d;
复制一个当前向量。
Return the cloned vector of this.
返回值: KVector2d
复制的向量。
The cloned vector.
cross
cross(other: KVector2d): number;
两向量的叉积。
Return the cross result of this vector and the input other vector.
参数:
- 
other: KVector2d被叉积的另一向量。 The vector to cross. 
返回值: number
两向量叉积的结果。
The cross product of the vectors.
dot
dot(other: KVector2d): number;
两向量的点积。
Return the dot product of this vector and the input other vector.
参数:
- 
other: KVector2d被点积的另一个向量。 The vector to dot. 
返回值: number
两向量点积的结果。
The dot product of the vectors.
isEqual
isEqual(other: KVector2d, 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: KVector2d被比较的向量。 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: KVector2d, 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: KVector2d被比较的另外一向量。 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: KVector2d, 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: KVector2d被比较的另外一向量。 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: KVector2d, 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: KVector2d要比较的向量。 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: KVector2d, 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: KVector2d要比较的向量。 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: KVector2d, 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: KVector2d被比较的另外一向量。 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): KVector2d;
返回一个新的向量,该新向量为当前向量的倍乘。
Return a new vector which is the scaler result of this vector.
参数:
- 
scale: number乘数。 The scale factor. 
返回值: KVector2d
倍乘后的向量。
a new multiplied vector.
normalized
normalized(): KVector2d;
返回当前向量的单位向量。
Return this vector's normalized vector.
返回值: KVector2d
一个新的单位向量。
a new normalized vector.
reversed
reversed(): KVector2d;
返回一个新的向量,该新向量为当前向量的翻转。
Return a new vector which is the reverse of this vector.
返回值: KVector2d
一个新的翻转向量。
a new reversed vector.
subtracted
subtracted(other: KVector2d): KVector2d;
两向量相减。
Return a new KVector3d which is this vector subtract the input vector.
参数:
- 
other: KVector2d被减的另一个向量。 The vector to subtract. 
返回值: KVector2d
两向量的差。
The new vector.