类: Vec2

extend: size

导入示例:

import { math } from "cc"; 
const { Vec2 } = math;

二维向量。

索引

构造函数

静态属性

静态方法
向量与四维矩阵乘法,默认向量第三位为 0,第四位为 1。
向量与三维矩阵乘法,默认向量第三位为 1。
向量转数组
逐元素向量减法
向量等价判断
返回向量的字符串表示
求两向量的欧氏距离平方
设置向量值
逐元素向量乘加: A + B * scale
逐元素向量四舍五入取整
生成一个在单位圆上均匀分布的随机向量
归一化向量,输入零向量将会返回零向量。
逐元素向量取负
向量标量乘法
逐元素向量乘法
逐元素向量最小值
逐元素向量最大值
逐元素向量线性插值: A + t * (B - A)
求向量长度平方
求向量长度
逐元素向量取倒数,接近 0 时返回 0
逐元素向量取倒数,接近 0 时返回 Infinity
数组转向量
逐元素向量向下取整
排除浮点数误差的向量近似等价判断
向量点积(数量积)
逐元素向量除法
求两向量的欧氏距离
向量叉积(向量积),注意二维向量的叉积为与 Z 轴平行的三维向量
复制目标向量
获得指定向量的拷贝
逐元素向量向上取整
求两向量夹角弧度,任意一个向量是零向量则返回零。
逐元素向量加法

属性
  • y public
y 分量。
  • x public
x 分量。

方法
将当前向量视为 z 分量为 0、w 分量为 1 的四维向量,
应用四维矩阵变换到当前矩阵
向量减法。将当前向量减去指定分量的向量
向量减法。将当前向量减去指定向量
判断当前向量是否与指定分量的向量相等。
判断当前向量是否与指定向量相等。
获取当前向量和指定向量之间的有符号角度。
有符号角度的取值范围为 (-180, 180],当前向量可以通过逆时针旋转有符号角度与指定向量同向。
将当前向量的旋转
计算当前向量在指定向量上的投影向量。
将当前向量归一化。
将当前向量的各个分量取反
向量数乘。将当前向量数乘指定标量
向量乘法。将当前向量与指定分量的向量相乘的结果赋值给当前向量。
向量乘法。将当前向量乘以与指定向量的结果赋值给当前向量。
根据指定的插值比率,从当前向量到目标向量之间做插值。
计算向量长度(模)的平方。
计算向量的长度(模)。
判断当前向量是否在误差范围内与指定分量的向量相等。
向量点乘。
向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
向量叉乘。
设置当前向量的值,使其各个分量都处于指定的范围内。
获取当前向量和指定向量之间的角度,任意一个向量是零向量则返回零。
向量加法。将当前向量与指定分量的向量相加
向量加法。将当前向量与指定向量的相加

继承方法
返回当前向量的字符串表示。
设置当前向量使其与指定向量相等。
判断当前向量是否在误差范围内与指定向量相等。
克隆当前向量。

详情

构造函数

public Vec2 (other : Vec2) :
Vec2
输入参数
名称类型描述
otherVec2-
返回值: Vec2
public Vec2 (x ?: number, y ?: number) :
Vec2
输入参数
名称类型描述
xnumber-
ynumber-
返回值: Vec2

静态属性

public ZERO : Readonly < Vec2 >
static
public UNIT_Y : Readonly < Vec2 >
static
public UNIT_X : Readonly < Vec2 >
static
public ONE : Readonly < Vec2 >
static
public NEG_ONE : Readonly < Vec2 >
static

静态方法

