class_quat.rst 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. :github_url: hide
  2. .. Generated automatically by doc/tools/makerst.py in Godot's source tree.
  3. .. DO NOT EDIT THIS FILE, but the Quat.xml source instead.
  4. .. The source is found in doc/classes or modules/<name>/doc_classes.
  5. .. _class_Quat:
  6. Quat
  7. ====
  8. Quaternion.
  9. Description
  10. -----------
  11. A unit quaternion used for representing 3D rotations.
  12. It is similar to :ref:`Basis<class_Basis>`, which implements matrix representation of rotations, and can be parametrized using both an axis-angle pair or Euler angles. But due to its compactness and the way it is stored in memory, certain operations (obtaining axis-angle and performing SLERP, in particular) are more efficient and robust against floating-point errors.
  13. Quaternions need to be (re)normalized.
  14. Tutorials
  15. ---------
  16. - `#interpolating-with-quaternions <../tutorials/3d/using_transforms.html#interpolating-with-quaternions>`_ in :doc:`../tutorials/3d/using_transforms`
  17. Properties
  18. ----------
  19. +---------------------------+---------------------------------+---------+
  20. | :ref:`float<class_float>` | :ref:`w<class_Quat_property_w>` | ``1.0`` |
  21. +---------------------------+---------------------------------+---------+
  22. | :ref:`float<class_float>` | :ref:`x<class_Quat_property_x>` | ``0.0`` |
  23. +---------------------------+---------------------------------+---------+
  24. | :ref:`float<class_float>` | :ref:`y<class_Quat_property_y>` | ``0.0`` |
  25. +---------------------------+---------------------------------+---------+
  26. | :ref:`float<class_float>` | :ref:`z<class_Quat_property_z>` | ``0.0`` |
  27. +---------------------------+---------------------------------+---------+
  28. Methods
  29. -------
  30. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  31. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Basis<class_Basis>` from **)** |
  32. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  33. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Vector3<class_Vector3>` euler **)** |
  34. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  35. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  36. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  37. | :ref:`Quat<class_Quat>` | :ref:`Quat<class_Quat_method_Quat>` **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)** |
  38. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  39. | :ref:`Quat<class_Quat>` | :ref:`cubic_slerp<class_Quat_method_cubic_slerp>` **(** :ref:`Quat<class_Quat>` b, :ref:`Quat<class_Quat>` pre_a, :ref:`Quat<class_Quat>` post_b, :ref:`float<class_float>` t **)** |
  40. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  41. | :ref:`float<class_float>` | :ref:`dot<class_Quat_method_dot>` **(** :ref:`Quat<class_Quat>` b **)** |
  42. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  43. | :ref:`Vector3<class_Vector3>` | :ref:`get_euler<class_Quat_method_get_euler>` **(** **)** |
  44. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  45. | :ref:`Quat<class_Quat>` | :ref:`inverse<class_Quat_method_inverse>` **(** **)** |
  46. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  47. | :ref:`bool<class_bool>` | :ref:`is_equal_approx<class_Quat_method_is_equal_approx>` **(** :ref:`Quat<class_Quat>` quat **)** |
  48. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  49. | :ref:`bool<class_bool>` | :ref:`is_normalized<class_Quat_method_is_normalized>` **(** **)** |
  50. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  51. | :ref:`float<class_float>` | :ref:`length<class_Quat_method_length>` **(** **)** |
  52. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  53. | :ref:`float<class_float>` | :ref:`length_squared<class_Quat_method_length_squared>` **(** **)** |
  54. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  55. | :ref:`Quat<class_Quat>` | :ref:`normalized<class_Quat_method_normalized>` **(** **)** |
  56. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  57. | void | :ref:`set_axis_angle<class_Quat_method_set_axis_angle>` **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)** |
  58. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  59. | void | :ref:`set_euler<class_Quat_method_set_euler>` **(** :ref:`Vector3<class_Vector3>` euler **)** |
  60. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  61. | :ref:`Quat<class_Quat>` | :ref:`slerp<class_Quat_method_slerp>` **(** :ref:`Quat<class_Quat>` b, :ref:`float<class_float>` t **)** |
  62. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  63. | :ref:`Quat<class_Quat>` | :ref:`slerpni<class_Quat_method_slerpni>` **(** :ref:`Quat<class_Quat>` b, :ref:`float<class_float>` t **)** |
  64. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  65. | :ref:`Vector3<class_Vector3>` | :ref:`xform<class_Quat_method_xform>` **(** :ref:`Vector3<class_Vector3>` v **)** |
  66. +-------------------------------+-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  67. Constants
  68. ---------
  69. .. _class_Quat_constant_IDENTITY:
  70. - **IDENTITY** = **Quat( 0, 0, 0, 1 )** --- The identity rotation. Equivalent to an identity matrix. If a vector is transformed by an identity quaternion, it will not change.
  71. Property Descriptions
  72. ---------------------
  73. .. _class_Quat_property_w:
  74. - :ref:`float<class_float>` **w**
  75. +-----------+---------+
  76. | *Default* | ``1.0`` |
  77. +-----------+---------+
  78. W component of the quaternion.
  79. ----
  80. .. _class_Quat_property_x:
  81. - :ref:`float<class_float>` **x**
  82. +-----------+---------+
  83. | *Default* | ``0.0`` |
  84. +-----------+---------+
  85. X component of the quaternion.
  86. ----
  87. .. _class_Quat_property_y:
  88. - :ref:`float<class_float>` **y**
  89. +-----------+---------+
  90. | *Default* | ``0.0`` |
  91. +-----------+---------+
  92. Y component of the quaternion.
  93. ----
  94. .. _class_Quat_property_z:
  95. - :ref:`float<class_float>` **z**
  96. +-----------+---------+
  97. | *Default* | ``0.0`` |
  98. +-----------+---------+
  99. Z component of the quaternion.
  100. Method Descriptions
  101. -------------------
  102. .. _class_Quat_method_Quat:
  103. - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Basis<class_Basis>` from **)**
  104. Returns the rotation matrix corresponding to the given quaternion.
  105. ----
  106. - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Vector3<class_Vector3>` euler **)**
  107. Returns a quaternion that will perform a rotation specified by Euler angles (in the YXZ convention: first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).
  108. ----
  109. - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  110. Returns a quaternion that will rotate around the given axis by the specified angle. The axis must be a normalized vector.
  111. ----
  112. - :ref:`Quat<class_Quat>` **Quat** **(** :ref:`float<class_float>` x, :ref:`float<class_float>` y, :ref:`float<class_float>` z, :ref:`float<class_float>` w **)**
  113. Returns a quaternion defined by these values.
  114. ----
  115. .. _class_Quat_method_cubic_slerp:
  116. - :ref:`Quat<class_Quat>` **cubic_slerp** **(** :ref:`Quat<class_Quat>` b, :ref:`Quat<class_Quat>` pre_a, :ref:`Quat<class_Quat>` post_b, :ref:`float<class_float>` t **)**
  117. Performs a cubic spherical-linear interpolation with another quaternion.
  118. ----
  119. .. _class_Quat_method_dot:
  120. - :ref:`float<class_float>` **dot** **(** :ref:`Quat<class_Quat>` b **)**
  121. Returns the dot product of two quaternions.
  122. ----
  123. .. _class_Quat_method_get_euler:
  124. - :ref:`Vector3<class_Vector3>` **get_euler** **(** **)**
  125. Returns Euler angles (in the YXZ convention: first Z, then X, and Y last) corresponding to the rotation represented by the unit quaternion. Returned vector contains the rotation angles in the format (X angle, Y angle, Z angle).
  126. ----
  127. .. _class_Quat_method_inverse:
  128. - :ref:`Quat<class_Quat>` **inverse** **(** **)**
  129. Returns the inverse of the quaternion.
  130. ----
  131. .. _class_Quat_method_is_equal_approx:
  132. - :ref:`bool<class_bool>` **is_equal_approx** **(** :ref:`Quat<class_Quat>` quat **)**
  133. Returns ``true`` if this quaterion and ``quat`` are approximately equal, by running :ref:`@GDScript.is_equal_approx<class_@GDScript_method_is_equal_approx>` on each component.
  134. ----
  135. .. _class_Quat_method_is_normalized:
  136. - :ref:`bool<class_bool>` **is_normalized** **(** **)**
  137. Returns whether the quaternion is normalized or not.
  138. ----
  139. .. _class_Quat_method_length:
  140. - :ref:`float<class_float>` **length** **(** **)**
  141. Returns the length of the quaternion.
  142. ----
  143. .. _class_Quat_method_length_squared:
  144. - :ref:`float<class_float>` **length_squared** **(** **)**
  145. Returns the length of the quaternion, squared.
  146. ----
  147. .. _class_Quat_method_normalized:
  148. - :ref:`Quat<class_Quat>` **normalized** **(** **)**
  149. Returns a copy of the quaternion, normalized to unit length.
  150. ----
  151. .. _class_Quat_method_set_axis_angle:
  152. - void **set_axis_angle** **(** :ref:`Vector3<class_Vector3>` axis, :ref:`float<class_float>` angle **)**
  153. Sets the quaternion to a rotation which rotates around axis by the specified angle, in radians. The axis must be a normalized vector.
  154. ----
  155. .. _class_Quat_method_set_euler:
  156. - void **set_euler** **(** :ref:`Vector3<class_Vector3>` euler **)**
  157. Sets the quaternion to a rotation specified by Euler angles (in the YXZ convention: first Z, then X, and Y last), given in the vector format as (X angle, Y angle, Z angle).
  158. ----
  159. .. _class_Quat_method_slerp:
  160. - :ref:`Quat<class_Quat>` **slerp** **(** :ref:`Quat<class_Quat>` b, :ref:`float<class_float>` t **)**
  161. Performs a spherical-linear interpolation with another quaternion.
  162. ----
  163. .. _class_Quat_method_slerpni:
  164. - :ref:`Quat<class_Quat>` **slerpni** **(** :ref:`Quat<class_Quat>` b, :ref:`float<class_float>` t **)**
  165. Performs a spherical-linear interpolation with another quaterion without checking if the rotation path is not bigger than 90°.
  166. ----
  167. .. _class_Quat_method_xform:
  168. - :ref:`Vector3<class_Vector3>` **xform** **(** :ref:`Vector3<class_Vector3>` v **)**
  169. Transforms the vector ``v`` by this quaternion.