class_quaternion.rst 42 KB

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