class_quaternion.rst 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  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/master/doc/tools/make_rst.py.
  5. .. XML source: https://github.com/godotengine/godot/tree/master/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. Quaternions are similar to :ref:`Basis<class_Basis>`, which implements the matrix representation of rotations. Unlike :ref:`Basis<class_Basis>`, which stores rotation, scale, and shearing, quaternions only store rotation.
  14. Quaternions can be parametrized using both an axis-angle pair or Euler angles. Due to their compactness and the way they are stored in memory, certain operations (obtaining axis-angle and performing SLERP, in particular) are more efficient and robust against floating-point errors.
  15. \ **Note:** Quaternions need to be normalized before being used for rotation.
  16. .. note::
  17. There are notable differences when using this API with C#. See :ref:`doc_c_sharp_differences` for more information.
  18. .. rst-class:: classref-introduction-group
  19. Tutorials
  20. ---------
  21. - `Using 3D transforms <../tutorials/3d/using_transforms.html#interpolating-with-quaternions>`__
  22. - `Third Person Shooter Demo <https://godotengine.org/asset-library/asset/678>`__
  23. .. rst-class:: classref-reftable-group
  24. Properties
  25. ----------
  26. .. table::
  27. :widths: auto
  28. +---------------------------+---------------------------------------+---------+
  29. | :ref:`float<class_float>` | :ref:`w<class_Quaternion_property_w>` | ``1.0`` |
  30. +---------------------------+---------------------------------------+---------+
  31. | :ref:`float<class_float>` | :ref:`x<class_Quaternion_property_x>` | ``0.0`` |
  32. +---------------------------+---------------------------------------+---------+
  33. | :ref:`float<class_float>` | :ref:`y<class_Quaternion_property_y>` | ``0.0`` |
  34. +---------------------------+---------------------------------------+---------+
  35. | :ref:`float<class_float>` | :ref:`z<class_Quaternion_property_z>` | ``0.0`` |
  36. +---------------------------+---------------------------------------+---------+
  37. .. rst-class:: classref-reftable-group
  38. Constructors
  39. ------------
  40. .. table::
  41. :widths: auto
  42. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** **)** |
  44. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` from **)** |
  46. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Vector3<class_Vector3>` arc_from, :ref:`Vector3<class_Vector3>` arc_to **)** |
  48. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  50. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`Quaternion<class_Quaternion>` | :ref:`Quaternion<class_Quaternion_constructor_Quaternion>` **(** :ref:`Basis<class_Basis>` from **)** |
  52. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :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 **)** |
  54. +-------------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. .. rst-class:: classref-reftable-group
  56. Methods
  57. -------
  58. .. table::
  59. :widths: auto
  60. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`float<class_float>` | :ref:`angle_to<class_Quaternion_method_angle_to>` **(** :ref:`Quaternion<class_Quaternion>` to **)** |const| |
  62. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`float<class_float>` | :ref:`dot<class_Quaternion_method_dot>` **(** :ref:`Quaternion<class_Quaternion>` with **)** |const| |
  64. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Quaternion<class_Quaternion>` | :ref:`exp<class_Quaternion_method_exp>` **(** **)** |const| |
  66. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. | :ref:`Quaternion<class_Quaternion>` | :ref:`from_euler<class_Quaternion_method_from_euler>` **(** :ref:`Vector3<class_Vector3>` euler **)** |static| |
  68. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  69. | :ref:`float<class_float>` | :ref:`get_angle<class_Quaternion_method_get_angle>` **(** **)** |const| |
  70. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  71. | :ref:`Vector3<class_Vector3>` | :ref:`get_axis<class_Quaternion_method_get_axis>` **(** **)** |const| |
  72. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  73. | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Quaternion_method_get_euler>` **(** :ref:`int<class_int>` order=2 **)** |const| |
  74. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  75. | :ref:`Quaternion<class_Quaternion>` | :ref:`inverse<class_Quaternion_method_inverse>` **(** **)** |const| |
  76. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  77. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` **(** :ref:`Quaternion<class_Quaternion>` to **)** |const| |
  78. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  79. | :ref:`bool<class_bool>` | :ref:`is_finite<class_Quaternion_method_is_finite>` **(** **)** |const| |
  80. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  81. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Quaternion_method_is_normalized>` **(** **)** |const| |
  82. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  83. | :ref:`float<class_float>` | :ref:`length<class_Quaternion_method_length>` **(** **)** |const| |
  84. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  85. | :ref:`float<class_float>` | :ref:`length_squared<class_Quaternion_method_length_squared>` **(** **)** |const| |
  86. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  87. | :ref:`Quaternion<class_Quaternion>` | :ref:`log<class_Quaternion_method_log>` **(** **)** |const| |
  88. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  89. | :ref:`Quaternion<class_Quaternion>` | :ref:`normalized<class_Quaternion_method_normalized>` **(** **)** |const| |
  90. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  91. | :ref:`Quaternion<class_Quaternion>` | :ref:`slerp<class_Quaternion_method_slerp>` **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const| |
  92. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  93. | :ref:`Quaternion<class_Quaternion>` | :ref:`slerpni<class_Quaternion_method_slerpni>` **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const| |
  94. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  95. | :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| |
  96. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  97. | :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| |
  98. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  99. .. rst-class:: classref-reftable-group
  100. Operators
  101. ---------
  102. .. table::
  103. :widths: auto
  104. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  105. | :ref:`bool<class_bool>` | :ref:`operator !=<class_Quaternion_operator_neq_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  106. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  107. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_Quaternion_operator_mul_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  108. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  109. | :ref:`Vector3<class_Vector3>` | :ref:`operator *<class_Quaternion_operator_mul_Vector3>` **(** :ref:`Vector3<class_Vector3>` right **)** |
  110. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  111. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_Quaternion_operator_mul_float>` **(** :ref:`float<class_float>` right **)** |
  112. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  113. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator *<class_Quaternion_operator_mul_int>` **(** :ref:`int<class_int>` right **)** |
  114. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  115. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator +<class_Quaternion_operator_sum_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  116. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  117. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator -<class_Quaternion_operator_dif_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  118. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  119. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator /<class_Quaternion_operator_div_float>` **(** :ref:`float<class_float>` right **)** |
  120. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  121. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator /<class_Quaternion_operator_div_int>` **(** :ref:`int<class_int>` right **)** |
  122. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  123. | :ref:`bool<class_bool>` | :ref:`operator ==<class_Quaternion_operator_eq_Quaternion>` **(** :ref:`Quaternion<class_Quaternion>` right **)** |
  124. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  125. | :ref:`float<class_float>` | :ref:`operator []<class_Quaternion_operator_idx_int>` **(** :ref:`int<class_int>` index **)** |
  126. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  127. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator unary+<class_Quaternion_operator_unplus>` **(** **)** |
  128. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  129. | :ref:`Quaternion<class_Quaternion>` | :ref:`operator unary-<class_Quaternion_operator_unminus>` **(** **)** |
  130. +-------------------------------------+--------------------------------------------------------------------------------------------------------------------+
  131. .. rst-class:: classref-section-separator
  132. ----
  133. .. rst-class:: classref-descriptions-group
  134. Constants
  135. ---------
  136. .. _class_Quaternion_constant_IDENTITY:
  137. .. rst-class:: classref-constant
  138. **IDENTITY** = ``Quaternion(0, 0, 0, 1)``
  139. The identity quaternion, representing no rotation. Equivalent to an identity :ref:`Basis<class_Basis>` matrix. If a vector is transformed by an identity quaternion, it will not change.
  140. .. rst-class:: classref-section-separator
  141. ----
  142. .. rst-class:: classref-descriptions-group
  143. Property Descriptions
  144. ---------------------
  145. .. _class_Quaternion_property_w:
  146. .. rst-class:: classref-property
  147. :ref:`float<class_float>` **w** = ``1.0``
  148. W component of the quaternion (real part).
  149. Quaternion components should usually not be manipulated directly.
  150. .. rst-class:: classref-item-separator
  151. ----
  152. .. _class_Quaternion_property_x:
  153. .. rst-class:: classref-property
  154. :ref:`float<class_float>` **x** = ``0.0``
  155. X component of the quaternion (imaginary ``i`` axis part).
  156. Quaternion components should usually not be manipulated directly.
  157. .. rst-class:: classref-item-separator
  158. ----
  159. .. _class_Quaternion_property_y:
  160. .. rst-class:: classref-property
  161. :ref:`float<class_float>` **y** = ``0.0``
  162. Y component of the quaternion (imaginary ``j`` axis part).
  163. Quaternion components should usually not be manipulated directly.
  164. .. rst-class:: classref-item-separator
  165. ----
  166. .. _class_Quaternion_property_z:
  167. .. rst-class:: classref-property
  168. :ref:`float<class_float>` **z** = ``0.0``
  169. Z component of the quaternion (imaginary ``k`` axis part).
  170. Quaternion components should usually not be manipulated directly.
  171. .. rst-class:: classref-section-separator
  172. ----
  173. .. rst-class:: classref-descriptions-group
  174. Constructor Descriptions
  175. ------------------------
  176. .. _class_Quaternion_constructor_Quaternion:
  177. .. rst-class:: classref-constructor
  178. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** **)**
  179. Constructs a default-initialized quaternion with all components set to ``0``.
  180. .. rst-class:: classref-item-separator
  181. ----
  182. .. rst-class:: classref-constructor
  183. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Quaternion<class_Quaternion>` from **)**
  184. Constructs a **Quaternion** as a copy of the given **Quaternion**.
  185. .. rst-class:: classref-item-separator
  186. ----
  187. .. rst-class:: classref-constructor
  188. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Vector3<class_Vector3>` arc_from, :ref:`Vector3<class_Vector3>` arc_to **)**
  189. Constructs a quaternion representing the shortest arc between two points on the surface of a sphere with a radius of ``1.0``.
  190. .. rst-class:: classref-item-separator
  191. ----
  192. .. rst-class:: classref-constructor
  193. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  194. Constructs a quaternion that will rotate around the given axis by the specified angle. The axis must be a normalized vector.
  195. .. rst-class:: classref-item-separator
  196. ----
  197. .. rst-class:: classref-constructor
  198. :ref:`Quaternion<class_Quaternion>` **Quaternion** **(** :ref:`Basis<class_Basis>` from **)**
  199. Constructs a quaternion from the given :ref:`Basis<class_Basis>`.
  200. .. rst-class:: classref-item-separator
  201. ----
  202. .. rst-class:: classref-constructor
  203. :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 **)**
  204. Constructs a quaternion defined by the given values.
  205. .. rst-class:: classref-section-separator
  206. ----
  207. .. rst-class:: classref-descriptions-group
  208. Method Descriptions
  209. -------------------
  210. .. _class_Quaternion_method_angle_to:
  211. .. rst-class:: classref-method
  212. :ref:`float<class_float>` **angle_to** **(** :ref:`Quaternion<class_Quaternion>` to **)** |const|
  213. 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.
  214. \ **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.
  215. .. rst-class:: classref-item-separator
  216. ----
  217. .. _class_Quaternion_method_dot:
  218. .. rst-class:: classref-method
  219. :ref:`float<class_float>` **dot** **(** :ref:`Quaternion<class_Quaternion>` with **)** |const|
  220. Returns the dot product of two quaternions.
  221. .. rst-class:: classref-item-separator
  222. ----
  223. .. _class_Quaternion_method_exp:
  224. .. rst-class:: classref-method
  225. :ref:`Quaternion<class_Quaternion>` **exp** **(** **)** |const|
  226. .. container:: contribute
  227. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  228. .. rst-class:: classref-item-separator
  229. ----
  230. .. _class_Quaternion_method_from_euler:
  231. .. rst-class:: classref-method
  232. :ref:`Quaternion<class_Quaternion>` **from_euler** **(** :ref:`Vector3<class_Vector3>` euler **)** |static|
  233. Constructs a Quaternion from Euler angles in YXZ rotation order.
  234. .. rst-class:: classref-item-separator
  235. ----
  236. .. _class_Quaternion_method_get_angle:
  237. .. rst-class:: classref-method
  238. :ref:`float<class_float>` **get_angle** **(** **)** |const|
  239. .. container:: contribute
  240. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  241. .. rst-class:: classref-item-separator
  242. ----
  243. .. _class_Quaternion_method_get_axis:
  244. .. rst-class:: classref-method
  245. :ref:`Vector3<class_Vector3>` **get_axis** **(** **)** |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_euler:
  251. .. rst-class:: classref-method
  252. :ref:`Vector3<class_Vector3>` **get_euler** **(** :ref:`int<class_int>` order=2 **)** |const|
  253. Returns the quaternion's rotation in the form of Euler angles. The Euler order depends on the ``order`` parameter, for example using the YXZ convention: since this method decomposes, first Z, then X, and Y last. See the :ref:`EulerOrder<enum_@GlobalScope_EulerOrder>` enum for possible values. The returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
  254. .. rst-class:: classref-item-separator
  255. ----
  256. .. _class_Quaternion_method_inverse:
  257. .. rst-class:: classref-method
  258. :ref:`Quaternion<class_Quaternion>` **inverse** **(** **)** |const|
  259. Returns the inverse of the quaternion.
  260. .. rst-class:: classref-item-separator
  261. ----
  262. .. _class_Quaternion_method_is_equal_approx:
  263. .. rst-class:: classref-method
  264. :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Quaternion<class_Quaternion>` to **)** |const|
  265. 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.
  266. .. rst-class:: classref-item-separator
  267. ----
  268. .. _class_Quaternion_method_is_finite:
  269. .. rst-class:: classref-method
  270. :ref:`bool<class_bool>` **is_finite** **(** **)** |const|
  271. Returns ``true`` if this quaternion is finite, by calling :ref:`@GlobalScope.is_finite<class_@GlobalScope_method_is_finite>` on each component.
  272. .. rst-class:: classref-item-separator
  273. ----
  274. .. _class_Quaternion_method_is_normalized:
  275. .. rst-class:: classref-method
  276. :ref:`bool<class_bool>` **is_normalized** **(** **)** |const|
  277. Returns whether the quaternion is normalized or not.
  278. .. rst-class:: classref-item-separator
  279. ----
  280. .. _class_Quaternion_method_length:
  281. .. rst-class:: classref-method
  282. :ref:`float<class_float>` **length** **(** **)** |const|
  283. Returns the length of the quaternion.
  284. .. rst-class:: classref-item-separator
  285. ----
  286. .. _class_Quaternion_method_length_squared:
  287. .. rst-class:: classref-method
  288. :ref:`float<class_float>` **length_squared** **(** **)** |const|
  289. Returns the length of the quaternion, squared.
  290. .. rst-class:: classref-item-separator
  291. ----
  292. .. _class_Quaternion_method_log:
  293. .. rst-class:: classref-method
  294. :ref:`Quaternion<class_Quaternion>` **log** **(** **)** |const|
  295. .. container:: contribute
  296. There is currently no description for this method. Please help us by :ref:`contributing one <doc_updating_the_class_reference>`!
  297. .. rst-class:: classref-item-separator
  298. ----
  299. .. _class_Quaternion_method_normalized:
  300. .. rst-class:: classref-method
  301. :ref:`Quaternion<class_Quaternion>` **normalized** **(** **)** |const|
  302. Returns a copy of the quaternion, normalized to unit length.
  303. .. rst-class:: classref-item-separator
  304. ----
  305. .. _class_Quaternion_method_slerp:
  306. .. rst-class:: classref-method
  307. :ref:`Quaternion<class_Quaternion>` **slerp** **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const|
  308. Returns the result of the spherical linear interpolation between this quaternion and ``to`` by amount ``weight``.
  309. \ **Note:** Both quaternions must be normalized.
  310. .. rst-class:: classref-item-separator
  311. ----
  312. .. _class_Quaternion_method_slerpni:
  313. .. rst-class:: classref-method
  314. :ref:`Quaternion<class_Quaternion>` **slerpni** **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const|
  315. Returns the result of the spherical linear interpolation between this quaternion and ``to`` by amount ``weight``, but without checking if the rotation path is not bigger than 90 degrees.
  316. .. rst-class:: classref-item-separator
  317. ----
  318. .. _class_Quaternion_method_spherical_cubic_interpolate:
  319. .. rst-class:: classref-method
  320. :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|
  321. Performs a spherical cubic interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
  322. .. rst-class:: classref-item-separator
  323. ----
  324. .. _class_Quaternion_method_spherical_cubic_interpolate_in_time:
  325. .. rst-class:: classref-method
  326. :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|
  327. Performs a spherical cubic interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
  328. It can perform smoother interpolation than :ref:`spherical_cubic_interpolate<class_Quaternion_method_spherical_cubic_interpolate>` by the time values.
  329. .. rst-class:: classref-section-separator
  330. ----
  331. .. rst-class:: classref-descriptions-group
  332. Operator Descriptions
  333. ---------------------
  334. .. _class_Quaternion_operator_neq_Quaternion:
  335. .. rst-class:: classref-operator
  336. :ref:`bool<class_bool>` **operator !=** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  337. Returns ``true`` if the quaternions are not equal.
  338. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` instead, which is more reliable.
  339. .. rst-class:: classref-item-separator
  340. ----
  341. .. _class_Quaternion_operator_mul_Quaternion:
  342. .. rst-class:: classref-operator
  343. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  344. Composes these two quaternions by multiplying them together. This has the effect of rotating the second quaternion (the child) by the first quaternion (the parent).
  345. .. rst-class:: classref-item-separator
  346. ----
  347. .. _class_Quaternion_operator_mul_Vector3:
  348. .. rst-class:: classref-operator
  349. :ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
  350. Rotates (multiplies) the :ref:`Vector3<class_Vector3>` by the given **Quaternion**.
  351. .. rst-class:: classref-item-separator
  352. ----
  353. .. _class_Quaternion_operator_mul_float:
  354. .. rst-class:: classref-operator
  355. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`float<class_float>` right **)**
  356. Multiplies each component of the **Quaternion** by the given value. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  357. .. rst-class:: classref-item-separator
  358. ----
  359. .. _class_Quaternion_operator_mul_int:
  360. .. rst-class:: classref-operator
  361. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`int<class_int>` right **)**
  362. Multiplies each component of the **Quaternion** by the given value. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  363. .. rst-class:: classref-item-separator
  364. ----
  365. .. _class_Quaternion_operator_sum_Quaternion:
  366. .. rst-class:: classref-operator
  367. :ref:`Quaternion<class_Quaternion>` **operator +** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  368. Adds each component of the left **Quaternion** to the right **Quaternion**. 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.
  369. .. rst-class:: classref-item-separator
  370. ----
  371. .. _class_Quaternion_operator_dif_Quaternion:
  372. .. rst-class:: classref-operator
  373. :ref:`Quaternion<class_Quaternion>` **operator -** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  374. Subtracts each component of the left **Quaternion** by the right **Quaternion**. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  375. .. rst-class:: classref-item-separator
  376. ----
  377. .. _class_Quaternion_operator_div_float:
  378. .. rst-class:: classref-operator
  379. :ref:`Quaternion<class_Quaternion>` **operator /** **(** :ref:`float<class_float>` right **)**
  380. Divides each component of the **Quaternion** by the given value. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  381. .. rst-class:: classref-item-separator
  382. ----
  383. .. _class_Quaternion_operator_div_int:
  384. .. rst-class:: classref-operator
  385. :ref:`Quaternion<class_Quaternion>` **operator /** **(** :ref:`int<class_int>` right **)**
  386. Divides each component of the **Quaternion** by the given value. This operation is not meaningful on its own, but it can be used as a part of a larger expression.
  387. .. rst-class:: classref-item-separator
  388. ----
  389. .. _class_Quaternion_operator_eq_Quaternion:
  390. .. rst-class:: classref-operator
  391. :ref:`bool<class_bool>` **operator ==** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  392. Returns ``true`` if the quaternions are exactly equal.
  393. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` instead, which is more reliable.
  394. .. rst-class:: classref-item-separator
  395. ----
  396. .. _class_Quaternion_operator_idx_int:
  397. .. rst-class:: classref-operator
  398. :ref:`float<class_float>` **operator []** **(** :ref:`int<class_int>` index **)**
  399. Access quaternion components using their index. ``q[0]`` is equivalent to ``q.x``, ``q[1]`` is equivalent to ``q.y``, ``q[2]`` is equivalent to ``q.z``, and ``q[3]`` is equivalent to ``q.w``.
  400. .. rst-class:: classref-item-separator
  401. ----
  402. .. _class_Quaternion_operator_unplus:
  403. .. rst-class:: classref-operator
  404. :ref:`Quaternion<class_Quaternion>` **operator unary+** **(** **)**
  405. Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable.
  406. .. rst-class:: classref-item-separator
  407. ----
  408. .. _class_Quaternion_operator_unminus:
  409. .. rst-class:: classref-operator
  410. :ref:`Quaternion<class_Quaternion>` **operator unary-** **(** **)**
  411. Returns the negative value of the **Quaternion**. This is the same as writing ``Quaternion(-q.x, -q.y, -q.z, -q.w)``. This operation results in a quaternion that represents the same rotation.
  412. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  413. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  414. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  415. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  416. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  417. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  418. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`