Ë
    âQ(hü6  ã                   óh   — d dl Zd dlmZ ddlmZ d„ Zd„ Zd„ Zd„ Z	d	„ Z
d
„ Zd„ Zd„ Z G d„ d«      Zy)é    N)Úsolve_bandedé   )ÚRotationc                 ó  — t        j                  t        | «      ddf«      }| dd…df    |dd…ddf<   | dd…df   |dd…ddf<   | dd…df   |dd…ddf<   | dd…df    |dd…ddf<   | dd…df    |dd…ddf<   | dd…df   |dd…ddf<   |S )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     úf/var/www/skyplay_api_hub/venv/lib/python3.12/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   — t        j                  d| |«      S )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 aÓ(Ð(r   c           	      ó
  — t         j                  j                  | d¬«      }t        j                  |«      }|dkD  }||   }dd|z  t        j                  d|z  «      z  z
  |dz  z  ||<   | }||   }dd|dz  z  z   ||<   t        | «      }t        j                  t        | «      ddf«      }t        j                  d«      |d	d	 |d	d	xxx d|z  z  ccc |d	d	xxx |d	d	…d	d	f   t        j                  ||«      z  z  ccc |S )
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Ø	ˆd‰€BØ�3˜‘8œbŸf™f S¨2¡XÓ.Ñ.Ñ.°"°a±%Ñ7€A€d�GØˆ5€DØ	ˆd‰€BØ�U˜R ™U‘]Ñ"€A€d�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°DÓ$9Ñ9Ñ9ƒIà€Mr   c           	      ó�  — t         j                  j                  | d¬«      }t        j                  |«      }t        j                  |«      }|dkD  }||   }dt        j                  |«      z
  |dz  z  ||<   |t        j
                  |«      z
  |dz  z  ||<   | }||   }d|dz  dz  z
  ||<   d|dz  d	z  z
  ||<   t        | «      }t        j                  t        | «      ddf«      }t        j                  d«      |d
d
 |d
d
xxx |d
d
…d
d
f   |z  z  ccc |d
d
xxx |d
d
…d
d
f   t        j                  ||«      z  z  ccc |S )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   s@  € ô �9‰9�>‰>˜'¨ˆ>Ó*€DÜ	�‰�tÓ	€BÜ	�‰�tÓ	€Bà�$‰;€DØ	ˆd‰€BØ”B—F‘F˜2“J‘ "¨¡'Ñ)€B€t�HØ”R—V‘V˜B“Z‘ 2¨¡7Ñ*€B€t�Hàˆ5€DØ	ˆd‰€BØ�R˜1‘W˜r‘\Ñ!€B€t�HØ�r˜Q‘w ‘}Ñ$€B€t�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°TÓ%:Ñ:Ñ:ƒIà€Mr   c                 ó   — t         j                  j                  | d¬«      }t        j                  | |z  d¬«      }t        j                  | |«      }t        j                  | |«      }t        j                  ||«      }t        j
                  |«      }t        j
                  |«      }t        j
                  |«      }	|dkD  }
||
   }| t        j                  |«      z  dt        j                  |«      dz
  z  z
  |dz  z  ||
<   d|z  dt        j                  |«      z  z   |t        j                  |«      z  z
  |dz  z  ||
<   |t        j                  |«      z
  |dz  z  |	|
<   |
 }
||
   }d	|dz  d
z  z
  ||
<   d|dz  dz  z   ||
<   d|dz  dz  z
  |	|
<   |dd…df   }|dd…df   }|dd…df   }|	dd…df   }	|||z  ||z  z   z  |	|z  z   S )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˜BÓ
€CÜ�8‰8�K Ó$€Dä	�‰�tÓ	€BÜ	�‰�tÓ	€BÜ	�‰�tÓ	€Bà�$‰;€DØ	ˆd‰€BØ�”b—f‘f˜R“jÑ  1¬¯©¨r«
°Q©Ñ#7Ñ7¸2À¹7ÑB€B€t�HØ�R‘˜!œbŸf™f R›j™.Ñ(¨2´·±°r³
©?Ñ:¸bÀA¹gÑE€B€t�HØ”R—V‘V˜B“Z‘ 2¨¡7Ñ*€B€t�Hàˆ5€DØ	ˆd‰€BØ�b˜A‘g ‘mÑ#€B€t�HØ�r˜Q‘w ‘Ñ&€B€t�HØ�R˜1‘W˜s‘]Ñ"€B€t�Hà	ŠAˆtˆG‰€BØ	ŠAˆtˆG‰€BØ	ŠAˆtˆG‰€BØ	ŠAˆtˆG‰€Bà��b‘˜2 ™8Ñ#Ñ$ r¨D¡yÑ0Ð0r   c                 ó,   — t        t        | «      |«      S )a1  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                 ó4   — t        | |«      t        | |«      z   S )a–  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                 ó.  — t        j                  d«      }t        j                  t        | «      «      }t        j                  | t        ¬«      }|dd…df   |dd |dd|dd…ddf   z   z  z  }t        j                  | t        ¬«      }||dd |d|dd…ddf   z  z  }t        j                  |t        ¬«      }|dd…df   |dd |d|dd…ddf   z  z  }t        j                  |t        ¬«      }||dd |dd|dd…ddf   z   z  z  }t        j                  dt        |«      z  «      x}	}
t        j
                  |j                  «       |j                  «       |	f«      }t        j
                  |j                  «       |j                  «       |
