mirror of
https://github.com/godotengine/godot-docs-l10n.git
synced 2025-12-31 09:49:22 +03:00
1295 lines
82 KiB
ReStructuredText
1295 lines
82 KiB
ReStructuredText
:github_url: hide
|
||
|
||
.. _class_Vector2:
|
||
|
||
Vector2
|
||
=======
|
||
|
||
使用浮点数坐标的 2D 向量。
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
描述
|
||
----
|
||
|
||
包含两个元素的结构体,可用于代表 2D 坐标或任何数值的二元组。
|
||
|
||
使用浮点数坐标。默认情况下,这些浮点值为 32 位精度,与始终为 64 位的 :ref:`float<class_float>` 并不相同。如果需要双精度,请在编译引擎时使用 ``precision=double`` 选项。
|
||
|
||
对应的整数版本见 :ref:`Vector2i<class_Vector2i>`\ 。
|
||
|
||
\ **注意:**\ 在布尔语境中,如果 Vector2 等于 ``Vector2(0, 0)`` 则求值结果为 ``false``\ 。否则 Vector2 的求值结果始终为 ``true``\ 。
|
||
|
||
.. rst-class:: classref-introduction-group
|
||
|
||
教程
|
||
----
|
||
|
||
- :doc:`数学文档索引 <../tutorials/math/index>`
|
||
|
||
- :doc:`向量数学 <../tutorials/math/vector_math>`
|
||
|
||
- :doc:`高等向量数学 <../tutorials/math/vectors_advanced>`
|
||
|
||
- `3Blue1Brown《线性代数的本质》 <https://www.youtube.com/playlist?list=PLZHQObOWTQDPD3MizzM2xVFitgF8hE_ab>`__
|
||
|
||
- `矩阵变换演示 <https://godotengine.org/asset-library/asset/2787>`__
|
||
|
||
- `所有 2D 演示 <https://github.com/godotengine/godot-demo-projects/tree/master/2d>`__
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
属性
|
||
----
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+---------------------------+------------------------------------+---------+
|
||
| :ref:`float<class_float>` | :ref:`x<class_Vector2_property_x>` | ``0.0`` |
|
||
+---------------------------+------------------------------------+---------+
|
||
| :ref:`float<class_float>` | :ref:`y<class_Vector2_property_y>` | ``0.0`` |
|
||
+---------------------------+------------------------------------+---------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
构造函数
|
||
--------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>`\ (\ ) |
|
||
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>`\ (\ from\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>`\ (\ from\: :ref:`Vector2i<class_Vector2i>`\ ) |
|
||
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`Vector2<class_Vector2_constructor_Vector2>`\ (\ x\: :ref:`float<class_float>`, y\: :ref:`float<class_float>`\ ) |
|
||
+-------------------------------+-----------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
方法
|
||
----
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`abs<class_Vector2_method_abs>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`angle<class_Vector2_method_angle>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`angle_to<class_Vector2_method_angle_to>`\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`angle_to_point<class_Vector2_method_angle_to_point>`\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`aspect<class_Vector2_method_aspect>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`bezier_derivative<class_Vector2_method_bezier_derivative>`\ (\ control_1\: :ref:`Vector2<class_Vector2>`, control_2\: :ref:`Vector2<class_Vector2>`, end\: :ref:`Vector2<class_Vector2>`, t\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`bezier_interpolate<class_Vector2_method_bezier_interpolate>`\ (\ control_1\: :ref:`Vector2<class_Vector2>`, control_2\: :ref:`Vector2<class_Vector2>`, end\: :ref:`Vector2<class_Vector2>`, t\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`bounce<class_Vector2_method_bounce>`\ (\ n\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`ceil<class_Vector2_method_ceil>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`clamp<class_Vector2_method_clamp>`\ (\ min\: :ref:`Vector2<class_Vector2>`, max\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`clampf<class_Vector2_method_clampf>`\ (\ min\: :ref:`float<class_float>`, max\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`cross<class_Vector2_method_cross>`\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`cubic_interpolate<class_Vector2_method_cubic_interpolate>`\ (\ b\: :ref:`Vector2<class_Vector2>`, pre_a\: :ref:`Vector2<class_Vector2>`, post_b\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`cubic_interpolate_in_time<class_Vector2_method_cubic_interpolate_in_time>`\ (\ b\: :ref:`Vector2<class_Vector2>`, pre_a\: :ref:`Vector2<class_Vector2>`, post_b\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`, b_t\: :ref:`float<class_float>`, pre_a_t\: :ref:`float<class_float>`, post_b_t\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`direction_to<class_Vector2_method_direction_to>`\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`distance_squared_to<class_Vector2_method_distance_squared_to>`\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`distance_to<class_Vector2_method_distance_to>`\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`dot<class_Vector2_method_dot>`\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`floor<class_Vector2_method_floor>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`from_angle<class_Vector2_method_from_angle>`\ (\ angle\: :ref:`float<class_float>`\ ) |static| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Vector2_method_is_equal_approx>`\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_finite<class_Vector2_method_is_finite>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_normalized<class_Vector2_method_is_normalized>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`is_zero_approx<class_Vector2_method_is_zero_approx>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`length<class_Vector2_method_length>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`length_squared<class_Vector2_method_length_squared>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`lerp<class_Vector2_method_lerp>`\ (\ to\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`limit_length<class_Vector2_method_limit_length>`\ (\ length\: :ref:`float<class_float>` = 1.0\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`max<class_Vector2_method_max>`\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`max_axis_index<class_Vector2_method_max_axis_index>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`maxf<class_Vector2_method_maxf>`\ (\ with\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`min<class_Vector2_method_min>`\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`int<class_int>` | :ref:`min_axis_index<class_Vector2_method_min_axis_index>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`minf<class_Vector2_method_minf>`\ (\ with\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`move_toward<class_Vector2_method_move_toward>`\ (\ to\: :ref:`Vector2<class_Vector2>`, delta\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`normalized<class_Vector2_method_normalized>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`orthogonal<class_Vector2_method_orthogonal>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`posmod<class_Vector2_method_posmod>`\ (\ mod\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`posmodv<class_Vector2_method_posmodv>`\ (\ modv\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`project<class_Vector2_method_project>`\ (\ b\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`reflect<class_Vector2_method_reflect>`\ (\ line\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`rotated<class_Vector2_method_rotated>`\ (\ angle\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`round<class_Vector2_method_round>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`sign<class_Vector2_method_sign>`\ (\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`slerp<class_Vector2_method_slerp>`\ (\ to\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`slide<class_Vector2_method_slide>`\ (\ n\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`snapped<class_Vector2_method_snapped>`\ (\ step\: :ref:`Vector2<class_Vector2>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`snappedf<class_Vector2_method_snappedf>`\ (\ step\: :ref:`float<class_float>`\ ) |const| |
|
||
+-------------------------------+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-reftable-group
|
||
|
||
运算符
|
||
------
|
||
|
||
.. table::
|
||
:widths: auto
|
||
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`operator !=<class_Vector2_operator_neq_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Transform2D>`\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator *<class_Vector2_operator_mul_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator +<class_Vector2_operator_sum_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator -<class_Vector2_operator_dif_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_float>`\ (\ right\: :ref:`float<class_float>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator /<class_Vector2_operator_div_int>`\ (\ right\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`operator \<<class_Vector2_operator_lt_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`operator \<=<class_Vector2_operator_lte_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`operator ==<class_Vector2_operator_eq_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`operator ><class_Vector2_operator_gt_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`bool<class_bool>` | :ref:`operator >=<class_Vector2_operator_gte_Vector2>`\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`float<class_float>` | :ref:`operator []<class_Vector2_operator_idx_int>`\ (\ index\: :ref:`int<class_int>`\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator unary+<class_Vector2_operator_unplus>`\ (\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
| :ref:`Vector2<class_Vector2>` | :ref:`operator unary-<class_Vector2_operator_unminus>`\ (\ ) |
|
||
+-------------------------------+----------------------------------------------------------------------------------------------------------------+
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
枚举
|
||
----
|
||
|
||
.. _enum_Vector2_Axis:
|
||
|
||
.. rst-class:: classref-enumeration
|
||
|
||
enum **Axis**: :ref:`🔗<enum_Vector2_Axis>`
|
||
|
||
.. _class_Vector2_constant_AXIS_X:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`Axis<enum_Vector2_Axis>` **AXIS_X** = ``0``
|
||
|
||
X 轴的枚举值。由 :ref:`max_axis_index()<class_Vector2_method_max_axis_index>` 和 :ref:`min_axis_index()<class_Vector2_method_min_axis_index>` 返回。
|
||
|
||
.. _class_Vector2_constant_AXIS_Y:
|
||
|
||
.. rst-class:: classref-enumeration-constant
|
||
|
||
:ref:`Axis<enum_Vector2_Axis>` **AXIS_Y** = ``1``
|
||
|
||
Y 轴的枚举值。由 :ref:`max_axis_index()<class_Vector2_method_max_axis_index>` 和 :ref:`min_axis_index()<class_Vector2_method_min_axis_index>` 返回。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
常量
|
||
----
|
||
|
||
.. _class_Vector2_constant_ZERO:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**ZERO** = ``Vector2(0, 0)`` :ref:`🔗<class_Vector2_constant_ZERO>`
|
||
|
||
零向量,所有分量都设置为 ``0`` 的向量。
|
||
|
||
.. _class_Vector2_constant_ONE:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**ONE** = ``Vector2(1, 1)`` :ref:`🔗<class_Vector2_constant_ONE>`
|
||
|
||
一向量,所有分量都设置为 ``1`` 的向量。
|
||
|
||
.. _class_Vector2_constant_INF:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**INF** = ``Vector2(inf, inf)`` :ref:`🔗<class_Vector2_constant_INF>`
|
||
|
||
无穷大向量,所有分量都设置为 :ref:`@GDScript.INF<class_@GDScript_constant_INF>` 的向量。
|
||
|
||
.. _class_Vector2_constant_LEFT:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**LEFT** = ``Vector2(-1, 0)`` :ref:`🔗<class_Vector2_constant_LEFT>`
|
||
|
||
左单位向量。代表左的方向。
|
||
|
||
.. _class_Vector2_constant_RIGHT:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**RIGHT** = ``Vector2(1, 0)`` :ref:`🔗<class_Vector2_constant_RIGHT>`
|
||
|
||
右单位向量。代表右的方向。
|
||
|
||
.. _class_Vector2_constant_UP:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**UP** = ``Vector2(0, -1)`` :ref:`🔗<class_Vector2_constant_UP>`
|
||
|
||
上单位向量。在 2D 中 Y 是向下的,所以这个向量指向 -Y。
|
||
|
||
.. _class_Vector2_constant_DOWN:
|
||
|
||
.. rst-class:: classref-constant
|
||
|
||
**DOWN** = ``Vector2(0, 1)`` :ref:`🔗<class_Vector2_constant_DOWN>`
|
||
|
||
下单位向量。在 2D 中 Y 是向下的,所以这个向量指向 +Y。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
属性说明
|
||
--------
|
||
|
||
.. _class_Vector2_property_x:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`float<class_float>` **x** = ``0.0`` :ref:`🔗<class_Vector2_property_x>`
|
||
|
||
向量的 X 分量。也可以通过使用索引位置 ``[0]`` 访问。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_property_y:
|
||
|
||
.. rst-class:: classref-property
|
||
|
||
:ref:`float<class_float>` **y** = ``0.0`` :ref:`🔗<class_Vector2_property_y>`
|
||
|
||
向量的 Y 分量。也可以通过使用索引位置 ``[1]`` 访问。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
构造函数说明
|
||
------------
|
||
|
||
.. _class_Vector2_constructor_Vector2:
|
||
|
||
.. rst-class:: classref-constructor
|
||
|
||
:ref:`Vector2<class_Vector2>` **Vector2**\ (\ ) :ref:`🔗<class_Vector2_constructor_Vector2>`
|
||
|
||
构造默认初始化的 **Vector2**\ ,所有分量均为 ``0``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-constructor
|
||
|
||
:ref:`Vector2<class_Vector2>` **Vector2**\ (\ from\: :ref:`Vector2<class_Vector2>`\ )
|
||
|
||
构造给定 **Vector2** 的副本。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-constructor
|
||
|
||
:ref:`Vector2<class_Vector2>` **Vector2**\ (\ from\: :ref:`Vector2i<class_Vector2i>`\ )
|
||
|
||
从 :ref:`Vector2i<class_Vector2i>` 构造新的 **Vector2**\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-constructor
|
||
|
||
:ref:`Vector2<class_Vector2>` **Vector2**\ (\ x\: :ref:`float<class_float>`, y\: :ref:`float<class_float>`\ )
|
||
|
||
从给定的 ``x`` 和 ``y`` 构造新的 **Vector2**\ 。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
方法说明
|
||
--------
|
||
|
||
.. _class_Vector2_method_abs:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **abs**\ (\ ) |const| :ref:`🔗<class_Vector2_method_abs>`
|
||
|
||
返回一个新向量,其所有分量都是绝对值,即正值。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_angle:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **angle**\ (\ ) |const| :ref:`🔗<class_Vector2_method_angle>`
|
||
|
||
Returns this vector's angle with respect to the positive X axis, or ``(1, 0)`` vector, in radians.
|
||
|
||
For example, ``Vector2.RIGHT.angle()`` will return zero, ``Vector2.DOWN.angle()`` will return ``PI / 2`` (a quarter turn, or 90 degrees), and ``Vector2(1, -1).angle()`` will return ``-PI / 4`` (a negative eighth turn, or -45 degrees).
|
||
|
||
This is equivalent to calling :ref:`@GlobalScope.atan2()<class_@GlobalScope_method_atan2>` with :ref:`y<class_Vector2_property_y>` and :ref:`x<class_Vector2_property_x>`.
|
||
|
||
\ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle.png>`__
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_angle_to:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **angle_to**\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_angle_to>`
|
||
|
||
Returns the signed angle to the given vector, in radians. The result ranges from ``-PI`` to ``PI`` (inclusive).
|
||
|
||
\ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to.png>`__
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_angle_to_point:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **angle_to_point**\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_angle_to_point>`
|
||
|
||
Returns the signed angle between the X axis and the line from this vector to point ``to``, in radians. The result ranges from ``-PI`` to ``PI`` (inclusive).
|
||
|
||
\ ``a.angle_to_point(b)`` is equivalent to ``(b - a).angle()``. See also :ref:`angle()<class_Vector2_method_angle>`.
|
||
|
||
\ `Illustration of the returned angle. <https://raw.githubusercontent.com/godotengine/godot-docs/master/img/vector2_angle_to_point.png>`__
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_aspect:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **aspect**\ (\ ) |const| :ref:`🔗<class_Vector2_method_aspect>`
|
||
|
||
Returns this vector's aspect ratio, which is :ref:`x<class_Vector2_property_x>` divided by :ref:`y<class_Vector2_property_y>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_bezier_derivative:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **bezier_derivative**\ (\ control_1\: :ref:`Vector2<class_Vector2>`, control_2\: :ref:`Vector2<class_Vector2>`, end\: :ref:`Vector2<class_Vector2>`, t\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_bezier_derivative>`
|
||
|
||
返回\ `贝赛尔曲线 <https://zh.wikipedia.org/zh-cn/%E8%B2%9D%E8%8C%B2%E6%9B%B2%E7%B7%9A>`__\ 上 ``t`` 处的导数,该曲线由此向量和控制点 ``control_1``\ 、\ ``control_2``\ 、终点 ``end`` 定义。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_bezier_interpolate:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **bezier_interpolate**\ (\ control_1\: :ref:`Vector2<class_Vector2>`, control_2\: :ref:`Vector2<class_Vector2>`, end\: :ref:`Vector2<class_Vector2>`, t\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_bezier_interpolate>`
|
||
|
||
返回\ `贝赛尔曲线 <https://zh.wikipedia.org/zh-cn/%E8%B2%9D%E8%8C%B2%E6%9B%B2%E7%B7%9A>`__\ 上 ``t`` 处的点,该曲线由此向量和控制点 ``control_1``\ 、\ ``control_2``\ 、终点 ``end`` 定义。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_bounce:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **bounce**\ (\ n\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_bounce>`
|
||
|
||
返回从由给定垂直法线 ``n`` 定义的线“反弹”的向量。
|
||
|
||
\ **注意:** :ref:`bounce()<class_Vector2_method_bounce>` 执行大多数引擎和框架调用 ``reflect()`` 的操作。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_ceil:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **ceil**\ (\ ) |const| :ref:`🔗<class_Vector2_method_ceil>`
|
||
|
||
返回一个新向量,所有的分量都是向上舍入(正无穷大方向)。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_clamp:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **clamp**\ (\ min\: :ref:`Vector2<class_Vector2>`, max\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_clamp>`
|
||
|
||
返回一个新向量,每个分量都使用 :ref:`@GlobalScope.clamp()<class_@GlobalScope_method_clamp>` 限制在 ``min`` 和 ``max`` 之间。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_clampf:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **clampf**\ (\ min\: :ref:`float<class_float>`, max\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_clampf>`
|
||
|
||
返回一个新向量,每个分量都使用 :ref:`@GlobalScope.clamp()<class_@GlobalScope_method_clamp>` 限制在 ``min`` 和 ``max`` 之间。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_cross:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **cross**\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_cross>`
|
||
|
||
返回该向量和 ``with`` 的 2D 类比叉积。
|
||
|
||
这是由两个向量所形成的平行四边形的有符号面积。如果第二个向量是从第一个向量的顺时针方向出发的,则叉积为正面积。如果是逆时针方向,则叉积为负面积。如果两个向量平行,则返回零,这对于测试两个向量是否平行很有用。
|
||
|
||
\ **注意:**\ 数学中没有定义二维空间的叉乘。此方法是将 2D 向量嵌入到 3D 空间的 XY 平面中,并使用它们的叉积的 Z 分量作为类比。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_cubic_interpolate:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **cubic_interpolate**\ (\ b\: :ref:`Vector2<class_Vector2>`, pre_a\: :ref:`Vector2<class_Vector2>`, post_b\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_cubic_interpolate>`
|
||
|
||
返回该向量和 ``b`` 之间进行三次插值 ``weight`` 处的结果,使用 ``pre_a`` 和 ``post_b`` 作为控制柄。\ ``weight`` 在 0.0 到 1.0 的范围内,代表插值的量。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_cubic_interpolate_in_time:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **cubic_interpolate_in_time**\ (\ b\: :ref:`Vector2<class_Vector2>`, pre_a\: :ref:`Vector2<class_Vector2>`, post_b\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`, b_t\: :ref:`float<class_float>`, pre_a_t\: :ref:`float<class_float>`, post_b_t\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_cubic_interpolate_in_time>`
|
||
|
||
返回该向量和 ``b`` 之间进行三次插值 ``weight`` 处的结果,使用 ``pre_a`` 和 ``post_b`` 作为控制柄。\ ``weight`` 在 0.0 到 1.0 的范围内,代表插值的量。
|
||
|
||
通过使用时间值,可以比 :ref:`cubic_interpolate()<class_Vector2_method_cubic_interpolate>` 进行更平滑的插值。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_direction_to:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **direction_to**\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_direction_to>`
|
||
|
||
Returns the normalized vector pointing from this vector to ``to``.
|
||
|
||
\ ``a.direction_to(b)`` is equivalent to ``(b - a).normalized()``. See also :ref:`normalized()<class_Vector2_method_normalized>`.
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_distance_squared_to:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **distance_squared_to**\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_distance_squared_to>`
|
||
|
||
返回该向量与 ``to`` 之间的距离的平方。
|
||
|
||
该方法比 :ref:`distance_to()<class_Vector2_method_distance_to>` 运行得更快,因此请在需要比较向量或者用于某些公式的平方距离时,优先使用这个方法。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_distance_to:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **distance_to**\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_distance_to>`
|
||
|
||
返回该向量与 ``to`` 之间的距离。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_dot:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **dot**\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_dot>`
|
||
|
||
返回该向量与 ``with`` 的点积。可用于比较两个向量之间的夹角。例如,可用于确定敌人是否面向玩家。
|
||
|
||
直角(90 度)的点积为 ``0``\ ;大于 0 则夹角小于 90 度;小于 0 则夹角大于 90 度。
|
||
|
||
使用(归一化的)单位向量时,如果向量朝向相反,则结果始终为 ``-1.0``\ (180 度角);如果向量方向一致,则结果始终为 ``1.0``\ (0 度角)。
|
||
|
||
\ **注意:**\ ``a.dot(b)`` 等价于 ``b.dot(a)``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_floor:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **floor**\ (\ ) |const| :ref:`🔗<class_Vector2_method_floor>`
|
||
|
||
返回一个新的向量,所有的向量都被四舍五入,向负无穷大。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_from_angle:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **from_angle**\ (\ angle\: :ref:`float<class_float>`\ ) |static| :ref:`🔗<class_Vector2_method_from_angle>`
|
||
|
||
创建旋转至 ``angle`` 角度的 **Vector2**\ ,旋转单位为弧度。相当于执行 ``Vector2(cos(angle), sin(angle))`` 或 ``Vector2.RIGHT.rotated(angle)``\ 。
|
||
|
||
::
|
||
|
||
print(Vector2.from_angle(0)) # 输出 (1.0, 0.0)
|
||
print(Vector2(1, 0).angle()) # 输出 0.0,即上一行所使用的角度。
|
||
print(Vector2.from_angle(PI / 2)) # 输出 (0.0, 1.0)
|
||
|
||
\ **注意:**\ 返回的 **Vector2** 的长度\ *约等于* ``1.0``\ ,由于浮点数精度问题,不保证精确等于 ``1.0``\ 。如果需要单位向量,请调用返回的 **Vector2** 的 :ref:`normalized()<class_Vector2_method_normalized>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_is_equal_approx:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_equal_approx**\ (\ to\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_is_equal_approx>`
|
||
|
||
如果这个向量与 ``to`` 大致相等,则返回 ``true``\ ,判断方法是对每个分量执行 :ref:`@GlobalScope.is_equal_approx()<class_@GlobalScope_method_is_equal_approx>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_is_finite:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_finite**\ (\ ) |const| :ref:`🔗<class_Vector2_method_is_finite>`
|
||
|
||
如果该向量无穷,则返回 ``true``\ ,判断方法是对每个分量调用 :ref:`@GlobalScope.is_finite()<class_@GlobalScope_method_is_finite>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_is_normalized:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_normalized**\ (\ ) |const| :ref:`🔗<class_Vector2_method_is_normalized>`
|
||
|
||
如果该向量是归一化的,即长度约等于 1,则返回 ``true``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_is_zero_approx:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`bool<class_bool>` **is_zero_approx**\ (\ ) |const| :ref:`🔗<class_Vector2_method_is_zero_approx>`
|
||
|
||
如果该向量的值大约为零,则返回 ``true``\ ,判断方法是对每个分量运行 :ref:`@GlobalScope.is_zero_approx()<class_@GlobalScope_method_is_zero_approx>`\ 。
|
||
|
||
该方法比使用 :ref:`is_equal_approx()<class_Vector2_method_is_equal_approx>` 和零向量比较要快。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_length:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **length**\ (\ ) |const| :ref:`🔗<class_Vector2_method_length>`
|
||
|
||
返回这个向量的长度,即大小。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_length_squared:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`float<class_float>` **length_squared**\ (\ ) |const| :ref:`🔗<class_Vector2_method_length_squared>`
|
||
|
||
返回这个向量的平方长度,即平方大小。
|
||
|
||
这个方法比 :ref:`length()<class_Vector2_method_length>` 运行得更快,所以如果你需要比较向量或需要一些公式的平方距离时,更喜欢用它。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_lerp:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **lerp**\ (\ to\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_lerp>`
|
||
|
||
返回此向量和 ``to`` 之间,按数量 ``weight`` 线性插值结果。\ ``weight`` 在 ``0.0`` 到 ``1.0`` 的范围内,代表插值的量。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_limit_length:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **limit_length**\ (\ length\: :ref:`float<class_float>` = 1.0\ ) |const| :ref:`🔗<class_Vector2_method_limit_length>`
|
||
|
||
返回应用了最大长度限制的向量,长度被限制到 ``length``\ 。如果向量非有限,则结果未定义。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_max:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **max**\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_max>`
|
||
|
||
返回自身与 ``with`` 各分量的最大值,等价于 ``Vector2(maxf(x, with.x), maxf(y, with.y))``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_max_axis_index:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **max_axis_index**\ (\ ) |const| :ref:`🔗<class_Vector2_method_max_axis_index>`
|
||
|
||
返回该向量中最大值的轴。见 ``AXIS_*`` 常量。如果所有分量相等,则该方法返回 :ref:`AXIS_X<class_Vector2_constant_AXIS_X>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_maxf:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **maxf**\ (\ with\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_maxf>`
|
||
|
||
返回自身与 ``with`` 各分量的最大值,等价于 ``Vector2(maxf(x, with), maxf(y, with))``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_min:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **min**\ (\ with\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_min>`
|
||
|
||
返回自身与 ``with`` 各分量的最小值,等价于 ``Vector2(minf(x, with.x), minf(y, with.y))``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_min_axis_index:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`int<class_int>` **min_axis_index**\ (\ ) |const| :ref:`🔗<class_Vector2_method_min_axis_index>`
|
||
|
||
返回该向量中最小值的轴。见 ``AXIS_*`` 常量。如果所有分量相等,则该方法返回 :ref:`AXIS_Y<class_Vector2_constant_AXIS_Y>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_minf:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **minf**\ (\ with\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_minf>`
|
||
|
||
返回自身与 ``with`` 各分量的最小值,等价于 ``Vector2(minf(x, with), minf(y, with))``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_move_toward:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **move_toward**\ (\ to\: :ref:`Vector2<class_Vector2>`, delta\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_move_toward>`
|
||
|
||
返回一个新向量,该向量朝 ``to`` 移动了固定的量 ``delta``\ 。不会超过最终值。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_normalized:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **normalized**\ (\ ) |const| :ref:`🔗<class_Vector2_method_normalized>`
|
||
|
||
返回该向量缩放至单位长度的结果。等价于 ``v / v.length()``\ 。如果 ``v.length() == 0`` 则返回 ``(0, 0)``\ 。另见 :ref:`is_normalized()<class_Vector2_method_is_normalized>`\ 。
|
||
|
||
\ **注意:**\ 如果输入向量的长度接近零,则这个函数可能返回不正确的值。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_orthogonal:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **orthogonal**\ (\ ) |const| :ref:`🔗<class_Vector2_method_orthogonal>`
|
||
|
||
返回一个与原来相比逆时针旋转 90 度的垂直向量,长度不变。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_posmod:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **posmod**\ (\ mod\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_posmod>`
|
||
|
||
返回由该向量的分量与 ``mod`` 执行 :ref:`@GlobalScope.fposmod()<class_@GlobalScope_method_fposmod>` 运算后组成的向量。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_posmodv:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **posmodv**\ (\ modv\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_posmodv>`
|
||
|
||
返回由该向量的分量与 ``modv`` 的分量执行 :ref:`@GlobalScope.fposmod()<class_@GlobalScope_method_fposmod>` 运算后组成的向量。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_project:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **project**\ (\ b\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_project>`
|
||
|
||
返回将该向量投影到给定的 ``b`` 向量上所得到的新向量。得到的新向量与 ``b`` 平行。另见 :ref:`slide()<class_Vector2_method_slide>`\ 。
|
||
|
||
\ **注意:**\ 如果 ``b`` 向量为零向量,得到的新向量的分量均为 :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_reflect:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **reflect**\ (\ line\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_reflect>`
|
||
|
||
返回从给定方向向量 ``line`` 定义的线反射向量的结果。
|
||
|
||
\ **注意:**\ :ref:`reflect()<class_Vector2_method_reflect>` 与其他引擎和框架调用的 ``reflect()`` 不同。在其他引擎中,\ ``reflect()`` 采用法线方向,即垂直于线的方向。在 Godot 中,你可以直接指定线的方向。另见 :ref:`bounce()<class_Vector2_method_bounce>`\ ,它执行大多数引擎调用的 ``reflect()``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_rotated:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **rotated**\ (\ angle\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_rotated>`
|
||
|
||
返回将这个向量旋转 ``angle`` 的结果(单位为弧度)。另见 :ref:`@GlobalScope.deg_to_rad()<class_@GlobalScope_method_deg_to_rad>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_round:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **round**\ (\ ) |const| :ref:`🔗<class_Vector2_method_round>`
|
||
|
||
返回所有分量都被四舍五入为最接近的整数的向量,中间情况向远离零的方向舍入。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_sign:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **sign**\ (\ ) |const| :ref:`🔗<class_Vector2_method_sign>`
|
||
|
||
返回新的向量,分量如果为正则设为 ``1.0``\ ,如果为负则设为 ``-1.0``\ ,如果为零则设为 ``0.0``\ 。结果与对每个分量调用 :ref:`@GlobalScope.sign()<class_@GlobalScope_method_sign>` 一致。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_slerp:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **slerp**\ (\ to\: :ref:`Vector2<class_Vector2>`, weight\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_slerp>`
|
||
|
||
返回在这个向量和 ``to`` 之间进行 ``weight`` 的球面线性插值的结果。\ ``weight`` 在 0.0 和 1.0 的范围内,代表插值的量。
|
||
|
||
如果输入向量的长度不同,这个函数也会对长度进行插值处理。对于输入向量中存在长度为零的向量的特殊情况,这个方法的行为与 :ref:`lerp()<class_Vector2_method_lerp>` 一致。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_slide:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **slide**\ (\ n\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_slide>`
|
||
|
||
返回将该向量沿着法线为 ``n`` 的直线滑动所得到的新向量。得到的新向量与 ``n`` 垂直,等价于将该向量减去在 ``n`` 上的投影。另见 :ref:`project()<class_Vector2_method_project>`\ 。
|
||
|
||
\ **注意:**\ 向量 ``n`` 必须为归一化的向量。另见 :ref:`normalized()<class_Vector2_method_normalized>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_snapped:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **snapped**\ (\ step\: :ref:`Vector2<class_Vector2>`\ ) |const| :ref:`🔗<class_Vector2_method_snapped>`
|
||
|
||
返回新的向量,每个分量都吸附到了与 ``step`` 中对应分量最接近的倍数。也可以用于将分量四舍五入至小数点后的任意位置。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_method_snappedf:
|
||
|
||
.. rst-class:: classref-method
|
||
|
||
:ref:`Vector2<class_Vector2>` **snappedf**\ (\ step\: :ref:`float<class_float>`\ ) |const| :ref:`🔗<class_Vector2_method_snappedf>`
|
||
|
||
返回一个新向量,其中每个分量都吸附到 ``step`` 的最接近的倍数。这也可以用于将分量四舍五入为任意数位的小数。
|
||
|
||
.. rst-class:: classref-section-separator
|
||
|
||
----
|
||
|
||
.. rst-class:: classref-descriptions-group
|
||
|
||
运算符说明
|
||
----------
|
||
|
||
.. _class_Vector2_operator_neq_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`bool<class_bool>` **operator !=**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_neq_Vector2>`
|
||
|
||
如果向量不相等,则返回 ``true``\ 。
|
||
|
||
\ **注意:**\ 由于浮点数精度误差,请考虑改用 :ref:`is_equal_approx()<class_Vector2_method_is_equal_approx>`\ ,会更可靠。
|
||
|
||
\ **注意:**\ 包含 :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` 元素的向量的行为与其他向量不同。因此,如果包含 NaN,则这个方法的结果可能不准确。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_mul_Transform2D:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator ***\ (\ right\: :ref:`Transform2D<class_Transform2D>`\ ) :ref:`🔗<class_Vector2_operator_mul_Transform2D>`
|
||
|
||
假设该变换的基是正交的(即旋转/反射可以,缩放/倾斜不行),将 **Vector2** 逆向变换(乘以)给定的 :ref:`Transform2D<class_Transform2D>` 变换矩阵。
|
||
|
||
\ ``vector * transform`` 相当于 ``transform.inverse() * vector``\ 。请参阅 :ref:`Transform2D.inverse()<class_Transform2D_method_inverse>`\ 。
|
||
|
||
对于通过仿射变换的逆进行的变换(例如缩放),可以使用 ``transform.affine_inverse() * vector`` 代替。请参阅 :ref:`Transform2D.affine_inverse()<class_Transform2D_method_affine_inverse>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_mul_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator ***\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_mul_Vector2>`
|
||
|
||
将该 **Vector2** 的每个分量乘以给定 **Vector2** 的对应分量。
|
||
|
||
::
|
||
|
||
print(Vector2(10, 20) * Vector2(3, 4)) # 输出 (30.0, 80.0)
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_mul_float:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator ***\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Vector2_operator_mul_float>`
|
||
|
||
将该 **Vector2** 的每个分量乘以给定的 :ref:`float<class_float>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_mul_int:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator ***\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Vector2_operator_mul_int>`
|
||
|
||
将该 **Vector2** 的每个分量乘以给定的 :ref:`int<class_int>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_sum_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator +**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_sum_Vector2>`
|
||
|
||
将该 **Vector2** 的每个分量加上给定 **Vector2** 的对应分量。
|
||
|
||
::
|
||
|
||
print(Vector2(10, 20) + Vector2(3, 4)) # 输出 (13.0, 24.0)
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_dif_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator -**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_dif_Vector2>`
|
||
|
||
将该 **Vector2** 的每个分量减去给定 **Vector2** 的对应分量。
|
||
|
||
::
|
||
|
||
print(Vector2(10, 20) - Vector2(3, 4)) # 输出 (7.0, 16.0)
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_div_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator /**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_div_Vector2>`
|
||
|
||
将该 **Vector2** 的每个分量除以给定 **Vector2** 的对应分量。
|
||
|
||
::
|
||
|
||
print(Vector2(10, 20) / Vector2(2, 5)) # 输出 (5.0, 4.0)
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_div_float:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator /**\ (\ right\: :ref:`float<class_float>`\ ) :ref:`🔗<class_Vector2_operator_div_float>`
|
||
|
||
将该 **Vector2** 的每个分量除以给定的 :ref:`float<class_float>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_div_int:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator /**\ (\ right\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Vector2_operator_div_int>`
|
||
|
||
将该 **Vector2** 的每个分量除以给定的 :ref:`int<class_int>`\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_lt_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`bool<class_bool>` **operator <**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_lt_Vector2>`
|
||
|
||
比较两个 **Vector2** 向量,首先检查左向量的 X 值是否小于 ``right`` 向量的 X 值。如果 X 值完全相等,则用相同的方法检查两个向量的 Y 值。该运算符可用于向量排序。
|
||
|
||
\ **注意:**\ 包含 :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` 元素的向量的行为与其他向量不同。因此,如果包含 NaN,则这个方法的结果可能不准确。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_lte_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`bool<class_bool>` **operator <=**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_lte_Vector2>`
|
||
|
||
比较两个 **Vector2** 向量,首先检查左向量的 X 值是否小于等于 ``right`` 向量的 X 值。如果 X 值完全相等,则用相同的方法检查两个向量的 Y 值。该运算符可用于向量排序。
|
||
|
||
\ **注意:**\ 包含 :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` 元素的向量的行为与其他向量不同。因此,如果包含 NaN,则这个方法的结果可能不准确。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_eq_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`bool<class_bool>` **operator ==**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_eq_Vector2>`
|
||
|
||
如果向量完全相等,则返回 ``true``\ 。
|
||
|
||
\ **注意:**\ 由于浮点数精度误差,请考虑改用 :ref:`is_equal_approx()<class_Vector2_method_is_equal_approx>`\ ,会更可靠。
|
||
|
||
\ **注意:**\ 包含 :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` 元素的向量的行为与其他向量不同。因此,如果包含 NaN,则这个方法的结果可能不准确。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_gt_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`bool<class_bool>` **operator >**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_gt_Vector2>`
|
||
|
||
比较两个 **Vector2** 向量,首先检查左向量的 X 值是否大于 ``right`` 向量的 X 值。如果 X 值完全相等,则用相同的方法检查两个向量的 Y 值。该运算符可用于向量排序。
|
||
|
||
\ **注意:**\ 包含 :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` 元素的向量的行为与其他向量不同。因此,如果包含 NaN,则这个方法的结果可能不准确。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_gte_Vector2:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`bool<class_bool>` **operator >=**\ (\ right\: :ref:`Vector2<class_Vector2>`\ ) :ref:`🔗<class_Vector2_operator_gte_Vector2>`
|
||
|
||
比较两个 **Vector2** 向量,首先检查左向量的 X 值是否大于等于 ``right`` 向量的 X 值。如果 X 值完全相等,则用相同的方法检查两个向量的 Y 值。该运算符可用于向量排序。
|
||
|
||
\ **注意:**\ 包含 :ref:`@GDScript.NAN<class_@GDScript_constant_NAN>` 元素的向量的行为与其他向量不同。因此,如果包含 NaN,则这个方法的结果可能不准确。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_idx_int:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`float<class_float>` **operator []**\ (\ index\: :ref:`int<class_int>`\ ) :ref:`🔗<class_Vector2_operator_idx_int>`
|
||
|
||
使用向量分量的 ``index`` 来访问向量分量。\ ``v[0]`` 等价于 ``v.x``\ 、\ ``v[1]`` 等价于 ``v.y``\ 。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_unplus:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator unary+**\ (\ ) :ref:`🔗<class_Vector2_operator_unplus>`
|
||
|
||
返回与 ``+`` 不存在时相同的值。单目 ``+`` 没有作用,但有时可以使你的代码更具可读性。
|
||
|
||
.. rst-class:: classref-item-separator
|
||
|
||
----
|
||
|
||
.. _class_Vector2_operator_unminus:
|
||
|
||
.. rst-class:: classref-operator
|
||
|
||
:ref:`Vector2<class_Vector2>` **operator unary-**\ (\ ) :ref:`🔗<class_Vector2_operator_unminus>`
|
||
|
||
返回该 **Vector2** 的负值。和写 ``Vector2(-v.x, -v.y)`` 是一样的。该操作在保持相同幅度的同时,翻转向量的方向。对于浮点数,零也有正负两种。
|
||
|
||
.. |virtual| replace:: :abbr:`virtual (本方法通常需要用户覆盖才能生效。)`
|
||
.. |required| replace:: :abbr:`required (This method is required to be overridden when extending its base class.)`
|
||
.. |const| replace:: :abbr:`const (本方法无副作用,不会修改该实例的任何成员变量。)`
|
||
.. |vararg| replace:: :abbr:`vararg (本方法除了能接受在此处描述的参数外,还能够继续接受任意数量的参数。)`
|
||
.. |constructor| replace:: :abbr:`constructor (本方法用于构造某个类型。)`
|
||
.. |static| replace:: :abbr:`static (调用本方法无需实例,可直接使用类名进行调用。)`
|
||
.. |operator| replace:: :abbr:`operator (本方法描述的是使用本类型作为左操作数的有效运算符。)`
|
||
.. |bitfield| replace:: :abbr:`BitField (这个值是由下列位标志构成位掩码的整数。)`
|
||
.. |void| replace:: :abbr:`void (无返回值。)`
|