K i.ddlmZddlmZddlmZmZddlmZm Z m Z m Z ddl m ZddlmZddlmZddlZGd d eZGd d eZGd deZGddeZGddeZGddeZdZy))Basic)sympify)cossin)eye rot_axis1 rot_axis2 rot_axis3)ImmutableDenseMatrix)cacheit)StrNceZdZdZdZy)Orienterz/ Super-class for all orienter classes. c|jS)zV The rotation matrix corresponding to this orienter instance. )_parent_orientselfs \/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/vector/orienters.pyrotation_matrixzOrienter.rotation_matrixs """N)__name__ __module__ __qualname____doc__rrrrr s #rrcXeZdZdZfdZdZedZedZ edZ xZ S) AxisOrienterz+ Class to denote an axis orienter. ct|tjjs t dt |}t ||||}||_||_ |S)Nzaxis should be a Vector) isinstancesympyvectorVector TypeErrorrsuper__new___angle_axis)clsangleaxisobj __class__s rr%zAxisOrienter.__new__sQ$ 3 3456 6goc5$/   rcy)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)rr)r*s r__init__zAxisOrienter.__init__(s8 rctjj|j|j }|j |}|j }td||jzz t|ztd|d |dg|dd|d g|d |ddggt|zz||jzz}|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)rTrMatrixr)rsystemr*theta parent_orients rrzAxisOrienter.rotation_matrixFs||##DIIv6@@B~~f% a&4$&&=0CJ>!d1gXtAw!7"&q'1tAwh!7#'7(DGQ!7!9:rdrerfrgr?r@s@rrBrBhs^)VrrBc eZdZdZdZdZdZy) BodyOrienterz* Class to denote a body-orienter. Tc8tj|||||}|Sr<rBr%r(rdrerfrgr+s rr%zBodyOrienter.__new__" ((fff)24 rcy)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') Nrrrdrerfrgs rr.zBodyOrienter.__init__sn rNrrrrr^r%r.rrrrtrtsI 7 rrtc eZdZdZdZdZdZy) SpaceOrienterz+ Class to denote a space-orienter. Fc8tj|||||}|Sr<rvrws rr%zSpaceOrienter.__new__rxrcy)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, )) Nrrzs rr.zSpaceOrienter.__init__s` rNr{rrrr}r}sI 0 rr}cheZdZdZfdZdZedZedZedZ edZ xZ S)QuaternionOrienterz0 Class to denote a quaternion-orienter. c  t|}t|}t|}t|}t|dz|dzz|dzz |dzz d||z||zz zd||z||zzzgd||z||zzz|dz|dzz |dzz|dzz d||z||zz zgd||z||zz zd||z||zzz|dz|dzz |dzz |dzzgg}|j}t||||||}||_||_||_||_||_ |S)Nr1) rr7r6r$r%_q0_q1_q2_q3r)r(q0q1q2q3r:r+r,s rr%zQuaternionOrienter.__new__3s R[ R[ R[ R["'B!G"3bAg"="$'#*"#rBwb'8"9"#rBwb'8"9";#$rBwb'8"9"$'B!G"3"$'#*,.!G#4"#rBwb'8"9";#$rBwb'8"9"#rBwb'8"9"$'B!G"3"$'#*,.!G#4"5 !6 7 & goc2r2r2* rcy)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, )) Nrrzs rr.zQuaternionOrienter.__init__OsJ rc|jSr<)rrs rrzQuaternionOrienter.q0v xxrc|jSr<)rrs rrzQuaternionOrienter.q1zrrc|jSr<)rrs rrzQuaternionOrienter.q2~rrc|jSr<)rrs rrzQuaternionOrienter.q3rr) rrrrr%r.r>rrrrr?r@s@rrr.sc8% Nrrc|dk(rtt|jS|dk(rtt|jS|dk(rtt |jSy)z)DCM for simple axis 1, 2 or 3 rotations. r2r1r0N)r7rr6r r )r*r)s rr_r_s^ qyi&(()) i&(()) i&(()) r)sympy.core.basicrsympy.core.sympifyr(sympy.functions.elementary.trigonometricrrsympy.matrices.denserrr r sympy.matrices.immutabler r7sympy.core.cacher sympy.core.symbolr sympy.vectorr rrrBrtr}rr_rrrrsz"&?GGC$! #u #M8M`>>BC %C L< &< ~VVr*r