public transformMat4 <Out extends dot , MatLike extends Out> (out : Out, a : Out, m : Out) :
Out
static
向量与四维矩阵乘法,默认向量第三位为 0,第四位为 1。
输入参数
名称类型描述
outOut-
aOut-
mOut-
返回值: Out
public transformMat3 <Out extends dot , MatLike extends IMat3Like> (out : _planeBias, a : _planeBias, m : IMat3Like) :
_planeBias
static
向量与三维矩阵乘法,默认向量第三位为 1。
输入参数
名称类型描述
out_planeBias-
a_planeBias-
mIMat3Like-
返回值: _planeBias
public toArray <Out extends IWritableArrayLike < number, Out >> (out : Out, v : dot, ofs ?: number) :
Out
static
向量转数组
输入参数
名称类型描述
outOut-
vdot-
ofsnumberArray Start Offset
返回值: Out
public subtract <Out extends dot> (out : _globalDSManager, a : _globalDSManager, b : _globalDSManager) :
_globalDSManager
static
逐元素向量减法
输入参数
名称类型描述
out_globalDSManager-
a_globalDSManager-
b_globalDSManager-
返回值: _globalDSManager
public strictEquals <Out extends dot> (a : Out, b : Out) :
boolean
static
向量等价判断
输入参数
名称类型描述
aOut-
bOut-
返回值: boolean
public str <Out extends dot> (a : Out) :
string
static
返回向量的字符串表示
输入参数
名称类型描述
aOut-
返回值: string
public squaredDistance <Out extends dot> (a : LEVEL_1, b : LEVEL_1) :
number
static
求两向量的欧氏距离平方
输入参数
名称类型描述
aLEVEL_1-
bLEVEL_1-
返回值: number
public set <Out extends dot> (out : diffuseMap, x : number, y : number) :
diffuseMap
static
设置向量值
输入参数
名称类型描述
outdiffuseMap-
xnumber-
ynumber-
返回值: diffuseMap
public scaleAndAdd <Out extends dot> (out : ShadowType, a : ShadowType, b : ShadowType, scale : number) :
ShadowType
static
逐元素向量乘加: A + B * scale
输入参数
名称类型描述
outShadowType-
aShadowType-
bShadowType-
scalenumber-
返回值: ShadowType
public round <Out extends dot> (out : Out, a : Out) :
Out
static
逐元素向量四舍五入取整
输入参数
名称类型描述
outOut-
aOut-
返回值: Out
public random <Out extends dot> (out : _material, scale ?: number) :
_material
static
生成一个在单位圆上均匀分布的随机向量
输入参数
名称类型描述
out_material-
scalenumbervector length
返回值: _material
public normalize <Out extends dot , Vec2Like extends dot> (out : Out, a : Vec2Like) :
Out
static
归一化向量,输入零向量将会返回零向量。
输入参数
名称类型描述
outOut-
aVec2Like-
返回值: Out
public negate <Out extends dot> (out : Out, a : Out) :
Out
static
逐元素向量取负
输入参数
名称类型描述
outOut-
aOut-
返回值: Out
public multiplyScalar <Out extends dot> (out : ShadowSize, a : ShadowSize, b : number) :
ShadowSize
static
向量标量乘法
输入参数
名称类型描述
outShadowSize-
aShadowSize-
bnumber-
返回值: ShadowSize
public multiply <Out extends dot> (out : _useDiffuseMap, a : _useDiffuseMap, b : _useDiffuseMap) :
_useDiffuseMap
static
逐元素向量乘法
输入参数
名称类型描述
out_useDiffuseMap-
a_useDiffuseMap-
b_useDiffuseMap-
返回值: _useDiffuseMap
public min <Out extends dot> (out : Out, a : Out, b : Out) :
Out
static
逐元素向量最小值
输入参数
名称类型描述
outOut-
aOut-
bOut-
返回值: Out
public max <Out extends dot> (out : Out, a : Out, b : Out) :
Out
static
逐元素向量最大值
输入参数
名称类型描述
outOut-
aOut-
bOut-
返回值: Out
public lerp <Out extends dot> (out : material, a : material, b : material, t : number) :
material
static
逐元素向量线性插值: A + t * (B - A)
输入参数
名称类型描述
outmaterial-
amaterial-
bmaterial-
tnumber-
返回值: material
public lengthSqr <Out extends dot> (a : Shadows) :
number
static
求向量长度平方
输入参数
名称类型描述
aShadows-
返回值: number
public len <Out extends dot> (a : Out) :
number
static
求向量长度
输入参数
名称类型描述
aOut-
返回值: number
public inverseSafe <Out extends dot> (out : Out, a : Out) :
Out
static
逐元素向量取倒数,接近 0 时返回 0
输入参数
名称类型描述
outOut-
aOut-
返回值: Out
public inverse <Out extends dot> (out : type, a : type) :
type
static
逐元素向量取倒数,接近 0 时返回 Infinity
输入参数
名称类型描述
outtype-
atype-
返回值: type
public fromArray <Out extends dot> (out : Fog, arr : IWritableArrayLike < number >, ofs ?: number) :
Fog
static
数组转向量
输入参数
名称类型描述
outFog-
arrIWritableArrayLike < number >-
ofsnumberArray Start Offset
返回值: Fog
public floor <Out extends dot> (out : setSkyboxMaterial, a : setSkyboxMaterial) :
setSkyboxMaterial
static
逐元素向量向下取整
输入参数
名称类型描述
outsetSkyboxMaterial-
asetSkyboxMaterial-
返回值: setSkyboxMaterial
public equals <Out extends dot> (a : fogColor, b : fogColor, epsilon ?: number) :
boolean
static
排除浮点数误差的向量近似等价判断
输入参数
名称类型描述
afogColor-
bfogColor-
epsilonnumber-
返回值: boolean
public dot <Out extends dot> (a : shadowColor, b : shadowColor) :
number
static
向量点积(数量积)
输入参数
名称类型描述
ashadowColor-
bshadowColor-
返回值: number
public divide <Out extends dot> (out : initialize, a : initialize, b : initialize) :
initialize
static
逐元素向量除法
输入参数
名称类型描述
outinitialize-
ainitialize-
binitialize-
返回值: initialize
public distance <Out extends dot> (a : SOFT, b : SOFT) :
number
static
求两向量的欧氏距离
输入参数
名称类型描述
aSOFT-
bSOFT-
返回值: number
public cross (a : dot, b : dot) :
number
static
向量叉积(向量积),注意二维向量的叉积为与 Z 轴平行的三维向量
输入参数
名称类型描述
adot-
bdot-
返回值: number
public cross <Out extends dot> (out : baked, a : shadowMapDirty, b : shadowMapDirty) :
baked
static
输入参数
名称类型描述
outbaked-
ashadowMapDirty-
bshadowMapDirty-
返回值: baked
public copy <Out extends dot> (out : Out, a : Out) :
Out
static
复制目标向量
输入参数
名称类型描述
outOut-
aOut-
返回值: Out
public clone <Out extends dot> (a : Out) :
Vec2
static
获得指定向量的拷贝
输入参数
名称类型描述
aOut-
返回值: Vec2
public ceil <Out extends dot> (out : Out, a : Out) :
Out
static
逐元素向量向上取整
输入参数
名称类型描述
outOut-
aOut-
返回值: Out
public angle <Out extends dot> (a : Out, b : Out) :
number
static
求两向量夹角弧度,任意一个向量是零向量则返回零。
输入参数
名称类型描述
aOut-
bOut-
返回值: number
public add <Out extends dot> (out : editableMaterial, a : editableMaterial, b : editableMaterial) :
editableMaterial
static
逐元素向量加法
输入参数
名称类型描述
outeditableMaterial-
aeditableMaterial-
beditableMaterial-
返回值: editableMaterial

