class_quaternion.rst 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. :github_url: hide
  2. .. DO NOT EDIT THIS FILE!!!
  3. .. Generated automatically from Godot engine sources.
  4. .. Generator: https://github.com/godotengine/godot/tree/4.1/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/4.1/doc/classes/Quaternion.xml.
  6. .. _class_Quaternion:
  7. Quaternion
  8. ==========
  9. A unit quaternion used for representing 3D rotations.
  10. .. rst-class:: classref-introduction-group
  11. Description
  12. -----------
  13. The **Quaternion** built-in :ref:`Variant<class_Variant>` type is a 4D data structure that represents rotation in the form of a `Hamilton convention quaternion <https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation>`__. Compared to the :ref:`Basis<class_Basis>` type which can store both rotation and scale, quaternions can *only* store rotation.
  14. A **Quaternion** is composed by 4 floating-point components: :ref:`w<class_Quaternion_property_w>`, :ref:`x<class_Quaternion_property_x>`, :ref:`y<class_Quaternion_property_y>`, and :ref:`z<class_Quaternion_property_z>`. These components are very compact in memory, and because of this some operations are more efficient and less likely to cause floating-point errors. Methods such as :ref:`get_angle<class_Quaternion_method_get_angle>`, :ref:`get_axis<class_Quaternion_method_get_axis>`, and :ref:`slerp<class_Quaternion_method_slerp>` are faster than their :ref:`Basis<class_Basis>` counterparts.
  15. For a great introduction to quaternions, see `this video by 3Blue1Brown <https://www.youtube.com/watch?v=d4EgbgTm0Bg>`__. You do not need to know the math behind quaternions, as Godot provides several helper methods that handle it for you. These include :ref:`slerp<class_Quaternion_method_slerp>` and :ref:`spherical_cubic_interpolate<class_Quaternion_method_spherical_cubic_interpolate>`, as well as the ``*`` operator.
  16. \ **Note:** Quaternions must be normalized before being used for rotation (see :ref:`normalized<class_Quaternion_method_normalized>`).
  17. \ **Note:** Similarly to :ref:`Vector2<class_Vector2>` and :ref:`Vector3<class_Vector3>`, the components of a quaternion use 32-bit precision by default, unlike :ref:`float<class_float>` which is always 64-bit. If double precision is needed, compile the engine with the option ``precision=double``.
  18. .. rst-class:: classref-introduction-group
  19. Tutorials
  20. ---------
  21. - `3Blue1Brown's video on Quaternions <https://www.youtube.com/watch?v=d4EgbgTm0Bg>`__
  22. - `Online Quaternion Visualization <https://quaternions.online/>`__
  23. - `Using 3D transforms <../tutorials/3d/using_transforms.html#interpolating-with-quaternions>`__
  24. - `Third Person Shooter Demo <https://godotengine.org/asset-library/asset/678>`__
  25. - `Advanced Quaternion Visualization <https://iwatake2222.github.io/rotation_master/rotation_master.html>`__
  26. .. rst-class:: classref-reftable-group
  27. Properties
  28. ----------
  29. .. table::
  30. :widths: auto
  31. +---------------------------+---------------------------------------+---------+
  32. | :ref:`float<class_float>` | :ref:`w<class_Quaternion_property_w>` | ``1.0`` |
  33. +---------------------------+---------------------------------------+---------+
  34. | :ref:`float<class_float>` | :ref:`x<class_Quaternion_property_x>` | ``0.0`` |
  35. +---------------------------+---------------------------------------+---------+
  36. | :ref:`float<class_float>` | :ref:`y<class_Quaternion_property_y>` | ``0.0`` |
  37. +---------------------------+---------------------------------------+---------+
  38. | :ref:`float<class_float>` | :ref:`z<class_Quaternion_property_z>` | ``0.0`` |
  39. +---------------------------+---------------------------------------+---------+
  40. .. rst-class:: classref-reftable-group
  41. Constructors
  42. ------------
  43. .. table::
  44. :widths: auto
  45. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  46. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** **)** |
  47. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  48. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` from **)** |
  49. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  50. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Vector3<class_Vector3>` arc_from, :ref:`Vector3<class_Vector3>` arc_to **)** |
  51. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  52. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  53. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  54. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Basis<class_Basis>` from **)** |
  55. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  56. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)** |
  57. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  58. .. rst-class:: classref-reftable-group
  59. Methods
  60. -------
  61. .. table::
  62. :widths: auto
  63. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  64. | :ref:`float<class_float>` | :ref:`angle_to<class_Quaternion_method_angle_to>` **(** :ref:`Quaternion<class_Quaternion>` to **)** |const| |
  65. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  66. | :ref:`float<class_float>` | :ref:`dot<class_Quaternion_method_dot>` **(** :ref:`Quaternion<class_Quaternion>` with **)** |const| |
  67. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  68. | :ref:`Quaternion<class_Quaternion>` | :ref:`exp<class_Quaternion_method_exp>` **(** **)** |const| |
  69. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  70. | :ref:`Quaternion<class_Quaternion>` | :ref:`from_euler<class_Quaternion_method_from_euler>` **(** :ref:`Vector3<class_Vector3>` euler **)** |static| |
  71. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  72. | :ref:`float<class_float>` | :ref:`get_angle<class_Quaternion_method_get_angle>` **(** **)** |const| |
  73. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  74. | :ref:`Vector3<class_Vector3>` | :ref:`get_axis<class_Quaternion_method_get_axis>` **(** **)** |const| |
  75. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  76. | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Quaternion_method_get_euler>` **(** :ref:`int<class_int>` order=2 **)** |const| |
  77. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  78. | :ref:`Quaternion<class_Quaternion>` | :ref:`inverse<class_Quaternion_method_inverse>` **(** **)** |const| |
  79. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  80. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` **(** :ref:`Quaternion<class_Quaternion>` to **)** |const| |
  81. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  82. | :ref:`bool<class_bool>` | :ref:`is_finite<class_Quaternion_method_is_finite>` **(** **)** |const| |
  83. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  84. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Quaternion_method_is_normalized>` **(** **)** |const| |
  85. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  86. | :ref:`float<class_float>` | :ref:`length<class_Quaternion_method_length>` **(** **)** |const| |
  87. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  88. | :ref:`float<class_float>` | :ref:`length_squared<class_Quaternion_method_length_squared>` **(** **)** |const| |
  89. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  90. | :ref:`Quaternion<class_Quaternion>` | :ref:`log<class_Quaternion_method_log>` **(** **)** |const| |
  91. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  92. | :ref:`Quaternion<class_Quaternion>` | :ref:`normalized<class_Quaternion_method_normalized>` **(** **)** |const| |
  93. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  94. | :ref:`Quaternion<class_Quaternion>` | :ref:`slerp<class_Quaternion_method_slerp>` **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const| |
  95. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  96. | :ref:`Quaternion<class_Quaternion>` | :ref:`slerpni<class_Quaternion_method_slerpni>` **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const| |
  97. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  98. | :ref:`Quaternion<class_Quaternion>` | :ref:`spherical_cubic_interpolate<class_Quaternion_method_spherical_cubic_interpolate>` **(** :ref:`Quaternion<class_Quaternion>` b, :ref:`Quaternion<class_Quaternion>` pre_a, :ref:`Quaternion<class_Quaternion>` post_b, :ref:`float<class_float>` weight **)** |const| |
  99. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  100. | :ref:`Quaternion<class_Quaternion>` | :ref:`spherical_cubic_interpolate_in_time<class_Quaternion_method_spherical_cubic_interpolate_in_time>` **(** :ref:`Quaternion<class_Quaternion>` b, :ref:`Quaternion<class_Quaternion>` pre_a, :ref:`Quaternion<class_Quaternion>` post_b, :ref:`float<class_float>` weight, :ref:`float<class_float>` b_t, :ref:`float<class_float>` pre_a_t, :ref:`float<class_float>` post_b_t **)** |const| |
  101. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  102. .. rst-class:: classref-reftable-group
  103. Operators
  104. ---------
  105. .. table::
  106. :widths: auto
  107. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  108. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Quaternion_operator_neq_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  109. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  110. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_Quaternion_operator_mul_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  111. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  112. | :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_Quaternion_operator_mul_Vector3>` **(** :ref:`Vector3<class_Vector3>` right **)** |
  113. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  114. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_Quaternion_operator_mul_float>` **(** :ref:`float<class_float>` right **)** |
  115. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  116. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_Quaternion_operator_mul_int>` **(** :ref:`int<class_int>` right **)** |
  117. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  118. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator +<class_Quaternion_operator_sum_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  119. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  120. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator -<class_Quaternion_operator_dif_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  121. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  122. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator /<class_Quaternion_operator_div_float>` **(** :ref:`float<class_float>` right **)** |
  123. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  124. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator /<class_Quaternion_operator_div_int>` **(** :ref:`int<class_int>` right **)** |
  125. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  126. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Quaternion_operator_eq_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  127. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  128. | :ref:`float<class_float>` | :ref:`operator []<class_Quaternion_operator_idx_int>` **(** :ref:`int<class_int>` index **)** |
  129. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  130. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator unary+<class_Quaternion_operator_unplus>` **(** **)** |
  131. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  132. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator unary-<class_Quaternion_operator_unminus>` **(** **)** |
  133. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  134. .. rst-class:: classref-section-separator
  135. ----
  136. .. rst-class:: classref-descriptions-group
  137. Constants
  138. ---------
  139. .. _class_Quaternion_constant_IDENTITY:
  140. .. rst-class:: classref-constant
  141. **IDENTITY** = ``Quaternion(0, 0, 0, 1)``
  142. The identity quaternion, representing no rotation. This has the same rotation as :ref:`Basis.IDENTITY<class_Basis_constant_IDENTITY>`.
  143. If a :ref:`Vector3<class_Vector3>` is rotated (multiplied) by this quaternion, it does not change.
  144. .. rst-class:: classref-section-separator
  145. ----
  146. .. rst-class:: classref-descriptions-group
  147. Property Descriptions
  148. ---------------------
  149. .. _class_Quaternion_property_w:
  150. .. rst-class:: classref-property
  151. :ref:`float<class_float>` **w** = ``1.0``
  152. W component of the quaternion. This is the "real" part.
  153. \ **Note:** Quaternion components should usually not be manipulated directly.
  154. .. rst-class:: classref-item-separator
  155. ----
  156. .. _class_Quaternion_property_x:
  157. .. rst-class:: classref-property
  158. :ref:`float<class_float>` **x** = ``0.0``
  159. X component of the quaternion. This is the value along the "imaginary" ``i`` axis.
  160. \ **Note:** Quaternion components should usually not be manipulated directly.
  161. .. rst-class:: classref-item-separator
  162. ----
  163. .. _class_Quaternion_property_y:
  164. .. rst-class:: classref-property
  165. :ref:`float<class_float>` **y** = ``0.0``
  166. Y component of the quaternion. This is the value along the "imaginary" ``j`` axis.
  167. \ **Note:** Quaternion components should usually not be manipulated directly.
  168. .. rst-class:: classref-item-separator
  169. ----
  170. .. _class_Quaternion_property_z:
  171. .. rst-class:: classref-property
  172. :ref:`float<class_float>` **z** = ``0.0``
  173. Z component of the quaternion. This is the value along the "imaginary" ``k`` axis.
  174. \ **Note:** Quaternion components should usually not be manipulated directly.
  175. .. rst-class:: classref-section-separator
  176. ----
  177. .. rst-class:: classref-descriptions-group
  178. Constructor Descriptions
  179. ------------------------
  180. .. _class_Quaternion_constructor_Quaternion:
  181. .. rst-class:: classref-constructor
  182. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** **)**
  183. Constructs a **Quaternion** identical to the :ref:`IDENTITY<class_Quaternion_constant_IDENTITY>`.
  184. .. rst-class:: classref-item-separator
  185. ----
  186. .. rst-class:: classref-constructor
  187. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Quaternion<class_Quaternion>` from **)**
  188. Constructs a **Quaternion** as a copy of the given **Quaternion**.
  189. .. rst-class:: classref-item-separator
  190. ----
  191. .. rst-class:: classref-constructor
  192. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Vector3<class_Vector3>` arc_from, :ref:`Vector3<class_Vector3>` arc_to **)**
  193. Constructs a **Quaternion** representing the shortest arc between ``arc_from`` and ``arc_to``. These can be imagined as two points intersecting a sphere's surface, with a radius of ``1.0``.
  194. .. rst-class:: classref-item-separator
  195. ----
  196. .. rst-class:: classref-constructor
  197. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  198. Constructs a **Quaternion** representing rotation around the ``axis`` by the given ``angle``, in radians. The axis must be a normalized vector.
  199. .. rst-class:: classref-item-separator
  200. ----
  201. .. rst-class:: classref-constructor
  202. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Basis<class_Basis>` from **)**
  203. Constructs a **Quaternion** from the given rotation :ref:`Basis<class_Basis>`.
  204. This constructor is faster than :ref:`Basis.get_rotation_quaternion<class_Basis_method_get_rotation_quaternion>`, but the given basis must be *orthonormalized* (see :ref:`Basis.orthonormalized<class_Basis_method_orthonormalized>`). Otherwise, the constructor fails and returns :ref:`IDENTITY<class_Quaternion_constant_IDENTITY>`.
  205. .. rst-class:: classref-item-separator
  206. ----
  207. .. rst-class:: classref-constructor
  208. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)**
  209. Constructs a **Quaternion** defined by the given values.
  210. \ **Note:** Only normalized quaternions represent rotation; if these values are not normalized, the new **Quaternion** will not be a valid rotation.
  211. .. rst-class:: classref-section-separator
  212. ----
  213. .. rst-class:: classref-descriptions-group
  214. Method Descriptions
  215. -------------------
  216. .. _class_Quaternion_method_angle_to:
  217. .. rst-class:: classref-method
  218. :ref:`float<class_float>` **angle_to** **(** :ref:`Quaternion<class_Quaternion>` to **)** |const|
  219. Returns the angle between this quaternion and ``to``. This is the magnitude of the angle you would need to rotate by to get from one to the other.
  220. \ **Note:** The magnitude of the floating-point error for this method is abnormally high, so methods such as ``is_zero_approx`` will not work reliably.
  221. .. rst-class:: classref-item-separator
  222. ----
  223. .. _class_Quaternion_method_dot:
  224. .. rst-class:: classref-method
  225. :ref:`float<class_float>` **dot** **(** :ref:`Quaternion<class_Quaternion>` with **)** |const|
  226. Returns the dot product between this quaternion and ``with``.
  227. This is equivalent to ``(quat.x * with.x) + (quat.y * with.y) + (quat.z * with.z) + (quat.w * with.w)``.
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_Quaternion_method_exp:
  231. .. rst-class:: classref-method
  232. :ref:`Quaternion<class_Quaternion>` **exp** **(** **)** |const|
  233. .. container:: contribute
  234. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  235. .. rst-class:: classref-item-separator
  236. ----
  237. .. _class_Quaternion_method_from_euler:
  238. .. rst-class:: classref-method
  239. :ref:`Quaternion<class_Quaternion>` **from_euler** **(** :ref:`Vector3<class_Vector3>` euler **)** |static|
  240. Constructs a new **Quaternion** from the given :ref:`Vector3<class_Vector3>` of `Euler angles <https://en.wikipedia.org/wiki/Euler_angles>`__, in radians. This method always uses the YXZ convention (:ref:`@GlobalScope.EULER_ORDER_YXZ<class_@GlobalScope_constant_EULER_ORDER_YXZ>`).
  241. .. rst-class:: classref-item-separator
  242. ----
  243. .. _class_Quaternion_method_get_angle:
  244. .. rst-class:: classref-method
  245. :ref:`float<class_float>` **get_angle** **(** **)** |const|
  246. .. container:: contribute
  247. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  248. .. rst-class:: classref-item-separator
  249. ----
  250. .. _class_Quaternion_method_get_axis:
  251. .. rst-class:: classref-method
  252. :ref:`Vector3<class_Vector3>` **get_axis** **(** **)** |const|
  253. .. container:: contribute
  254. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  255. .. rst-class:: classref-item-separator
  256. ----
  257. .. _class_Quaternion_method_get_euler:
  258. .. rst-class:: classref-method
  259. :ref:`Vector3<class_Vector3>` **get_euler** **(** :ref:`int<class_int>` order=2 **)** |const|
  260. Returns this quaternion's rotation as a :ref:`Vector3<class_Vector3>` of `Euler angles <https://en.wikipedia.org/wiki/Euler_angles>`__, in radians.
  261. The order of each consecutive rotation can be changed with ``order`` (see :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` constants). By default, the YXZ convention is used (:ref:`@GlobalScope.EULER_ORDER_YXZ<class_@GlobalScope_constant_EULER_ORDER_YXZ>`): Z (roll) is calculated first, then X (pitch), and lastly Y (yaw). When using the opposite method :ref:`from_euler<class_Quaternion_method_from_euler>`, this order is reversed.
  262. .. rst-class:: classref-item-separator
  263. ----
  264. .. _class_Quaternion_method_inverse:
  265. .. rst-class:: classref-method
  266. :ref:`Quaternion<class_Quaternion>` **inverse** **(** **)** |const|
  267. Returns the inverse version of this quaternion, inverting the sign of every component except :ref:`w<class_Quaternion_property_w>`.
  268. .. rst-class:: classref-item-separator
  269. ----
  270. .. _class_Quaternion_method_is_equal_approx:
  271. .. rst-class:: classref-method
  272. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Quaternion<class_Quaternion>` to **)** |const|
  273. Returns ``true`` if this quaternion and ``to`` are approximately equal, by running :ref:`@GlobalScope.is_equal_approx<class_@GlobalScope_method_is_equal_approx>` on each component.
  274. .. rst-class:: classref-item-separator
  275. ----
  276. .. _class_Quaternion_method_is_finite:
  277. .. rst-class:: classref-method
  278. :ref:`bool<class_bool>` **is_finite** **(** **)** |const|
  279. Returns ``true`` if this quaternion is finite, by calling :ref:`@GlobalScope.is_finite<class_@GlobalScope_method_is_finite>` on each component.
  280. .. rst-class:: classref-item-separator
  281. ----
  282. .. _class_Quaternion_method_is_normalized:
  283. .. rst-class:: classref-method
  284. :ref:`bool<class_bool>` **is_normalized** **(** **)** |const|
  285. Returns ``true`` if this quaternion is normalized. See also :ref:`normalized<class_Quaternion_method_normalized>`.
  286. .. rst-class:: classref-item-separator
  287. ----
  288. .. _class_Quaternion_method_length:
  289. .. rst-class:: classref-method
  290. :ref:`float<class_float>` **length** **(** **)** |const|
  291. Returns this quaternion's length, also called magnitude.
  292. .. rst-class:: classref-item-separator
  293. ----
  294. .. _class_Quaternion_method_length_squared:
  295. .. rst-class:: classref-method
  296. :ref:`float<class_float>` **length_squared** **(** **)** |const|
  297. Returns this quaternion's length, squared.
  298. \ **Note:** This method is faster than :ref:`length<class_Quaternion_method_length>`, so prefer it if you only need to compare quaternion lengths.
  299. .. rst-class:: classref-item-separator
  300. ----
  301. .. _class_Quaternion_method_log:
  302. .. rst-class:: classref-method
  303. :ref:`Quaternion<class_Quaternion>` **log** **(** **)** |const|
  304. Returns the logarithm of this quaternion. Multiplies this quaternion's rotation axis by its rotation angle, and stores the result in the returned quaternion's vector part (:ref:`x<class_Quaternion_property_x>`, :ref:`y<class_Quaternion_property_y>`, and :ref:`z<class_Quaternion_property_z>`). The returned quaternion's real part (:ref:`w<class_Quaternion_property_w>`) is always ``0.0``.
  305. .. rst-class:: classref-item-separator
  306. ----
  307. .. _class_Quaternion_method_normalized:
  308. .. rst-class:: classref-method
  309. :ref:`Quaternion<class_Quaternion>` **normalized** **(** **)** |const|
  310. Returns a copy of this quaternion, normalized so that its length is ``1.0``. See also :ref:`is_normalized<class_Quaternion_method_is_normalized>`.
  311. .. rst-class:: classref-item-separator
  312. ----
  313. .. _class_Quaternion_method_slerp:
  314. .. rst-class:: classref-method
  315. :ref:`Quaternion<class_Quaternion>` **slerp** **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const|
  316. Performs a spherical-linear interpolation with the ``to`` quaternion, given a ``weight`` and returns the result. Both this quaternion and ``to`` must be normalized.
  317. .. rst-class:: classref-item-separator
  318. ----
  319. .. _class_Quaternion_method_slerpni:
  320. .. rst-class:: classref-method
  321. :ref:`Quaternion<class_Quaternion>` **slerpni** **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const|
  322. Performs a spherical-linear interpolation with the ``to`` quaternion, given a ``weight`` and returns the result. Unlike :ref:`slerp<class_Quaternion_method_slerp>`, this method does not check if the rotation path is smaller than 90 degrees. Both this quaternion and ``to`` must be normalized.
  323. .. rst-class:: classref-item-separator
  324. ----
  325. .. _class_Quaternion_method_spherical_cubic_interpolate:
  326. .. rst-class:: classref-method
  327. :ref:`Quaternion<class_Quaternion>` **spherical_cubic_interpolate** **(** :ref:`Quaternion<class_Quaternion>` b, :ref:`Quaternion<class_Quaternion>` pre_a, :ref:`Quaternion<class_Quaternion>` post_b, :ref:`float<class_float>` weight **)** |const|
  328. Performs a spherical cubic interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
  329. .. rst-class:: classref-item-separator
  330. ----
  331. .. _class_Quaternion_method_spherical_cubic_interpolate_in_time:
  332. .. rst-class:: classref-method
  333. :ref:`Quaternion<class_Quaternion>` **spherical_cubic_interpolate_in_time** **(** :ref:`Quaternion<class_Quaternion>` b, :ref:`Quaternion<class_Quaternion>` pre_a, :ref:`Quaternion<class_Quaternion>` post_b, :ref:`float<class_float>` weight, :ref:`float<class_float>` b_t, :ref:`float<class_float>` pre_a_t, :ref:`float<class_float>` post_b_t **)** |const|
  334. Performs a spherical cubic interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
  335. It can perform smoother interpolation than ``spherical_cubic_interpolate()`` by the time values.
  336. .. rst-class:: classref-section-separator
  337. ----
  338. .. rst-class:: classref-descriptions-group
  339. Operator Descriptions
  340. ---------------------
  341. .. _class_Quaternion_operator_neq_Quaternion:
  342. .. rst-class:: classref-operator
  343. :ref:`bool<class_bool>` **operator !=** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  344. Returns ``true`` if the components of both quaternions are not exactly equal.
  345. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` instead, which is more reliable.
  346. .. rst-class:: classref-item-separator
  347. ----
  348. .. _class_Quaternion_operator_mul_Quaternion:
  349. .. rst-class:: classref-operator
  350. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  351. Composes (multiplies) two quaternions. This rotates the ``right`` quaternion (the child) by this quaternion (the parent).
  352. .. rst-class:: classref-item-separator
  353. ----
  354. .. _class_Quaternion_operator_mul_Vector3:
  355. .. rst-class:: classref-operator
  356. :ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
  357. Rotates (multiplies) the ``right`` vector by this quaternion, returning a :ref:`Vector3<class_Vector3>`.
  358. .. rst-class:: classref-item-separator
  359. ----
  360. .. _class_Quaternion_operator_mul_float:
  361. .. rst-class:: classref-operator
  362. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`float<class_float>` right **)**
  363. Multiplies each component of the **Quaternion** by the right :ref:`float<class_float>` value.
  364. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  365. .. rst-class:: classref-item-separator
  366. ----
  367. .. _class_Quaternion_operator_mul_int:
  368. .. rst-class:: classref-operator
  369. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`int<class_int>` right **)**
  370. Multiplies each component of the **Quaternion** by the right :ref:`int<class_int>` value.
  371. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  372. .. rst-class:: classref-item-separator
  373. ----
  374. .. _class_Quaternion_operator_sum_Quaternion:
  375. .. rst-class:: classref-operator
  376. :ref:`Quaternion<class_Quaternion>` **operator +** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  377. Adds each component of the left **Quaternion** to the right **Quaternion**.
  378. This operation is not meaningful on its own, but it can be used as a part of a larger expression, such as approximating an intermediate rotation between two nearby rotations.
  379. .. rst-class:: classref-item-separator
  380. ----
  381. .. _class_Quaternion_operator_dif_Quaternion:
  382. .. rst-class:: classref-operator
  383. :ref:`Quaternion<class_Quaternion>` **operator -** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  384. Subtracts each component of the left **Quaternion** by the right **Quaternion**.
  385. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  386. .. rst-class:: classref-item-separator
  387. ----
  388. .. _class_Quaternion_operator_div_float:
  389. .. rst-class:: classref-operator
  390. :ref:`Quaternion<class_Quaternion>` **operator /** **(** :ref:`float<class_float>` right **)**
  391. Divides each component of the **Quaternion** by the right :ref:`float<class_float>` value.
  392. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  393. .. rst-class:: classref-item-separator
  394. ----
  395. .. _class_Quaternion_operator_div_int:
  396. .. rst-class:: classref-operator
  397. :ref:`Quaternion<class_Quaternion>` **operator /** **(** :ref:`int<class_int>` right **)**
  398. Divides each component of the **Quaternion** by the right :ref:`int<class_int>` value.
  399. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  400. .. rst-class:: classref-item-separator
  401. ----
  402. .. _class_Quaternion_operator_eq_Quaternion:
  403. .. rst-class:: classref-operator
  404. :ref:`bool<class_bool>` **operator ==** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  405. Returns ``true`` if the components of both quaternions are exactly equal.
  406. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` instead, which is more reliable.
  407. .. rst-class:: classref-item-separator
  408. ----
  409. .. _class_Quaternion_operator_idx_int:
  410. .. rst-class:: classref-operator
  411. :ref:`float<class_float>` **operator []** **(** :ref:`int<class_int>` index **)**
  412. Accesses each component of this quaternion by their index.
  413. Index ``0`` is the same as :ref:`x<class_Quaternion_property_x>`, index ``1`` is the same as :ref:`y<class_Quaternion_property_y>`, index ``2`` is the same as :ref:`z<class_Quaternion_property_z>`, and index ``3`` is the same as :ref:`w<class_Quaternion_property_w>`.
  414. .. rst-class:: classref-item-separator
  415. ----
  416. .. _class_Quaternion_operator_unplus:
  417. .. rst-class:: classref-operator
  418. :ref:`Quaternion<class_Quaternion>` **operator unary+** **(** **)**
  419. Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable.
  420. .. rst-class:: classref-item-separator
  421. ----
  422. .. _class_Quaternion_operator_unminus:
  423. .. rst-class:: classref-operator
  424. :ref:`Quaternion<class_Quaternion>` **operator unary-** **(** **)**
  425. Returns the negative value of the **Quaternion**. This is the same as multiplying all components by ``-1``. This operation results in a quaternion that represents the same rotation.
  426. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  427. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  428. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  429. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  430. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  431. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  432. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`