ó
    Eñi¤7  ã                   óh   • S SK rS SKJr  SSKJr  S rS rS rS r	S	 r
S
 rS rS r " S S5      rg)é    N)Úsolve_bandedé   )ÚRotationc                 ó  • [         R                  " [        U 5      SS45      nU SS2S4   * USS2SS4'   U SS2S4   USS2SS4'   U SS2S4   USS2SS4'   U SS2S4   * USS2SS4'   U SS2S4   * USS2SS4'   U SS2S4   USS2SS4'   U$ )z¨Create skew-symmetric matrices corresponding to vectors.

Parameters
----------
x : ndarray, shape (n, 3)
    Set of vectors.

Returns
-------
ndarray, shape (n, 3, 3)
é   Né   r   r   )ÚnpÚzerosÚlen)ÚxÚresults     Úe/home/mande/repo/quber/.venv/lib/python3.13/site-packages/scipy/spatial/transform/_rotation_spline.pyÚ_create_skew_matrixr      s±   € ô �XŠX”s˜1“v˜q !�nÓ%€FØš˜A˜‘w�h€FŠ1ˆa�ˆ7�OØš˜1˜‘g€FŠ1ˆa�ˆ7�OØš˜1˜‘g€FŠ1ˆa�ˆ7�OØš˜A˜‘w�h€FŠ1ˆa�ˆ7�OØš˜A˜‘w�h€FŠ1ˆa�ˆ7�OØš˜1˜‘g€FŠ1ˆa�ˆ7�OØ€Mó    c                 ó0   • [         R                  " SX5      $ )z5Compute the product of stack of matrices and vectors.z
ijk,ik->ij)r	   Úeinsum)ÚAÚbs     r   Ú _matrix_vector_product_of_stacksr      s   € ä�9Š9�\ 1Ó(Ð(r   c           	      ó  • [         R                  R                  U SS9n[         R                  " U5      nUS:„  nX   nSSU-  [         R                  " SU-  5      -  -
  US-  -  X#'   U) nX   nSSUS-  -  -   X#'   [        U 5      n[         R                  " [        U 5      SS45      n[         R                  " S5      US	S	& US	S	=== SU-  -  sss& US	S	=== US	S	2S	S	4   [         R                  " XU5      -  -  sss& U$ )
a  Compute matrices to transform angular rates to rot. vector derivatives.

The matrices depend on the current attitude represented as a rotation
vector.

Parameters
----------
rotvecs : ndarray, shape (n, 3)
    Set of rotation vectors.

Returns
-------
ndarray, shape (n, 3, 3)
r   ©Úaxisç-Cëâ6?ç      à?r   çUUUUUUµ?glÁlÁV?r   N)
r	   ÚlinalgÚnormÚ
empty_likeÚtanr   Úemptyr   ÚidentityÚmatmul)Úrotvecsr   ÚkÚmaskÚnmÚskewr   s          r   Ú"_angular_rate_to_rotvec_dot_matrixr(   !   s÷   € ô �9‰9�>‰>˜'¨ˆ>Ð*€DÜ
�Š�dÓ€Aà�$‰;€DØ	‰€BØ�3˜‘8œbŸfšf S¨2¡XÓ.Ñ.Ñ.°"°a±%Ñ7€A�GØˆ5€DØ	‰€BØ�U˜R ™U‘]Ñ"€A�Gä˜wÓ'€Dä�XŠX”s˜7“| Q¨Ð*Ó+€FÜ—’˜A“€F‰1€IØ
‰1ƒI��t‘ÑƒIØ
‰1ƒI�’1�d˜D�=Ñ!¤B§I¢I¨dÓ$9Ñ9Ñ9ƒIà€Mr   c           	      óŠ  • [         R                  R                  U SS9n[         R                  " U5      n[         R                  " U5      nUS:„  nX   nS[         R                  " U5      -
  US-  -  X$'   U[         R
                  " U5      -
  US-  -  X4'   U) nX   nSUS-  S-  -
  X$'   SUS-  S	-  -
  X4'   [        U 5      n[         R                  " [        U 5      SS45      n[         R                  " S5      US
S
& US
S
=== US
S
2S
S
4   U-  -  sss& US
S
=== US
S
2S
S
4   [         R                  " Xf5      -  -  sss& U$ )a  Compute matrices to transform rot. vector derivatives to angular rates.

The matrices depend on the current attitude represented as a rotation
vector.

Parameters
----------
rotvecs : ndarray, shape (n, 3)
    Set of rotation vectors.

Returns
-------
ndarray, shape (n, 3, 3)
r   r   r   r   r   r   é   çUUUUUUÅ?éx   N)r	   r   r   r   ÚcosÚsinr   r    r   r!   r"   )r#   r   Úk1Úk2r%   r&   r'   r   s           r   Ú"_rotvec_dot_to_angular_rate_matrixr1   D   s2  € ô �9‰9�>‰>˜'¨ˆ>Ð*€DÜ	�Š�tÓ	€BÜ	�Š�tÓ	€Bà�$‰;€DØ	‰€BØ”B—F’F˜2“J‘ "¨¡'Ñ)€B�HØ”R—V’V˜B“Z‘ 2¨¡7Ñ*€B�Hàˆ5€DØ	‰€BØ�R˜1‘W˜r‘\Ñ!€B�HØ�r˜Q‘w ‘}Ñ$€B�Hä˜wÓ'€Dä�XŠX”s˜7“| Q¨Ð*Ó+€FÜ—’˜A“€F‰1€IØ
‰1ƒI�’A�t˜T�MÑ" TÑ)Ñ)ƒIØ
‰1ƒI�’A�t˜T�MÑ"¤R§Y¢Y¨tÓ%:Ñ:Ñ:ƒIà€Mr   c                 óŽ  • [         R                  R                  U SS9n[         R                  " X-  SS9n[         R                  " X5      n[         R                  " X5      n[         R                  " X5      n[         R
                  " U5      n[         R
                  " U5      n[         R
                  " U5      n	US:„  n
X*   nU* [         R                  " U5      -  S[         R                  " U5      S-
  -  -
  US-  -  Xz'   SU-  S[         R                  " U5      -  -   U[         R                  " U5      -  -
  US-  -  XŠ'   U[         R                  " U5      -
  US-  -  Xš'   U
) n
X*   nS	US-  S
-  -
  Xz'   SUS-  S-  -   XŠ'   SUS-  S-  -
  Xš'   USS2S4   nUSS2S4   nUSS2S4   nU	SS2S4   n	X7U-  X…-  -   -  X–-  -   $ )a„  Compute the non-linear term in angular acceleration.

The angular acceleration contains a quadratic term with respect to
the derivative of the rotation vector. This function computes that.

Parameters
----------
rotvecs : ndarray, shape (n, 3)
    Set of rotation vectors.
rotvecs_dot : ndarray, shape (n, 3)
    Set of rotation vector derivatives.

Returns
-------
ndarray, shape (n, 3)
r   r   r   r   é   éþÿÿÿr   é   r   é´   g‘¿i<1  r+   r,   N)r	   r   r   ÚsumÚcrossr   r.   r-   )r#   Úrotvecs_dotr   ÚdpÚcpÚccpÚdccpr/   r0   Úk3r%   r&   s               r   Ú$_angular_acceleration_nonlinear_termr?   k   s±  € ô" �9‰9�>‰>˜'¨ˆ>Ð*€DÜ	�Š�Ñ%¨AÑ	.€BÜ	�Š�'Ó	'€BÜ
�(Š(�7Ó
€CÜ�8Š8�KÓ$€Dä	�Š�tÓ	€BÜ	�Š�tÓ	€BÜ	�Š�tÓ	€Bà�$‰;€DØ	‰€BØ�”b—f’f˜R“jÑ  1¬¯ª¨r«
°Q©Ñ#7Ñ7¸2À¹7ÑB€B�HØ�R‘˜!œbŸfšf R›j™.Ñ(¨2´·²°r³
©?Ñ:¸bÀA¹gÑE€B�HØ”R—V’V˜B“Z‘ 2¨¡7Ñ*€B�Hàˆ5€DØ	‰€BØ�b˜A‘g ‘mÑ#€B�HØ�r˜Q‘w ‘Ñ&€B�HØ�R˜1‘W˜s‘]Ñ"€B�Hà	ŠAˆtˆG‰€BØ	ŠAˆtˆG‰€BØ	ŠAˆtˆG‰€BØ	ŠAˆtˆG‰€Bà�b‘˜2™8Ñ#Ñ$ r¡yÑ0Ð0r   c                 ó,   • [        [        U 5      U5      $ )a	  Compute angular rates given rotation vectors and its derivatives.

Parameters
----------
rotvecs : ndarray, shape (n, 3)
    Set of rotation vectors.
rotvecs_dot : ndarray, shape (n, 3)
    Set of rotation vector derivatives.

Returns
-------
ndarray, shape (n, 3)
)r   r1   )r#   r9   s     r   Ú_compute_angular_raterA   š   s   € ô ,Ü*¨7Ó3°[óBð Br   c                 ó0   • [        X5      [        X5      -   $ )af  Compute angular acceleration given rotation vector and its derivatives.

Parameters
----------
rotvecs : ndarray, shape (n, 3)
    Set of rotation vectors.
rotvecs_dot : ndarray, shape (n, 3)
    Set of rotation vector derivatives.
rotvecs_dot_dot : ndarray, shape (n, 3)
    Set of rotation vector second derivatives.

Returns
-------
ndarray, shape (n, 3)
)rA   r?   )r#   r9   Úrotvecs_dot_dots      r   Ú_compute_angular_accelerationrD   ¬   s    € ô  " 'Ó;Ü0°ÓFñGð Hr   c                 ó$  • [         R                  " S5      n[         R                  " [        U 5      5      n[         R                  " U [        S9nUSS2S4   USS& USSUSS2SS4   -   -  -  n[         R                  " U [        S9nX6SS& USUSS2SS4   -  -  n[         R                  " U[        S9nUSS2S4   USS& USUSS2SS4   -  -  n[         R                  " U[        S9nX8SS& USSUSS2SS4   -   -  -  n[         R                  " S[        U5      -  5      =pš[         R
                  " UR                  5       UR                  5       U	45      n[         R
                  " UR                  5       UR                  5       U
45      n[         R
                  " U R                  5       UR                  5       [         R                  " US5      45      nSnSn[         R                  " Xï-   S-   S[        U5      -  45      nUUXë-   U-
  U4'   U$ )a
  Create a 3-diagonal block matrix as banded.

The matrix has the following structure:

    DB...
    ADB..
    .ADB.
    ..ADB
    ...AD

The blocks A, B and D are 3-by-3 matrices. The D matrices has the form
d * I.

Parameters
----------
A : ndarray, shape (n, 3, 3)
    Stack of A blocks.
B : ndarray, shape (n, 3, 3)
    Stack of B blocks.
d : ndarray, shape (n + 1,)
    Values for diagonal blocks.

Returns
-------
ndarray, shape (11, 3 * (n + 1))
    Matrix in the banded form as used by `scipy.linalg.solve_banded`.
r   ©ÚdtypeNr   r5   )	r	   Úaranger   r   ÚintÚhstackÚravelÚrepeatr
   )r   ÚBÚdÚindÚ
ind_blocksÚA_iÚA_jÚB_iÚB_jÚdiag_iÚdiag_jÚiÚjÚvaluesÚuÚlr   s                    r   Ú_create_block_3_diagonal_matrixr\   À   sÏ  € ô8 �)Š)�A‹,€CÜ—’œ3˜q›6Ó"€Jä
�-Š-˜¤Ñ
%€CØ’�D�‰\€C‰€FØˆ1��Jšq $¨˜}Ñ-Ñ-Ñ.Ñ.€Cä
�-Š-˜¤Ñ
%€CØ‰€FØˆ1ˆzš!˜T 4˜-Ñ(Ñ(Ñ(€Cä
�-Š-˜¤Ñ
%€CØ’�D�‰\€C‰€FØˆ1ˆzš!˜T 4˜-Ñ(Ñ(Ñ(€Cä
�-Š-˜¤Ñ
%€CØ‰€FØˆ1��Jšq $¨˜}Ñ-Ñ-Ñ.Ñ.€Cä—i’i ¤C¨£F¡
Ó+Ð+€FÜ
�	Š	�3—9‘9“; §	¡	£¨VÐ4Ó5€AÜ
�	Š	�3—9‘9“; §	¡	£¨VÐ4Ó5€AÜ�YŠY˜Ÿ™›	 1§7¡7£9¬b¯iªi¸¸1«oÐ>Ó?€Fà	€AØ	€AÜ�XŠX�q‘u˜q‘y !¤c¨!£f¡*Ð-Ó.€FØ!€Fˆ1‰5�1‰9�aˆ<ÑØ€Mr   c                   ó6   • \ rS rSrSrSrSrS rS rS
S jr	Sr
g	)ÚRotationSplineéû   aW	  Interpolate rotations with continuous angular rate and acceleration.

The rotation vectors between each consecutive orientation are cubic
functions of time and it is guaranteed that angular rate and acceleration
are continuous. Such interpolation are analogous to cubic spline
interpolation.

Refer to [1]_ for math and implementation details.

Parameters
----------
times : array_like, shape (N,)
    Times of the known rotations. At least 2 times must be specified.
rotations : `Rotation` instance
    Rotations to perform the interpolation between. Must contain N
    rotations.

Methods
-------
__call__

References
----------
.. [1] `Smooth Attitude Interpolation
        <https://github.com/scipy/scipy/files/2932755/attitude_interpolation.pdf>`_

Examples
--------
>>> from scipy.spatial.transform import Rotation, RotationSpline
>>> import numpy as np

Define the sequence of times and rotations from the Euler angles:

>>> times = [0, 10, 20, 40]
>>> angles = [[-10, 20, 30], [0, 15, 40], [-30, 45, 30], [20, 45, 90]]
>>> rotations = Rotation.from_euler('XYZ', angles, degrees=True)

Create the interpolator object:

>>> spline = RotationSpline(times, rotations)

Interpolate the Euler angles, angular rate and acceleration:

>>> angular_rate = np.rad2deg(spline(times, 1))
>>> angular_acceleration = np.rad2deg(spline(times, 2))
>>> times_plot = np.linspace(times[0], times[-1], 100)
>>> angles_plot = spline(times_plot).as_euler('XYZ', degrees=True)
>>> angular_rate_plot = np.rad2deg(spline(times_plot, 1))
>>> angular_acceleration_plot = np.rad2deg(spline(times_plot, 2))

On this plot you see that Euler angles are continuous and smooth:

>>> import matplotlib.pyplot as plt
>>> plt.plot(times_plot, angles_plot)
>>> plt.plot(times, angles, 'x')
>>> plt.title("Euler angles")
>>> plt.show()

The angular rate is also smooth:

>>> plt.plot(times_plot, angular_rate_plot)
>>> plt.plot(times, angular_rate, 'x')
>>> plt.title("Angular rate")
>>> plt.show()

The angular acceleration is continuous, but not smooth. Also note that
the angular acceleration is not a piecewise-linear function, because
it is different from the second derivative of the rotation vector (which
is a piecewise-linear function as in the cubic spline).

>>> plt.plot(times_plot, angular_acceleration_plot)
>>> plt.plot(times, angular_acceleration, 'x')
>>> plt.title("Angular acceleration")
>>> plt.show()
é
   g•Ö&è.>c           
      ó°  • US   R                  5       n[        U5      n[        U5      n[        SUSS -  USS2S S 4   -  SUSS -  USS2S S 4   -  SSUS S -  SUSS  -  -   -  5      nSUS S US S2S 4   S-  -  USS  USS 2S 4   S-  -  -   -  nUS==   SUS   -  US   R	                  U5      -  -  ss'   US==   SUS   -  US   R	                  US   5      -  -  ss'   [        U R                  5       H±  n	[        XR5      n
[        US S U
S S 5      nX‹-
  n[        SX|R                  5       5      nUR                  S	5      n[        R                  " XÒS S -
  5      nXÒS S& [        R                  " XàR                  S[        R                  " U5      -   -  :  5      (       d  M±    O   [        XR5      n
[        R                   " XBS S 45      nX*4$ )
Nr   r   r   éÿÿÿÿr3   é   r4   )r5   r5   )rb   r   )Úcopyr(   r1   r\   ÚdotÚrangeÚMAX_ITERr   r?   r   rK   Úreshaper	   ÚabsÚallÚTOLÚvstack)ÚselfÚdtÚangular_ratesr#   Úangular_rate_firstr   ÚA_invÚMÚb0Ú	iterationr9   Ú
delta_betar   Úangular_rates_newÚdeltas                  r   Ú_solve_for_angular_ratesÚ'RotationSpline._solve_for_angular_ratesK  s  € Ø*¨1Ñ-×2Ñ2Ó4Ðä.¨wÓ7ˆÜ2°7Ó;ˆÜ+Ø��a˜�‰O˜b  2  t¨TÐ!1Ñ2Ñ2Ø��!�B�‰K˜"˜Q˜r˜T 4¨Ð-Ñ.Ñ.Ø��R˜˜�W‘˜q 2 a b 6™zÑ)Ñ*ó,ˆð
 �'˜#˜2�,  C R C¨ I¡°"Ñ!4Ñ4Ø˜!˜"�+  1¡2 t 8¡°Ñ 2Ñ2ñ3ñ 4ˆà
ˆ1‹��R˜‘U‘˜U 1™XŸ\™\Ð*<Ó=Ñ=Ñ=‹Ø
ˆ2‹�!�b˜‘f‘*˜q ™uŸy™y¨°rÑ):Ó;Ñ;Ñ;‹ä˜tŸ}™}Ö-ˆIÜ:¸1ÓLˆKÜ=Ø˜˜�˜k¨#¨2Ð.ó0ˆJà‘ˆAÜ ,¨V°Q¿¹»	Ó BÐØ 1× 9Ñ 9¸'Ó BÐä—F’FÐ,¸S¸bÐ/AÑAÓBˆEØ!2˜#˜2ÐÜ�vŠv�eŸh™h¨!¬b¯fªfÐ5FÓ.GÑ*GÑHÑH×IÓIÙñ .ô 7°qÓHˆÜŸ	š	Ð#5ÀSÀbÐ7IÐ"JÓKˆàÐ)Ð)r   c                 óä  • SSK Jn  UR                  (       a  [        S5      eUR	                  5       R
                  S:”  a  [        S5      e[        U5      S:X  a  [        S5      e[        R                  " U[        S9nUR
                  S:w  a  [        S	5      e[        U5      [        U5      :w  a$  [        S
[        U5       S[        U5       S35      e[        R                  " U5      n[        R                  " US:*  5      (       a  [        S5      eUS S R                  5       USS  -  R                  5       nXTS S 2S 4   -  n[        U5      S:X  a  UnOU R                  XFU5      u  pgUS S 2S 4   n[        R                  " S[        U5      S-
  S45      nSU-  XF-  -   XG-  -   US-  -  US'   SU-  SU-  U-  -
  XG-  -
  US-  -  US'   XhS'   SUS'   Xl        X l        U" X�5      U l        g )Nr   )ÚPPolyz,`rotations` must be a sequence of rotations.r   z?Rotations with more than 1 leading dimension are not supported.r   z.`rotations` must contain at least 2 rotations.rF   z`times` must be 1-dimensional.zLExpected number of rotations to be equal to number of timestamps given, got z rotations and z timestamps.z9Values in `times` must be in a strictly increasing order.rb   r3   r   r4   )Úscipy.interpolater{   ÚsingleÚ
ValueErrorÚas_quatÚndimr   r	   ÚasarrayÚfloatÚdiffÚanyÚinvÚ	as_rotvecrx   r    ÚtimesÚ	rotationsÚinterpolator)	rm   r‡   rˆ   r{   rn   r#   ro   r9   Úcoeffs	            r   Ú__init__ÚRotationSpline.__init__l  s	  € Ý+à××ÜÐKÓLÐLà×ÑÓ×#Ñ# aÓ'ÜØQóð ô ˆy‹>˜QÓÜÐMÓNÐNä—
’
˜5¬Ñ.ˆØ�:‰:˜‹?ÜÐ=Ó>Ð>äˆu‹:œ˜Y›Ó'Üð $ä$'¨	£NÐ#3ð 4$Ü$'¨£J <¨|ð=ó >ð >ô
 �WŠW�U‹^ˆÜ�6Š6�"˜‘'�?‰?Üð 1ó 2ð 2ð ˜S˜b�>×%Ñ%Ó'¨)°A°B¨-Ñ7×BÑBÓDˆØ¢Q¨ W¡+Ñ-ˆäˆy‹>˜QÓØ'‰Kà)-×)FÑ)FØ 7ó*,Ñ&ˆMð ’�4�‰[ˆÜ—’˜!œS ›Z¨!™^¨QÐ/Ó0ˆØ˜‘L 2Ñ#5Ñ5ØÑ&ñ'Ø*,°©'ñ2ˆˆa‰à˜‘K ! b¡&¨=Ñ"8Ñ8ØÑ&ñ'Ø*,°©'ñ2ˆˆa‰à ˆa‰Øˆˆa‰àŒ
Ø"ŒÙ! %Ó/ˆÕr   c                 óÊ  • US;  a  [        S5      e[        R                  " U[        S9nUR                  S:”  a  [        S5      eUR                  S:H  n[        R
                  " U5      nU R                  U5      nUS:X  ax  [        R                  " U R                  USS9nUS-  nSXUS:  '   [        U R                  5      S-
  nUS-
  XUUS-
  :„  '   U R                  U   [        R                  " U5      -  nO]US:X  a  U R                  US5      n[        XH5      nO9US	:X  a1  U R                  US5      nU R                  US	5      n	[        XHU	5      nO eU(       a  US   nU$ )
a~  Compute interpolated values.

Parameters
----------
times : float or array_like
    Times of interest.
order : {0, 1, 2}, optional
    Order of differentiation:

        * 0 (default) : return Rotation
        * 1 : return the angular rate in rad/sec
        * 2 : return the angular acceleration in rad/sec/sec

Returns
-------
Interpolated Rotation, angular rate or acceleration.
)r   r   r   z`order` must be 0, 1 or 2.rF   r   z&`times` must be at most 1-dimensional.r   Úright)Úsider   )r~   r	   r�   r‚   r€   Ú
atleast_1dr‰   Úsearchsortedr‡   r   rˆ   r   Úfrom_rotvecrA   rD   )
rm   r‡   ÚorderÚ
singe_timer#   ÚindexÚ
n_segmentsr   r9   rC   s
             r   Ú__call__ÚRotationSpline.__call__Ÿ  sW  € ð$ ˜	Ó!ÜÐ9Ó:Ð:ä—
’
˜5¬Ñ.ˆØ�:‰:˜‹>ÜÐEÓFÐFà—Z‘Z 1‘_ˆ
Ü—’˜eÓ$ˆà×#Ñ# EÓ*ˆØ�A‹:Ü—O’O D§J¡J°¸GÑDˆEØ�Q‰JˆEØ ˆE˜!‘)ÑÜ˜TŸZ™Z›¨1Ñ,ˆJØ,6¸©NˆE˜* q™.Ñ(Ñ)Ø—^‘^ EÑ*¬X×-AÒ-AÀ'Ó-JÑJ‰FØ�a‹ZØ×+Ñ+¨E°1Ó5ˆKÜ*¨7Ó@‰FØ�a‹ZØ×+Ñ+¨E°1Ó5ˆKØ"×/Ñ/°°qÓ9ˆOÜ2°7Ø3BóD‰Fð �5æØ˜A‘YˆFàˆr   )r‰   rˆ   r‡   N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rg   rk   rx   r‹   r—   Ú__static_attributes__© r   r   r^   r^   û   s&   † ñJðX €HØ
€Cò*òB10÷f2r   r^   )Únumpyr	   Úscipy.linalgr   Ú	_rotationr   r   r   r(   r1   r?   rA   rD   r\   r^   rŸ   r   r   Ú<module>r£      sH   ðÛ Ý %Ý òò,)ò
 òF$òN,1ò^Bò$Hò(8÷vVò Vr   