跳转至

Vector2

简要描述

用于2D数学的向量。

描述

2元素结构,可用于表示2D空间或任何其他成对的数值中的位置。

成员

类型 属性名 默认值
float x 0.0
float y 0.0

方法

返回值类型 方法名称
Vector2 Vector2(#method-Vector2)(x: float, y: float)
Vector2 abs()
float angle()
float angle_to(to: Vector2)
float angle_to_point(to: Vector2)
float aspect()
Vector2 bounce(n: Vector2)
Vector2 ceil()
Vector2 clamped(length: float)
float cross(with: Vector2)
Vector2 cubic_interpolate(b: Vector2, pre_a: Vector2, post_b: Vector2, t: float)
Vector2 direction_to(b: Vector2)
float distance_squared_to(to: Vector2)
float distance_to(to: Vector2)
float dot(with: Vector2)
Vector2 floor()
bool is_equal_approx(v: Vector2)
bool is_normalized()
float length()
float length_squared()
Vector2 linear_interpolate(b: Vector2, t: float)
Vector2 move_toward(to: Vector2, delta: float)
Vector2 normalized()
Vector2 posmod(mod: float)
Vector2 posmodv(modv: Vector2)
Vector2 project(b: Vector2)
Vector2 reflect(n: Vector2)
Vector2 rotated(phi: float)
Vector2 round()
Vector2 sign()
Vector2 slerp(b: Vector2, t: float)
Vector2 slide(n: Vector2)
Vector2 snapped(by: Vector2)
Vector2 tangent()

常量

  • AXIS_X = 0

X轴的枚举值。

  • AXIS_Y = 1

Y轴的枚举值。

  • ZERO = Vector2( 0, 0 )

零向量。

  • ONE = Vector2( 1, 1 )

一种向量。

  • INF = Vector2( inf, inf )

无限矢量。

  • LEFT = Vector2( -1, 0 )

左单位向量。

  • RIGHT = Vector2( 1, 0 )

正确的单位向量。

  • UP = Vector2( 0, -1 )

向上单位向量。

  • DOWN = Vector2( 0, 1 )

下单位向量。

成员说明

  • float x
Default 0.0
getter ****
  • float y
Default 0.0
getter ****

方法说明

  • Vector2 Vector2(x: float, y: float)

根据给定的xy构造一个新的Vector2。


  • abs abs()

返回一个新矢量,其中所有分量均为绝对值(即正数)。


  • angle angle()

返回向量相对于X轴的弧度角,即(1,0)向量。

当使用向量的[成员x]和成员y作为参数调用时,等效于[@]的结果:atan2(x,y)


  • angle_to angle_to(to: Vector2)

返回两个向量之间的弧度角。


  • angle_to_point angle_to_point(to: Vector2)

返回连接两个点的线和X坐标之间的弧度角。


  • aspect aspect()

返回[成员x]与成员y的比率。


  • bounce bounce(n: Vector2)

返回从给定法线定义的平面“反弹”的向量。


  • ceil ceil()

返回所有分量均四舍五入的向量。


  • clamped clamped(length: float)

返回最大长度的向量。


  • cross cross(with: Vector2)

返回具有给定向量的叉积的二维类似物。


  • cubic_interpolate cubic_interpolate(b: Vector2, pre_a: Vector2, post_b: Vector2, t: float)

使用pre_apost_b作为句柄在此向量和b之间进行内插,然后在t位置返回结果。


  • direction_to direction_to(b: Vector2)

返回从该向量指向b的归一化向量。


  • distance_squared_to distance_squared_to(to: Vector2)

返回向量b的平方距离。 如果您需要对向量进行排序或某些公式需要平方距离,则应优先使用此函数,而不要使用[distance_to]。


  • distance_to distance_to(to: Vector2)

返回到向量b的距离。


  • dot dot(with: Vector2)

返回带有向量b的点积。


  • floor floor()

返回所有分量均四舍五入的向量。


  • is_equal_approx is_equal_approx(v: Vector2)

如果此向量和v大致相等,则通过在每个组件上运行[@],返回true


  • is_normalized is_normalized()

如果向量归一化,则返回true


  • length length()

返回向量的长度。


  • length_squared length_squared()

返回向量的长度平方。 如果您需要对向量进行排序或某些公式需要平方长度,则最好使用此方法优先于[方法长度]。


  • linear_interpolate linear_interpolate(b: Vector2, t: float)

返回此向量和b之间线性插值的结果,数量为tt0.0-1.0的范围内,表示内插量。


  • move_toward move_toward(to: Vector2, delta: float)

将向量朝to移动固定的delta数量。


  • normalized normalized()

返回缩放到单位长度的向量。


  • posmod posmod(mod: float)

返回一个由该向量的组件的fposmodmod组成的向量。


  • posmodv posmodv(modv: Vector2)

返回一个由该向量的fposmod组件和modv的组件组成的向量。


  • project project(b: Vector2)

返回投影到向量b上的向量。


  • reflect reflect(n: Vector2)

返回从给定法线定义的平面反射的向量。


  • rotated rotated(phi: float)

返回以phi弧度旋转的向量。


  • round round()

返回向量,其中所有分量都四舍五入到最接近的整数,中途情况从零舍入。


  • sign sign()

返回矢量,每个矢量设置为一个或一个负数,具体取决于这些分量的符号。


  • slerp slerp(b: Vector2, t: float)

返回此向量和b之间的球面线性插值的结果,数量为tt0.0-1.0的范围内,表示内插量。

**注意:**两个向量都必须归一化。


  • slide slide(n: Vector2)

返回向量在给定法线定义的平面上的分量。


  • snapped snapped(by: Vector2)

返回捕捉到具有给定大小的网格的向量。


  • tangent tangent()

返回垂直向量。