f«      }t        j
                  | j                  «       |j                  «       t        j                  |d«      f«      }d}d}t        j                  ||z   dz   dt        |«      z  f«      }||||z   |z
  |f<   |S )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Ø€C‰€FØˆ1ˆzš!˜T 4˜-Ñ(Ñ(Ñ(€Cä
�-‰-˜¤Ô
%€CØ’�D�‰\€C‰€FØˆ1ˆzš!˜T 4˜-Ñ(Ñ(Ñ(€Cä
�-‰-˜¤Ô
%€CØ€C‰€FØˆ1��Jšq $¨˜}Ñ-Ñ-Ñ.Ñ.€Cä—i‘i ¤C¨£F¡
Ó+Ð+€FˆVÜ
�	‰	�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˜1‘u˜q‘y !¤c¨!£f¡*Ð-Ó.€FØ!€Fˆ1ˆq‰5�1‰9�aˆ<ÑØ€Mr   c                   ó,   — e Zd ZdZdZdZd„ Zd„ Zdd„Zy)	ÚRotationSplinea7
  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           
      ó¬  — |d   j                  «       }t        |«      }t        |«      }t        d|dd z  |dd…d d f   z  d|dd z  |dd…d d f   z  dd|d d z  d|dd  z  z   z  «      }d|d d |d d…d f   dz  z  |dd  |dd …d f   dz  z  z   z  }|dxx   d|d   z  |d   j	                  |«      z  z  cc<   |dxx   d|d   z  |d   j	                  |d   «      z  z  cc<   t        | j                  «      D ]®  }	t        ||«      }
t        |d d |
d d «      }||z
  }t        d||j                  «       «      }|j                  d	«      }t        j                  ||d d z
  «      }||d d t        j                  || j                  dt        j                  |«      z   z  k  «      sŒ® n t        ||«      }
t        j                   ||d d f«      }||
fS )
Nr   r   r   éÿÿÿÿr3   é   r4   )r5   r5   )ra   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_ratesz'RotationSpline._solve_for_angular_ratesK  s1  € Ø*¨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¸mÓLˆKÜ=Ø˜˜�˜k¨#¨2Ð.ó0ˆJà�Z‘ˆAÜ ,¨V°Q¸¿¹»	Ó BÐØ 1× 9Ñ 9¸'Ó BÐä—F‘FÐ,¨}¸S¸bÐ/AÑAÓBˆEØ!2ˆM˜#˜2ÐÜ�v‰v�e˜dŸh™h¨!¬b¯f©fÐ5FÓ.GÑ*GÑHÑHÕIÙð	ô 7°q¸-ÓHˆÜŸ	™	Ð#5°}ÀSÀbÐ7IÐ"JÓKˆà˜kÐ)Ð)r   c                 óˆ  — ddl m} |j                  rt        d«      ‚t	        |«      dk(  rt        d«      ‚t        j                  |t        ¬«      }|j                  dk7  rt        d«      ‚t	        |«      t	        |«      k7  r$t        dt	        |«      › d	t	        |«      › d
�«      ‚t        j                  |«      }t        j                  |dk  «      rt        d«      ‚|d d j                  «       |dd  z  j                  «       }||d d …d f   z  }t	        |«      dk(  r|}n| j                  |||«      \  }}|d d …d f   }t        j                  dt	        |«      dz
  df«      }d|z  ||z  z   ||z  z   |dz  z  |d<   d|z  d|z  |z  z
  ||z  z
  |dz  z  |d<   ||d<   d|d<   || _        || _         |||«      | _        y )Nr   )ÚPPolyz,`rotations` must be a sequence of rotations.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.ra   r   r3   r   r4   )Úscipy.interpolatery   ÚsingleÚ
ValueErrorr   r	   ÚasarrayÚfloatÚndimÚdiffÚanyÚinvÚ	as_rotvecrw   r    ÚtimesÚ	rotationsÚinterpolator)	rl   r„   r…   ry   rm   r#   rn   r9   Úcoeffs	            r   Ú__init__zRotationSpline.__init__l  sò  € Ý+à×ÒÜÐKÓLÐLäˆ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Ø�M 7ó*,Ñ&ˆM˜;ð ’�4�‰[ˆÜ—‘˜!œS ›Z¨!™^¨QÐ/Ó0ˆØ˜‘L 2¨Ñ#5Ñ5Ø˜;Ñ&ñ'Ø*,°©'ñ2ˆˆa‰à˜‘K ! b¡&¨=Ñ"8Ñ8Ø˜;Ñ&ñ'Ø*,°©'ñ2ˆˆa‰à ˆˆa‰Øˆˆa‰àˆŒ
Ø"ˆŒÙ! %¨Ó/ˆÕr   c                 óÀ  — |dvrt        d«      ‚t        j                  |t        ¬«      }|j                  dkD  rt        d«      ‚|j                  dk(  }t        j
                  |«      }| j                  |«      }|dk(  r{t        j                  | j                  |d¬«      }|dz  }d||dk  <   t        | j                  «      dz
  }|dz
  |||dz
  kD  <   | j                  |   t        j                  |«      z  }n]|dk(  r| j                  |d«      }t        ||«      }n9|d	k(  r2| j                  |d«      }| j                  |d	«      }	t        |||	«      }nJ ‚|r|d   }|S )
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   )
rl   r„   ÚorderÚ
singe_timer#   ÚindexÚ
n_segmentsr   r9   rC   s
             r   Ú__call__zRotationSpline.__call__š  s_  € ð$ ˜	Ñ!ÜÐ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°KÓ@‰FØ�aŠZØ×+Ñ+¨E°1Ó5ˆKØ"×/Ñ/°°qÓ9ˆOÜ2°7¸KØ3BóD‰Fð �5áØ˜A‘YˆFàˆr   N)r   )	Ú__name__Ú
__module__Ú__qualname__Ú__doc__rf   rj   rw   rˆ   r“   © r   r   r^   r^   û   s&   „ ñJðX €HØ
€Cò*òB,0ô\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Qò Qr   