属性

public y : number
y 分量。
public x : number
x 分量。

方法

public transformMat4 (matrix : Mat4) :
Vec2
将当前向量视为 z 分量为 0、w 分量为 1 的四维向量,
应用四维矩阵变换到当前矩阵
输入参数
名称类型描述
matrixMat4matrix to transform with
返回值: Vec2
public subtract2f (x : number, y : number) :
Vec2
向量减法。将当前向量减去指定分量的向量
输入参数
名称类型描述
xnumberThe x value of specified vector
ynumberThe y value of specified vector
返回值: Vec2
public subtract (other : Vec2) :
Vec2
向量减法。将当前向量减去指定向量
输入参数
名称类型描述
otherVec2specified vector
返回值: Vec2
public strictEquals2f (x : number, y : number) :
boolean
判断当前向量是否与指定分量的向量相等。
输入参数
名称类型描述
xnumberThe x value of specified vector
ynumberThe y value of specified vector
返回值: boolean
public strictEquals (other : Vec2) :
boolean
判断当前向量是否与指定向量相等。
输入参数
名称类型描述
otherVec2specified vector
返回值: boolean
public signAngle (other : Vec2) :
number
获取当前向量和指定向量之间的有符号角度。
有符号角度的取值范围为 (-180, 180],当前向量可以通过逆时针旋转有符号角度与指定向量同向。
输入参数
名称类型描述
otherVec2specified vector
返回值: number
public rotate (radians : number) :
Vec2
将当前向量的旋转
输入参数
名称类型描述
radiansnumberradius of rotation
返回值: Vec2
public project (other : Vec2) :
Vec2
计算当前向量在指定向量上的投影向量。
输入参数
名称类型描述
otherVec2specified vector
返回值: Vec2
public normalize () :
Vec2
将当前向量归一化。
返回值: Vec2
public negative () :
Vec2
将当前向量的各个分量取反
返回值: Vec2
public multiplyScalar (scalar : number) :
Vec2
向量数乘。将当前向量数乘指定标量
输入参数
名称类型描述
scalarnumberscalar number
返回值: Vec2
public multiply2f (x : number, y : number) :
Vec2
向量乘法。将当前向量与指定分量的向量相乘的结果赋值给当前向量。
输入参数
名称类型描述
xnumberThe x value of specified vector
ynumberThe y value of specified vector
返回值: Vec2
public multiply (other : Vec2) :
Vec2
向量乘法。将当前向量乘以与指定向量的结果赋值给当前向量。
输入参数
名称类型描述
otherVec2specified vector
返回值: Vec2
public lerp (to : Vec2, ratio : number) :
Vec2
根据指定的插值比率,从当前向量到目标向量之间做插值。
输入参数
名称类型描述
toVec2Target vector
rationumberThe interpolation coefficient.The range is [0,1].
返回值: Vec2
public lengthSqr () :
number
计算向量长度(模)的平方。
返回值: number
public length () :
number
计算向量的长度(模)。
返回值: number
public equals2f (x : number, y : number, epsilon ?: number) :
boolean
判断当前向量是否在误差范围内与指定分量的向量相等。
输入参数
名称类型描述
xnumberThe x value of specified vector
ynumberThe y value of specified vector
epsilonnumberThe error allowed. It`s should be a non-negative number.
返回值: boolean
public dot (other : Vec2) :
number
向量点乘。
输入参数
名称类型描述
otherVec2specified vector
返回值: number
public divide2f (x : number, y : number) :
Vec2
向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
输入参数
名称类型描述
xnumberThe x value of specified vector
ynumberThe y value of specified vector
返回值: Vec2
public divide (other : Vec2) :
Vec2
向量逐元素相除。将当前向量与指定分量的向量相除的结果赋值给当前向量。
输入参数
名称类型描述
otherVec2specified vector
返回值: Vec2
public cross (other : Vec2) :
number
向量叉乘。
输入参数
名称类型描述
otherVec2specified vector
返回值: number
public clampf (minInclusive : Vec2, maxInclusive : Vec2) :
Vec2
设置当前向量的值,使其各个分量都处于指定的范围内。
输入参数
名称类型描述
minInclusiveVec2Minimum value allowed
maxInclusiveVec2Maximum value allowed
返回值: Vec2
public angle (other : Vec2) :
number
获取当前向量和指定向量之间的角度,任意一个向量是零向量则返回零。
输入参数
名称类型描述
otherVec2specified vector.
返回值: number
public add2f (x : number, y : number) :
Vec2
向量加法。将当前向量与指定分量的向量相加
输入参数
名称类型描述
xnumberThe x value of specified vector
ynumberThe y value of specified vector
返回值: Vec2
public add (other : Vec2) :
Vec2
向量加法。将当前向量与指定向量的相加
输入参数
名称类型描述
otherVec2specified vector
返回值: Vec2

继承方法

public toString () :
string
返回当前向量的字符串表示。
返回值: string
public set (other : Vec2) :
Vec2
设置当前向量使其与指定向量相等。
输入参数
名称类型描述
otherVec2Specified vector
返回值: Vec2
public set (x ?: number, y ?: number) :
Vec2
设置当前向量的具体分量值。
输入参数
名称类型描述
xnumberx value
ynumbery value
返回值: Vec2
public equals (other : Vec2, epsilon ?: number) :
boolean
判断当前向量是否在误差范围内与指定向量相等。
输入参数
名称类型描述
otherVec2Specified vector
epsilonnumberThe error allowed. It`s should be a non-negative number.
返回值: boolean
public clone () :
Vec2
克隆当前向量。
返回值: Vec2

索引

构造函数
静态属性
静态方法
属性
  • y public
  • x public
方法
继承方法