class_quaternion.rst 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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. Returns the exponential of this quaternion. The rotation axis of the result is the normalized rotation axis of this quaternion, the angle of the result is the length of the vector part of this quaternion.
  227. .. rst-class:: classref-item-separator
  228. ----
  229. .. _class_Quaternion_method_from_euler:
  230. .. rst-class:: classref-method
  231. :ref:`Quaternion<class_Quaternion>` **from_euler** **(** :ref:`Vector3<class_Vector3>` euler **)** |static|
  232. Constructs a Quaternion from Euler angles in YXZ rotation order.
  233. .. rst-class:: classref-item-separator
  234. ----
  235. .. _class_Quaternion_method_get_angle:
  236. .. rst-class:: classref-method
  237. :ref:`float<class_float>` **get_angle** **(** **)** |const|
  238. Returns the angle of the rotation represented by this quaternion.
  239. \ **Note:** The quaternion must be normalized.
  240. .. rst-class:: classref-item-separator
  241. ----
  242. .. _class_Quaternion_method_get_axis:
  243. .. rst-class:: classref-method
  244. :ref:`Vector3<class_Vector3>` **get_axis** **(** **)** |const|
  245. Returns the rotation axis of the rotation represented by this quaternion.
  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. Returns the logarithm of this quaternion. The vector part of the result is the rotation axis of this quaternion multiplied by its rotation angle, the real part of the result is zero.
  294. .. rst-class:: classref-item-separator
  295. ----
  296. .. _class_Quaternion_method_normalized:
  297. .. rst-class:: classref-method
  298. :ref:`Quaternion<class_Quaternion>` **normalized** **(** **)** |const|
  299. Returns a copy of the quaternion, normalized to unit length.
  300. .. rst-class:: classref-item-separator
  301. ----
  302. .. _class_Quaternion_method_slerp:
  303. .. rst-class:: classref-method
  304. :ref:`Quaternion<class_Quaternion>` **slerp** **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const|
  305. Returns the result of the spherical linear interpolation between this quaternion and ``to`` by amount ``weight``.
  306. \ **Note:** Both quaternions must be normalized.
  307. .. rst-class:: classref-item-separator
  308. ----
  309. .. _class_Quaternion_method_slerpni:
  310. .. rst-class:: classref-method
  311. :ref:`Quaternion<class_Quaternion>` **slerpni** **(** :ref:`Quaternion<class_Quaternion>` to, :ref:`float<class_float>` weight **)** |const|
  312. 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.
  313. .. rst-class:: classref-item-separator
  314. ----
  315. .. _class_Quaternion_method_spherical_cubic_interpolate:
  316. .. rst-class:: classref-method
  317. :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|
  318. Performs a spherical cubic interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
  319. .. rst-class:: classref-item-separator
  320. ----
  321. .. _class_Quaternion_method_spherical_cubic_interpolate_in_time:
  322. .. rst-class:: classref-method
  323. :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|
  324. Performs a spherical cubic interpolation between quaternions ``pre_a``, this vector, ``b``, and ``post_b``, by the given amount ``weight``.
  325. It can perform smoother interpolation than :ref:`spherical_cubic_interpolate<class_Quaternion_method_spherical_cubic_interpolate>` by the time values.
  326. .. rst-class:: classref-section-separator
  327. ----
  328. .. rst-class:: classref-descriptions-group
  329. Operator Descriptions
  330. ---------------------
  331. .. _class_Quaternion_operator_neq_Quaternion:
  332. .. rst-class:: classref-operator
  333. :ref:`bool<class_bool>` **operator !=** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  334. Returns ``true`` if the quaternions are not equal.
  335. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` instead, which is more reliable.
  336. .. rst-class:: classref-item-separator
  337. ----
  338. .. _class_Quaternion_operator_mul_Quaternion:
  339. .. rst-class:: classref-operator
  340. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  341. 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).
  342. .. rst-class:: classref-item-separator
  343. ----
  344. .. _class_Quaternion_operator_mul_Vector3:
  345. .. rst-class:: classref-operator
  346. :ref:`Vector3<class_Vector3>` **operator *** **(** :ref:`Vector3<class_Vector3>` right **)**
  347. Rotates (multiplies) the :ref:`Vector3<class_Vector3>` by the given **Quaternion**.
  348. .. rst-class:: classref-item-separator
  349. ----
  350. .. _class_Quaternion_operator_mul_float:
  351. .. rst-class:: classref-operator
  352. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`float<class_float>` right **)**
  353. 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.
  354. .. rst-class:: classref-item-separator
  355. ----
  356. .. _class_Quaternion_operator_mul_int:
  357. .. rst-class:: classref-operator
  358. :ref:`Quaternion<class_Quaternion>` **operator *** **(** :ref:`int<class_int>` right **)**
  359. 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.
  360. .. rst-class:: classref-item-separator
  361. ----
  362. .. _class_Quaternion_operator_sum_Quaternion:
  363. .. rst-class:: classref-operator
  364. :ref:`Quaternion<class_Quaternion>` **operator +** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  365. 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.
  366. .. rst-class:: classref-item-separator
  367. ----
  368. .. _class_Quaternion_operator_dif_Quaternion:
  369. .. rst-class:: classref-operator
  370. :ref:`Quaternion<class_Quaternion>` **operator -** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  371. 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.
  372. .. rst-class:: classref-item-separator
  373. ----
  374. .. _class_Quaternion_operator_div_float:
  375. .. rst-class:: classref-operator
  376. :ref:`Quaternion<class_Quaternion>` **operator /** **(** :ref:`float<class_float>` right **)**
  377. 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.
  378. .. rst-class:: classref-item-separator
  379. ----
  380. .. _class_Quaternion_operator_div_int:
  381. .. rst-class:: classref-operator
  382. :ref:`Quaternion<class_Quaternion>` **operator /** **(** :ref:`int<class_int>` right **)**
  383. 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.
  384. .. rst-class:: classref-item-separator
  385. ----
  386. .. _class_Quaternion_operator_eq_Quaternion:
  387. .. rst-class:: classref-operator
  388. :ref:`bool<class_bool>` **operator ==** **(** :ref:`Quaternion<class_Quaternion>` right **)**
  389. Returns ``true`` if the quaternions are exactly equal.
  390. \ **Note:** Due to floating-point precision errors, consider using :ref:`is_equal_approx<class_Quaternion_method_is_equal_approx>` instead, which is more reliable.
  391. .. rst-class:: classref-item-separator
  392. ----
  393. .. _class_Quaternion_operator_idx_int:
  394. .. rst-class:: classref-operator
  395. :ref:`float<class_float>` **operator []** **(** :ref:`int<class_int>` index **)**
  396. 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``.
  397. .. rst-class:: classref-item-separator
  398. ----
  399. .. _class_Quaternion_operator_unplus:
  400. .. rst-class:: classref-operator
  401. :ref:`Quaternion<class_Quaternion>` **operator unary+** **(** **)**
  402. Returns the same value as if the ``+`` was not there. Unary ``+`` does nothing, but sometimes it can make your code more readable.
  403. .. rst-class:: classref-item-separator
  404. ----
  405. .. _class_Quaternion_operator_unminus:
  406. .. rst-class:: classref-operator
  407. :ref:`Quaternion<class_Quaternion>` **operator unary-** **(** **)**
  408. 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.
  409. .. |virtual| replace:: :abbr:`virtual (This method should typically be overridden by the user to have any effect.)`
  410. .. |const| replace:: :abbr:`const (This method has no side effects. It doesn't modify any of the instance's member variables.)`
  411. .. |vararg| replace:: :abbr:`vararg (This method accepts any number of arguments after the ones described here.)`
  412. .. |constructor| replace:: :abbr:`constructor (This method is used to construct a type.)`
  413. .. |static| replace:: :abbr:`static (This method doesn't need an instance to be called, so it can be called directly using the class name.)`
  414. .. |operator| replace:: :abbr:`operator (This method describes a valid operator to use with this type as left-hand operand.)`
  415. .. |bitfield| replace:: :abbr:`BitField (This value is an integer composed as a bitmask of the following flags.)`