Vector4¶
使用浮点坐标的4D向量。
描述¶
一种4元素结构,可用于表示4D坐标或任何其他四元数值。
它使用浮点坐标。默认情况下,这些浮点值使用32位精度,与始终为64位的float不同。如果需要双精度,请使用选项精度=双编译引擎。
有关其整数对应项,请参见Vector4i。
注意:在布尔上下文中,如果Vector4等于Vector4(0,0,0,0),则Vector4将评估为false。否则,Vector4将始终评估为true。
属性¶
构造函数¶
方法¶
abs() const |
|
ceil() const |
|
cubic_interpolate(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float) const |
|
cubic_interpolate_in_time(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float, b_t: float, pre_a_t: float, post_b_t: float) const |
|
direction_to(to: Vector4) const |
|
distance_squared_to(to: Vector4) const |
|
distance_to(to: Vector4) const |
|
floor() const |
|
inverse() const |
|
is_equal_approx(to: Vector4) const |
|
is_finite() const |
|
is_normalized() const |
|
is_zero_approx() const |
|
length() const |
|
length_squared() const |
|
max_axis_index() const |
|
min_axis_index() const |
|
normalized() const |
|
round() const |
|
sign() const |
|
运算符¶
operator !=(right: Vector4) |
|
operator *(right: Projection) |
|
operator *(right: Vector4) |
|
operator *(right: float) |
|
operator *(right: int) |
|
operator +(right: Vector4) |
|
operator -(right: Vector4) |
|
operator /(right: Vector4) |
|
operator /(right: float) |
|
operator /(right: int) |
|
operator <(right: Vector4) |
|
operator <=(right: Vector4) |
|
operator ==(right: Vector4) |
|
operator >(right: Vector4) |
|
operator >=(right: Vector4) |
|
operator [](index: int) |
|
枚举¶
enum Axis: 🔗
Axis AXIS_X = 0
X轴的枚举值。由max_axis_index()和min_axis_index()返回。
Axis AXIS_Y = 1
Y轴的枚举值。由max_axis_index()和min_axis_index()返回。
Axis AXIS_Z = 2
Z轴的枚举值。由max_axis_index()和min_axis_index()返回。
Axis AXIS_W = 3
W轴的枚举值。由max_axis_index()和min_axis_index()返回。
常量¶
ZERO = Vector4(0, 0, 0, 0) 🔗
零向量,所有分量都设置为0的向量。
ONE = Vector4(1, 1, 1, 1) 🔗
一个向量,所有分量都设置为1的向量。
INF = Vector4(inf, inf, inf, inf) 🔗
无穷大向量,所有分量都设置为@S3Script.INF的向量。
属性说明¶
向量的W分量。也可以使用索引位置[3]访问。
向量的X分量。也可以使用索引位置[0]访问。
向量的Y分量。也可以使用索引位置[1]访问。
向量的Z分量。也可以使用索引位置[2]访问。
构造函数说明¶
构造一个默认初始化的Vector4,所有组件都设置为0。
Vector4 Vector4(from: Vector4)
构造一个Vector4作为给定Vector4的副本。
Vector4 Vector4(from: Vector4i)
从给定的Vector4i构造一个新的Vector4。
Vector4 Vector4(x: float, y: float, z: float, w: float)
返回具有给定组件的Vector4。
方法说明¶
返回一个新向量,其中所有分量都为绝对值(即正)。
返回一个新向量,所有分量都四舍五入(朝向正无穷大)。
Vector4 clamp(min: Vector4, max: Vector4) const 🔗
通过在每个组件上运行@GlobalScope.clamp(),返回一个新向量,其中所有组件都夹在min和max的组件之间。
Vector4 clampf(min: float, max: float) const 🔗
通过在每个组件上运行@GlobalScope.clamp(),返回一个新向量,其中所有组件都夹在min和max之间。
Vector4 cubic_interpolate(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float) const 🔗
使用pre_a和post_b作为句柄,在此向量和b之间执行三次插值,并返回位置weight处的结果。weight在0.0到1.0的范围内,表示插值量。
Vector4 cubic_interpolate_in_time(b: Vector4, pre_a: Vector4, post_b: Vector4, weight: float, b_t: float, pre_a_t: float, post_b_t: float) const 🔗
使用pre_a和post_b作为句柄,在此向量和b之间执行三次插值,并返回位置weight处的结果。weight在0.0到1.0的范围内,表示插值量。
它可以通过时间值执行比cubic_interpolate()更平滑的插值。
Vector4 direction_to(to: Vector4) const 🔗
返回从该向量指向to的规范化向量。这等效于使用(b-a)。规范化()。
float distance_squared_to(to: Vector4) const 🔗
返回此向量与to之间的平方距离。
此方法比distance_to()运行得更快,因此如果您需要比较向量或需要某些公式的平方距离,则更喜欢它。
float distance_to(to: Vector4) const 🔗
返回此向量与to之间的距离。
float dot(with: Vector4) const 🔗
返回此向量和with的点积。
返回一个新向量,所有分量都向下舍入(朝向负无穷大)。
返回向量的逆。这与Vector4(1.0/v. x,1.0/v.y,1.0/v.z,1.0/v.w)相同。
bool is_equal_approx(to: Vector4) const 🔗
如果此向量和to近似相等,则返回true,方法是在每个组件上运行@GlobalScope.is_equal_approx()。
如果此向量是有限的,则返回true,方法是在每个组件上调用@GlobalScope.is_finite()。
如果向量被归一化,即其长度约等于1,则返回true。
如果此向量的值近似为零,则通过在每个组件上运行@GlobalScope.is_zero_approx()返回true。
这种方法比使用一个值作为零向量的is_equal_approx()更快。
返回此向量的长度(大小)。
float length_squared() const 🔗
返回此向量的平方长度(平方幅度)。
此方法比length()运行得更快,因此如果您需要比较向量或需要某些公式的平方距离,则更喜欢它。
Vector4 lerp(to: Vector4, weight: float) const 🔗
返回此向量与to之间按数量weight进行线性插值的结果。weight在0.0到1.0的范围内,表示插值量。
Vector4 max(with: Vector4) const 🔗
返回this和with的组件最大值,相当于Vector4(maxf(x, with.x),maxf(y,with.y),maxf(z,with.z),maxf(w,with.w))。
返回向量最高值的轴。请参见AXIS_*常量。如果所有分量相等,则此方法返回AXIS_X。
Vector4 maxf(with: float) const 🔗
返回this和with的组件最大值,相当于Vector4(maxf(x, with),maxf(y,with),maxf(z,with),maxf(w,with))。
Vector4 min(with: Vector4) const 🔗
返回this和with的组件最小值,相当于Vector4(minf(x, with.x),minf(y,with.y),minf(z,with.z),minf(w,with.w))。
返回向量最低值的轴。请参见AXIS_*常量。如果所有分量相等,则此方法返回AXIS_W。
Vector4 minf(with: float) const 🔗
返回this和with的组件最小值,相当于Vector4(minf(x, with),minf(y,with),minf(z,with),minf(w,with))。
返回将向量缩放到单位长度的结果。等效于v/v. long()。如果v.long()==0,则返回(0,0,0,0)。另请参见is_normalized()。
注意:如果输入向量长度接近零,此函数可能会返回不正确的值。
Vector4 posmod(mod: float) const 🔗
返回由该向量的组件的@GlobalScope.fposmod()和mod组成的向量。
Vector4 posmodv(modv: Vector4) const 🔗
返回由该向量的组件的@GlobalScope.fposmod()和modv的组件组成的向量。
返回一个新向量,其中所有分量四舍五入到最接近的整数,其中一半情况从零四舍五入。
返回一个新向量,如果每个组件为正,则将每个组件设置为1.0,如果为负,则将-1.0,如果为零,则将0.0。结果与在每个组件上调用@GlobalScope.sign()相同。
Vector4 snapped(step: Vector4) const 🔗
返回一个新向量,其中每个组件都捕捉到step中相应组件的最接近倍数。这也可用于将组件四舍五入到任意数量的小数。
Vector4 snappedf(step: float) const 🔗
返回一个新向量,其中每个组件都捕捉到step的最接近倍数。这也可用于将组件四舍五入到任意数量的小数。
运算符说明¶
bool operator !=(right: Vector4) 🔗
如果向量不相等,则返回true。
注:由于浮点精度误差,考虑改用is_equal_approx(),这样更可靠。
注意:具有@S3Script.NAN元素的向量的行为与其他向量不同。因此,如果包含NaN,则此运算符的结果可能不准确。
Vector4 operator *(right: Projection) 🔗
将Vector4转换(乘以)给定Projection矩阵的转置。
对于通过投影的逆变换投影. inverse()*可以使用向量代替。请参阅Projection.inverse()。
Vector4 operator *(right: Vector4) 🔗
将 Vector4 的每个分量与给定的 Vector4 的分量相乘。
print(Vector4(10, 20, 30, 40) * Vector4(3, 4, 5, 6)) # Prints (30.0, 80.0, 150.0, 240.0)
Vector4 operator *(right: float) 🔗
将 Vector4 的每个分量与给定的 float 相乘
print(Vector4(10, 20, 30, 40) * 2) # Prints (20.0, 40.0, 60.0, 80.0)
Vector4 operator *(right: int) 🔗
将Vector4的每个组件乘以给定的int。
Vector4 operator +(right: Vector4) 🔗
将 Vector4 的每个分量与给定的 Vector4 的分量相加。
print(Vector4(10, 20, 30, 40) + Vector4(3, 4, 5, 6)) # Prints (13.0, 24.0, 35.0, 46.0)
Vector4 operator -(right: Vector4) 🔗
将 Vector4 的每个分量减去给定 Vector4 的分量。
print(Vector4(10, 20, 30, 40) - Vector4(3, 4, 5, 6)) # Prints (7.0, 16.0, 25.0, 34.0)
Vector4 operator /(right: Vector4) 🔗
将 Vector4 的每个分量除以给定 Vector4 的分量。
print(Vector4(10, 20, 30, 40) / Vector4(2, 5, 3, 4)) # Prints (5.0, 4.0, 10.0, 10.0)
Vector4 operator /(right: float) 🔗
将 Vector4 的每个分量除以给定的 float。
print(Vector4(10, 20, 30, 40) / 2) # Prints (5.0, 10.0, 15.0, 20.0)
Vector4 operator /(right: int) 🔗
将Vector4的每个组件除以给定的int。
bool operator <(right: Vector4) 🔗
通过首先检查左向量的X值是否小于right向量的X值来比较两个Vector4向量。如果X值完全相等,则它使用两个向量的Y值、两个向量的Z值重复此检查,然后使用W值。此运算符对于排序向量很有用。
注意:具有@S3Script.NAN元素的向量的行为与其他向量不同。因此,如果包含NaN,则此运算符的结果可能不准确。
bool operator <=(right: Vector4) 🔗
通过首先检查左向量的X值是否小于或等于right向量的X值来比较两个Vector4向量。如果X值完全相等,则它使用两个向量的Y值、两个向量的Z值重复此检查,然后使用W值。此运算符对于排序向量很有用。
注意:具有@S3Script.NAN元素的向量的行为与其他向量不同。因此,如果包含NaN,则此运算符的结果可能不准确。
bool operator ==(right: Vector4) 🔗
如果向量完全相等,则返回true。
注意:由于浮点精度误差,考虑改用is_equal_approx(),这样更可靠。
注意:具有@S3Script.NAN元素的向量的行为与其他向量不同。因此,如果包含NaN,则此运算符的结果可能不准确。
bool operator >(right: Vector4) 🔗
通过首先检查左向量的X值是否大于right向量的X值来比较两个Vector4向量。如果X值完全相等,则它使用两个向量的Y值、两个向量的Z值重复此检查,然后使用W值。此运算符对于排序向量很有用。
注意:具有@S3Script.NAN元素的向量的行为与其他向量不同。因此,如果包含NaN,则此运算符的结果可能不准确。
bool operator >=(right: Vector4) 🔗
通过首先检查左向量的X值是否大于或等于right向量的X值来比较两个Vector4向量。如果X值完全相等,则它使用两个向量的Y值、两个向量的Z值重复此检查,然后使用W值。此运算符对于排序向量很有用。
注意:具有@S3Script.NAN元素的向量的行为与其他向量不同。因此,如果包含NaN,则此运算符的结果可能不准确。
float operator [](index: int) 🔗
v[0]等价于v. x,v[1]等价于v.y,v[2]等价于v.z,v[3]等价于v.w。
返回与+不存在相同的值。一元+什么也不做,但有时它可以使您的代码更具可读性。
返回Vector4的负值。这与编写Vector4(-v. x,-v.y,-v.z,-v.w)相同。此操作在保持相同大小的同时翻转向量的方向。对于浮点数,数字零可以是正的也可以是负的。