
    wg.                         d dl mZ d dlmZ d dlmZmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZ d dlmZ d dlZ G d	 d
e      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zd Zy)    )Basic)sympify)cossin)eye	rot_axis1	rot_axis2	rot_axis3)ImmutableDenseMatrix)cacheit)StrNc                       e Zd ZdZd Zy)Orienterz/
    Super-class for all orienter classes.
    c                     | j                   S )zV
        The rotation matrix corresponding to this orienter
        instance.
        )_parent_orientselfs    [/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/vector/orienters.pyrotation_matrixzOrienter.rotation_matrix   s    
 """    N)__name__
__module____qualname____doc__r    r   r   r   r      s    #r   r   c                   X     e Zd ZdZ fdZd Zed        Zed        Z	ed        Z
 xZS )AxisOrienterz+
    Class to denote an axis orienter.
    c                     t        |t        j                  j                        st	        d      t        |      }t        |   | ||      }||_        ||_	        |S )Nzaxis should be a Vector)

isinstancesympyvectorVector	TypeErrorr   super__new___angle_axis)clsangleaxisobj	__class__s       r   r%   zAxisOrienter.__new__   sQ    $ 3 34566goc5$/
	
r   c                      y)a  
        Axis rotation is a rotation about an arbitrary axis by
        some angle. The angle is supplied as a SymPy expr scalar, and
        the axis is supplied as a Vector.

        Parameters
        ==========

        angle : Expr
            The angle by which the new system is to be rotated

        axis : Vector
            The axis around which the rotation has to be performed

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> from sympy import symbols
        >>> q1 = symbols('q1')
        >>> N = CoordSys3D('N')
        >>> from sympy.vector import AxisOrienter
        >>> orienter = AxisOrienter(q1, N.i + 2 * N.j)
        >>> B = N.orient_new('B', (orienter, ))

        Nr   )r   r)   r*   s      r   __init__zAxisOrienter.__init__(   s    8 	r   c                    t         j                  j                  | j                  |      j	                         }|j                  |      }| j                  }t        d      ||j                  z  z
  t        |      z  t        d|d    |d   g|d   d|d    g|d    |d   dgg      t        |      z  z   ||j                  z  z   }|j                  }|S )z
        The rotation matrix corresponding to this orienter
        instance.

        Parameters
        ==========

        system : CoordSys3D
            The coordinate system wrt which the rotation matrix
            is to be computed
           r         )r    r!   expressr*   	normalize	to_matrixr)   r   Tr   Matrixr   )r   systemr*   thetaparent_orients        r   r   zAxisOrienter.rotation_matrixF   s     ||##DIIv6@@B~~f%

a&4$&&=0CJ>!d1gXtAw!7"&q'1tAwh!7#'7(DGQ!7!9 :<?JGG 	'
 &r   c                     | j                   S N)r&   r   s    r   r)   zAxisOrienter.angle_   s    {{r   c                     | j                   S r<   )r'   r   s    r   r*   zAxisOrienter.axisc   s    zzr   )r   r   r   r   r%   r.   r   r   propertyr)   r*   __classcell__r,   s   @r   r   r      sN    	<  0    r   r   c                   b     e Zd ZdZ fdZed        Zed        Zed        Zed        Z	 xZ
S )ThreeAngleOrienterz3
    Super-class for Body and Space orienters.
    c           	         t        |t              r|j                  }d}|}t        |      j	                         }t        |      dk(  st        d      |D cg c]  }|j                  dd       }}|D cg c]  }|j                  dd       }}|D cg c]  }|j                  dd	       }}d
j                  |      }||vrt        d      t        |d         }t        |d         }	t        |d         }
t        |      }t        |      }t        |      }| j                  r't        ||      t        |	|      z  t        |
|      z  }n&t        |
|      t        |	|      z  t        ||      z  }|j                  }t        | =  | |||t        |            }||_        ||_        ||_        ||_        ||_        |S c c}w c c}w c c}w )N)123231312132213321121131212232313323 r0   z%rot_order should be a str of length 3X1Y2Z3rP   zInvalid rot_type parameterr   r2   r1   )r   r   namestrupperlenr#   replacejoinintr   	_in_order_rotr6   r$   r%   _angle1_angle2_angle3
_rot_orderr   )r(   angle1angle2angle3	rot_orderapproved_ordersoriginal_rot_orderia1a2a3r:   r+   r,   s                r   r%   zThreeAngleOrienter.__new__m   s   i%!I- '	N((*	I!#CDD2;<QQYYsC(<	<2;<QQYYsC(<	<2;<QQYYsC(<	<GGI&	O+899111==!"f-!"f-.!"f-.M ""f-!"f-.!"f-.M &goY9+*
= =<<s   G7GGc                     | j                   S r<   )r`   r   s    r   rd   zThreeAngleOrienter.angle1       ||r   c                     | j                   S r<   )ra   r   s    r   re   zThreeAngleOrienter.angle2   ro   r   c                     | j                   S r<   )rb   r   s    r   rf   zThreeAngleOrienter.angle3   ro   r   c                     | j                   S r<   )rc   r   s    r   rg   zThreeAngleOrienter.rot_order   s    r   )r   r   r   r   r%   r>   rd   re   rf   rg   r?   r@   s   @r   rB   rB   h   s^    )V        r   rB   c                        e Zd ZdZdZd Zd Zy)BodyOrienterz*
    Class to denote a body-orienter.
    Tc                 8    t         j                  | ||||      }|S r<   rB   r%   r(   rd   re   rf   rg   r+   s         r   r%   zBodyOrienter.__new__   "     ((fff)24
r   c                      y)a  
        Body orientation takes this coordinate system through three
        successive simple rotations.

        Body fixed rotations include both Euler Angles and
        Tait-Bryan Angles, see https://en.wikipedia.org/wiki/Euler_angles.

        Parameters
        ==========

        angle1, angle2, angle3 : Expr
            Three successive angles to rotate the coordinate system by

        rotation_order : string
            String defining the order of axes for rotation

        Examples
        ========

        >>> from sympy.vector import CoordSys3D, BodyOrienter
        >>> from sympy import symbols
        >>> q1, q2, q3 = symbols('q1 q2 q3')
        >>> N = CoordSys3D('N')

        A 'Body' fixed rotation is described by three angles and
        three body-fixed rotation axes. To orient a coordinate system D
        with respect to N, each sequential rotation is always about
        the orthogonal unit vectors fixed to D. For example, a '123'
        rotation will specify rotations about N.i, then D.j, then
        D.k. (Initially, D.i is same as N.i)
        Therefore,

        >>> body_orienter = BodyOrienter(q1, q2, q3, '123')
        >>> D = N.orient_new('D', (body_orienter, ))

        is same as

        >>> from sympy.vector import AxisOrienter
        >>> axis_orienter1 = AxisOrienter(q1, N.i)
        >>> D = N.orient_new('D', (axis_orienter1, ))
        >>> axis_orienter2 = AxisOrienter(q2, D.j)
        >>> D = D.orient_new('D', (axis_orienter2, ))
        >>> axis_orienter3 = AxisOrienter(q3, D.k)
        >>> D = D.orient_new('D', (axis_orienter3, ))

        Acceptable rotation orders are of length 3, expressed in XYZ or
        123, and cannot have a rotation about about an axis twice in a row.

        >>> body_orienter1 = BodyOrienter(q1, q2, q3, '123')
        >>> body_orienter2 = BodyOrienter(q1, q2, 0, 'ZXZ')
        >>> body_orienter3 = BodyOrienter(0, 0, 0, 'XYX')

        Nr   r   rd   re   rf   rg   s        r   r.   zBodyOrienter.__init__   s    n 	r   Nr   r   r   r   r^   r%   r.   r   r   r   rt   rt      s     I
7r   rt   c                        e Zd ZdZdZd Zd Zy)SpaceOrienterz+
    Class to denote a space-orienter.
    Fc                 8    t         j                  | ||||      }|S r<   rv   rw   s         r   r%   zSpaceOrienter.__new__   rx   r   c                      y)a  
        Space rotation is similar to Body rotation, but the rotations
        are applied in the opposite order.

        Parameters
        ==========

        angle1, angle2, angle3 : Expr
            Three successive angles to rotate the coordinate system by

        rotation_order : string
            String defining the order of axes for rotation

        See Also
        ========

        BodyOrienter : Orienter to orient systems wrt Euler angles.

        Examples
        ========

        >>> from sympy.vector import CoordSys3D, SpaceOrienter
        >>> from sympy import symbols
        >>> q1, q2, q3 = symbols('q1 q2 q3')
        >>> N = CoordSys3D('N')

        To orient a coordinate system D with respect to N, each
        sequential rotation is always about N's orthogonal unit vectors.
        For example, a '123' rotation will specify rotations about
        N.i, then N.j, then N.k.
        Therefore,

        >>> space_orienter = SpaceOrienter(q1, q2, q3, '312')
        >>> D = N.orient_new('D', (space_orienter, ))

        is same as

        >>> from sympy.vector import AxisOrienter
        >>> axis_orienter1 = AxisOrienter(q1, N.i)
        >>> B = N.orient_new('B', (axis_orienter1, ))
        >>> axis_orienter2 = AxisOrienter(q2, N.j)
        >>> C = B.orient_new('C', (axis_orienter2, ))
        >>> axis_orienter3 = AxisOrienter(q3, N.k)
        >>> D = C.orient_new('C', (axis_orienter3, ))

        Nr   rz   s        r   r.   zSpaceOrienter.__init__   s    ` 	r   Nr{   r   r   r   r}   r}      s     I
0r   r}   c                   h     e Zd ZdZ fdZd Zed        Zed        Zed        Z	ed        Z
 xZS )QuaternionOrienterz0
    Class to denote a quaternion-orienter.
    c           	          t        |      }t        |      }t        |      }t        |      }t        |dz  |dz  z   |dz  z
  |dz  z
  d||z  ||z  z
  z  d||z  ||z  z   z  gd||z  ||z  z   z  |dz  |dz  z
  |dz  z   |dz  z
  d||z  ||z  z
  z  gd||z  ||z  z
  z  d||z  ||z  z   z  |dz  |dz  z
  |dz  z
  |dz  z   gg      }|j                  }t        |   | ||||      }||_        ||_        ||_        ||_        ||_	        |S )Nr1   )
r   r7   r6   r$   r%   _q0_q1_q2_q3r   )r(   q0q1q2q3r:   r+   r,   s          r   r%   zQuaternionOrienter.__new__3  s   R[R[R[R["'B!G"3bAg"="$'#*"#rBwb'8"9"#rBwb'8"9"; #$rBwb'8"9"$'B!G"3"$'#*,.!G#4"#rBwb'8"9"; #$rBwb'8"9"#rBwb'8"9"$'B!G"3"$'#*,.!G#4"5!6 7 &goc2r2r2*
r   c                      y)a  
        Quaternion orientation orients the new CoordSys3D with
        Quaternions, defined as a finite rotation about lambda, a unit
        vector, by some amount theta.

        This orientation is described by four parameters:

        q0 = cos(theta/2)

        q1 = lambda_x sin(theta/2)

        q2 = lambda_y sin(theta/2)

        q3 = lambda_z sin(theta/2)

        Quaternion does not take in a rotation order.

        Parameters
        ==========

        q0, q1, q2, q3 : Expr
            The quaternions to rotate the coordinate system by

        Examples
        ========

        >>> from sympy.vector import CoordSys3D
        >>> from sympy import symbols
        >>> q0, q1, q2, q3 = symbols('q0 q1 q2 q3')
        >>> N = CoordSys3D('N')
        >>> from sympy.vector import QuaternionOrienter
        >>> q_orienter = QuaternionOrienter(q0, q1, q2, q3)
        >>> B = N.orient_new('B', (q_orienter, ))

        Nr   rz   s        r   r.   zQuaternionOrienter.__init__O  s    J 	r   c                     | j                   S r<   )r   r   s    r   r   zQuaternionOrienter.q0v      xxr   c                     | j                   S r<   )r   r   s    r   r   zQuaternionOrienter.q1z  r   r   c                     | j                   S r<   )r   r   s    r   r   zQuaternionOrienter.q2~  r   r   c                     | j                   S r<   )r   r   s    r   r   zQuaternionOrienter.q3  r   r   )r   r   r   r   r%   r.   r>   r   r   r   r   r?   r@   s   @r   r   r   .  sc    8%N        r   r   c                     | dk(  rt        t        |      j                        S | dk(  rt        t        |      j                        S | dk(  rt        t	        |      j                        S y)z)DCM for simple axis 1, 2 or 3 rotations. r2   r1   r0   N)r7   r   r6   r	   r
   )r*   r)   s     r   r_   r_     s^    qyi&(())	i&(())	i&(()) 
r   )sympy.core.basicr   sympy.core.sympifyr   (sympy.functions.elementary.trigonometricr   r   sympy.matrices.denser   r   r	   r
   sympy.matrices.immutabler   r7   sympy.core.cacher   sympy.core.symbolr   sympy.vectorr    r   r   rB   rt   r}   r   r_   r   r   r   <module>r      sz    " & ? G G C $ ! 
#u 
#M8 M`> >BC% CL<& <~V Vr*r   