
    \h_T                         S r SSKJrJr  SSKJrJrJrJrJ	r	J
r
  SSKJr  SSKJr  SSKJr  SSKJrJr  SSKJr  / S	Qr " S
 S\5      r " S S\5      r " S S\5      rS rg)z.Geometry objects for use by wrapping pathways.    )ABCabstractmethod)Integeracospisqrtsympifytan)Eq)atan2)cancel)Vectordot)trigsimp)WrappingGeometryBaseWrappingCylinderWrappingSpherec                   h    \ rS rSrSr\\S 5       5       r\S 5       r\S 5       r	\S 5       r
S rSrg	)
r      zAbstract base class for all geometry classes to inherit from.

Notes
=====

Instances of this class cannot be directly instantiated by users. However,
it can be used to created custom geometry types through subclassing.

c                     g)z0The point with which the geometry is associated.N )clss    a/var/www/auris/envauris/lib/python3.13/site-packages/sympy/physics/mechanics/wrapping_geometry.pypointWrappingGeometryBase.point   s     	    c                     g)zReturns ``True`` if a point is on the geometry's surface.

Parameters
==========
point : Point
    The point for which it's to be ascertained if it's on the
    geometry's surface or not.

Nr   selfr   s     r   point_on_surface%WrappingGeometryBase.point_on_surface%   s     	r   c                     g)a  Returns the shortest distance between two points on a geometry's
surface.

Parameters
==========

point_1 : Point
    The point from which the geodesic length should be calculated.
point_2 : Point
    The point to which the geodesic length should be calculated.

Nr   r   point_1point_2s      r   geodesic_length$WrappingGeometryBase.geodesic_length2   s     	r   c                     g)The vectors parallel to the geodesic at the two end points.

Parameters
==========

point_1 : Point
    The point from which the geodesic originates.
point_2 : Point
    The point at which the geodesic terminates.

Nr   r#   s      r   geodesic_end_vectors)WrappingGeometryBase.geodesic_end_vectorsB   s     	r   c                 4    U R                   R                   S3$ )z,Default representation of a geometry object.z())	__class____name__r   s    r   __repr__WrappingGeometryBase.__repr__Q   s    ..))*"--r   r   N)r.   
__module____qualname____firstlineno____doc__propertyr   r   r    r&   r*   r0   __static_attributes__r   r   r   r   r      sd        
 
    .r   r   c                       \ rS rSrSrS r\S 5       r\R                  S 5       r\S 5       r	\	R                  S 5       r	S r
S	 rS
 rS rSrg)r   V   a  A solid spherical object.

Explanation
===========

A wrapping geometry that allows for circular arcs to be defined between
pairs of points. These paths are always geodetic (the shortest possible).

Examples
========

To create a ``WrappingSphere`` instance, a ``Symbol`` denoting its radius
and ``Point`` at which its center will be located are needed:

>>> from sympy import symbols
>>> from sympy.physics.mechanics import Point, WrappingSphere
>>> r = symbols('r')
>>> pO = Point('pO')

A sphere with radius ``r`` centered on ``pO`` can be instantiated with:

>>> WrappingSphere(r, pO)
WrappingSphere(radius=r, point=pO)

Parameters
==========

radius : Symbol
    Radius of the sphere. This symbol must represent a value that is
    positive and constant, i.e. it cannot be a dynamic symbol, nor can it
    be an expression.
point : Point
    A point at which the sphere is centered.

See Also
========

WrappingCylinder: Cylindrical geometry where the wrapping direction can be
    defined.

c                     Xl         X l        g)zInitializer for ``WrappingSphere``.

Parameters
==========

radius : Symbol
    The radius of the sphere.
point : Point
    A point on which the sphere is centered.

N)radiusr   )r   r;   r   s      r   __init__WrappingSphere.__init__   s     
r   c                     U R                   $ )zRadius of the sphere._radiusr/   s    r   r;   WrappingSphere.radius        ||r   c                     Xl         g Nr?   r   r;   s     r   r;   rA          r   c                     U R                   $ )z(A point on which the sphere is centered._pointr/   s    r   r   WrappingSphere.point        {{r   c                     Xl         g rD   rH   r   s     r   r   rJ          r   c                     UR                  U R                  5      n[        U[        5      (       a  [	        X"5      nOUS-  n[        X0R                  S-  5      S:H  $ )ac  Returns ``True`` if a point is on the sphere's surface.

Parameters
==========

point : Point
    The point for which it's to be ascertained if it's on the sphere's
    surface or not. This point's position relative to the sphere's
    center must be a simple expression involving the radius of the
    sphere, otherwise this check will likely not work.

   T)pos_fromr   
isinstancer   r   r   r;   )r   r   point_vectorpoint_radius_squareds       r   r    WrappingSphere.point_on_surface   sQ     ~~djj1lF++#&|#B #/? &Q74??r   c                    X4 Hq  nU R                  U5      (       a  M  SU SUR                  U R                  5      R                  5        SU R                   SU  SU R                   S3n[        U5      e   UR                  U R                  5      R                  5       nUR                  U R                  5      R                  5       n[        UR                  U5      5      nU R                  U-  nU$ )a  Returns the shortest distance between two points on the sphere's
surface.

Explanation
===========

The geodesic length, i.e. the shortest arc along the surface of a
sphere, connecting two points can be calculated using the formula:

.. math::

   l = \arccos\left(\mathbf{v}_1 \cdot \mathbf{v}_2\right)

where $\mathbf{v}_1$ and $\mathbf{v}_2$ are the unit vectors from the
sphere's center to the first and second points on the sphere's surface
respectively. Note that the actual path that the geodesic will take is
undefined when the two points are directly opposite one another.

Examples
========

A geodesic length can only be calculated between two points on the
sphere's surface. Firstly, a ``WrappingSphere`` instance must be
created along with two points that will lie on its surface:

>>> from sympy import symbols
>>> from sympy.physics.mechanics import (Point, ReferenceFrame,
...     WrappingSphere)
>>> N = ReferenceFrame('N')
>>> r = symbols('r')
>>> pO = Point('pO')
>>> pO.set_vel(N, 0)
>>> sphere = WrappingSphere(r, pO)
>>> p1 = Point('p1')
>>> p2 = Point('p2')

Let's assume that ``p1`` lies at a distance of ``r`` in the ``N.x``
direction from ``pO`` and that ``p2`` is located on the sphere's
surface in the ``N.y + N.z`` direction from ``pO``. These positions can
be set with:

>>> p1.set_pos(pO, r*N.x)
>>> p1.pos_from(pO)
r*N.x
>>> p2.set_pos(pO, r*(N.y + N.z).normalize())
>>> p2.pos_from(pO)
sqrt(2)*r/2*N.y + sqrt(2)*r/2*N.z

The geodesic length, which is in this case is a quarter of the sphere's
circumference, can be calculated using the ``geodesic_length`` method:

>>> sphere.geodesic_length(p1, p2)
pi*r/2

If the ``geodesic_length`` method is passed an argument, the ``Point``
that doesn't lie on the sphere's surface then a ``ValueError`` is
raised because it's not possible to calculate a value in this case.

Parameters
==========

point_1 : Point
    Point from which the geodesic length should be calculated.
point_2 : Point
    Point to which the geodesic length should be calculated.

.Geodesic length cannot be calculated as point  with radius z from the sphere's center   does not lie on the surface of .)	r    rP   r   	magnituder;   
ValueError	normalizer   r   )	r   r$   r%   r   msgpoint_1_vectorpoint_2_vectorcentral_angler&   s	            r   r&   WrappingSphere.geodesic_length   s    H 'E((//DUG L##(>>$**#=#G#G#I"J K115 =&&*V=QH  !o% ( !))$**5??A ))$**5??A^//?@++m3r   c                    XpCU R                   nUR                  U5      nUR                  U5      nUR                  U5      S:X  a  SU SU SU  S3n[        U5      eUR                  UR                  U5      5      R                  U5      R	                  5       UR                  UR                  U5      5      R                  U5      R	                  5       4$ )r)   r   z:Can't compute geodesic end vectors for the pair of points  and z on a sphere zE as they are diametrically opposed, thus the geodesic is not defined.)r   rP   crossr[   r\   )	r   r$   r%   pApBpOpA_vecpB_vecr]   s	            r   r*   #WrappingSphere.geodesic_end_vectors	  s     BZZRR<<1$M$eB4}TF 3=> 
 S/! LLR)//7AACLLR)//7AAC
 	
r   c                 h    U R                   R                   SU R                   SU R                   S3$ )z'Representation of a ``WrappingSphere``.(radius=, point=))r-   r.   r;   r   r/   s    r   r0   WrappingSphere.__repr__'  s8     ~~&&'x} =ZZL#	
r   )rI   r@   r   r;   N)r.   r2   r3   r4   r5   r<   r6   r;   setterr   r    r&   r*   r0   r7   r   r   r   r   r   V   s|    (T   ]]    \\ @(Qf
<
r   r   c                       \ rS rSrSrS r\S 5       r\R                  S 5       r\S 5       r	\	R                  S 5       r	\S 5       r
\
R                  S	 5       r
S
 rS rS rS rSrg)r   i/  a  A solid (infinite) cylindrical object.

Explanation
===========

A wrapping geometry that allows for circular arcs to be defined between
pairs of points. These paths are always geodetic (the shortest possible) in
the sense that they will be a straight line on the unwrapped cylinder's
surface. However, it is also possible for a direction to be specified, i.e.
paths can be influenced such that they either wrap along the shortest side
or the longest side of the cylinder. To define these directions, rotations
are in the positive direction following the right-hand rule.

Examples
========

To create a ``WrappingCylinder`` instance, a ``Symbol`` denoting its
radius, a ``Vector`` defining its axis, and a ``Point`` through which its
axis passes are needed:

>>> from sympy import symbols
>>> from sympy.physics.mechanics import (Point, ReferenceFrame,
...     WrappingCylinder)
>>> N = ReferenceFrame('N')
>>> r = symbols('r')
>>> pO = Point('pO')
>>> ax = N.x

A cylinder with radius ``r``, and axis parallel to ``N.x`` passing through
``pO`` can be instantiated with:

>>> WrappingCylinder(r, pO, ax)
WrappingCylinder(radius=r, point=pO, axis=N.x)

Parameters
==========

radius : Symbol
    The radius of the cylinder.
point : Point
    A point through which the cylinder's axis passes.
axis : Vector
    The axis along which the cylinder is aligned.

See Also
========

WrappingSphere: Spherical geometry where the wrapping direction is always
    geodetic.

c                 (    Xl         X l        X0l        g)a]  Initializer for ``WrappingCylinder``.

Parameters
==========

radius : Symbol
    The radius of the cylinder. This symbol must represent a value that
    is positive and constant, i.e. it cannot be a dynamic symbol.
point : Point
    A point through which the cylinder's axis passes.
axis : Vector
    The axis along which the cylinder is aligned.

N)r;   r   axis)r   r;   r   rs   s       r   r<   WrappingCylinder.__init__d  s     
	r   c                     U R                   $ )zRadius of the cylinder.r?   r/   s    r   r;   WrappingCylinder.radiusw  rB   r   c                     Xl         g rD   r?   rE   s     r   r;   rv   |  rF   r   c                     U R                   $ )z1A point through which the cylinder's axis passes.rH   r/   s    r   r   WrappingCylinder.point  rK   r   c                     Xl         g rD   rH   r   s     r   r   ry     rM   r   c                     U R                   $ )z)Axis along which the cylinder is aligned.)_axisr/   s    r   rs   WrappingCylinder.axis  s     zzr   c                 .    UR                  5       U l        g rD   )r\   r|   )r   rs   s     r   rs   r}     s    ^^%
r   c                 &   UR                  U R                  5      nUR                  U R                  5      U R                  -  nX#-
  n[	        U[
        5      (       a  [        XD5      nOUS-  n[        [        U5      U R                  S-  5      S:H  $ )ag  Returns ``True`` if a point is on the cylinder's surface.

Parameters
==========

point : Point
    The point for which it's to be ascertained if it's on the
    cylinder's surface or not. This point's position relative to the
    cylinder's axis must be a simple expression involving the radius of
    the sphere, otherwise this check will likely not work.

rO   T)	rP   r   r   rs   rQ   r   r   r   r;   )r   r   relative_positionparallelrR   rS   s         r   r    !WrappingCylinder.point_on_surface  s~     "NN4::6$((3dii?(3lF++#&|#B #/? (/0$++q.ATIIr   c                    X4 H~  nU R                  U5      (       a  M  SU SUR                  U R                  5      R                  5        SU R                   SU  SU R                   SU R
                   S3n[        U5      e   UR                  U5      nUR                  U R
                  5      nUR                  U R                  5      nUUR                  U R
                  5      U R
                  -  -
  R                  5       nUR                  U R                  5      n	U	U	R                  U R
                  5      U R
                  -  -
  R                  5       n
[        [        UR                  U
5      R                  U R
                  5      5      [        UR                  U
5      5      5      nU R                  U-  n[        US-  US-  -   5      nU$ )aA	  The shortest distance between two points on a geometry's surface.

Explanation
===========

The geodesic length, i.e. the shortest arc along the surface of a
cylinder, connecting two points. It can be calculated using Pythagoras'
theorem. The first short side is the distance between the two points on
the cylinder's surface parallel to the cylinder's axis. The second
short side is the arc of a circle between the two points of the
cylinder's surface perpendicular to the cylinder's axis. The resulting
hypotenuse is the geodesic length.

Examples
========

A geodesic length can only be calculated between two points on the
cylinder's surface. Firstly, a ``WrappingCylinder`` instance must be
created along with two points that will lie on its surface:

>>> from sympy import symbols, cos, sin
>>> from sympy.physics.mechanics import (Point, ReferenceFrame,
...     WrappingCylinder, dynamicsymbols)
>>> N = ReferenceFrame('N')
>>> r = symbols('r')
>>> pO = Point('pO')
>>> pO.set_vel(N, 0)
>>> cylinder = WrappingCylinder(r, pO, N.x)
>>> p1 = Point('p1')
>>> p2 = Point('p2')

Let's assume that ``p1`` is located at ``N.x + r*N.y`` relative to
``pO`` and that ``p2`` is located at ``r*(cos(q)*N.y + sin(q)*N.z)``
relative to ``pO``, where ``q(t)`` is a generalized coordinate
specifying the angle rotated around the ``N.x`` axis according to the
right-hand rule where ``N.y`` is zero. These positions can be set with:

>>> q = dynamicsymbols('q')
>>> p1.set_pos(pO, N.x + r*N.y)
>>> p1.pos_from(pO)
N.x + r*N.y
>>> p2.set_pos(pO, r*(cos(q)*N.y + sin(q)*N.z).normalize())
>>> p2.pos_from(pO).simplify()
r*cos(q(t))*N.y + r*sin(q(t))*N.z

The geodesic length, which is in this case a is the hypotenuse of a
right triangle where the other two side lengths are ``1`` (parallel to
the cylinder's axis) and ``r*q(t)`` (parallel to the cylinder's cross
section), can be calculated using the ``geodesic_length`` method:

>>> cylinder.geodesic_length(p1, p2).simplify()
sqrt(r**2*q(t)**2 + 1)

If the ``geodesic_length`` method is passed an argument ``Point`` that
doesn't lie on the sphere's surface then a ``ValueError`` is raised
because it's not possible to calculate a value in this case.

Parameters
==========

point_1 : Point
    Point from which the geodesic length should be calculated.
point_2 : Point
    Point to which the geodesic length should be calculated.

rV   rW   z from the cylinder's center rX   z
 and axis rY   rO   )r    rP   r   rZ   r;   rs   r[   r   r\   _directional_atanr   rd   r   )r   r$   r%   r   r]   r   parallel_lengthpoint_1_relative_positionpoint_1_perpendicular_vectorpoint_2_relative_positionpoint_2_perpendicular_vectorr`   planar_arc_lengthr&   s                 r   r&    WrappingCylinder.geodesic_length  s   F 'E((//DUG L##(>>$**#=#G#G#I"J K337::, ?&&*V=Zyyk	$  !o% ( $,,W5+//		:$+$4$4TZZ$@!%'++DII6tyy@A
)+ 	%
 %,$4$4TZZ$@!%'++DII6tyy@A
)+ 	%
 */34TYY! /334PQR	
 !KK514Eq4HHIr   c                 \   UR                  U R                  5      nUR                  U R                  5      nX4:X  a  SU SU S3n[        U5      eUR                  U R                  5      U R                  -  nUR                  U R                  5      U R                  -  nX6-
  nXG-
  n	X:X  a  [        S5      n
[        S5      nOSU R                  R                  U5      R                  5       n
U R                  R                  U	5      R                  5       * nU R                  X5      nUR                  U5      nUR                  U R                  5      n[        US-  US-  -
  5      nX-  XR                  -  -   R                  5       nX-  XR                  -  -
  R                  5       nUU4$ )r)   z:Cannot compute geodesic end vectors for coincident points rc   z as no geodesic exists.r   rO   )
rP   r   r[   r   rs   r   rd   r\   r&   r   )r   r$   r%   point_1_from_origin_pointpoint_2_from_origin_pointr]   point_1_parallelpoint_2_parallelpoint_1_normalpoint_2_normalpoint_1_perpendicularpoint_2_perpendicularr&   r   r   r   r^   r_   s                     r   r*   %WrappingCylinder.geodesic_end_vectors  s    %,$4$4TZZ$@!$+$4$4TZZ$@!$AL)5	)@B  S/!488CdiiO488CdiiO3F3F+$*1I!$*1I!$(IIOON$C$M$M$O!%)YY__^%D%N%N%P$P!..w@#,,W5+//		: !!3oq6H!HI 5		)*
)+ 	
 5		)*
)+ 	
 //r   c                     U R                   R                   SU R                   SU R                   SU R                   S3$ )z)Representation of a ``WrappingCylinder``.rl   rm   z, axis=rn   )r-   r.   r;   r   rs   r/   s    r   r0   WrappingCylinder.__repr__B  sB     ~~&&'x} =ZZL		{!5	
r   )r|   rI   r@   rs   r   r;   N)r.   r2   r3   r4   r5   r<   r6   r;   rp   r   rs   r    r&   r*   r0   r7   r   r   r   r   r   /  s    2h&   ]]    \\    
[[& &J,fP00d
r   r   c                    U R                   (       a0  UR                   (       a  [        X5      nUS:  a  US[        -  -  nU$ U R                   (       a  SU  SU S3n[        U5      eUR                   (       a  SU  SU S3n[        U5      e[	        [        X-  5      5      n[        U[        5      (       a  UR                  S   nU$ UR                  (       af  UR                  S   [        S5      :X  aJ  [        UR                  S	   [        5      (       a(  S[        -  UR                  S	   R                  S   -
  nU$ S
U S3n[        U5      e)aO  Compute atan in a directional sense as required for geodesics.

Explanation
===========

To be able to control the direction of the geodesic length along the
surface of a cylinder a dedicated arctangent function is needed that
properly handles the directionality of different case. This function
ensures that the central angle is always positive but shifting the case
where ``atan2`` would return a negative angle to be centered around
``2*pi``.

Notes
=====

This function only handles very specific cases, i.e. the ones that are
expected to be encountered when calculating symbolic geodesics on uniformly
curved surfaces. As such, ``NotImplemented`` errors can be raised in many
cases. This function is named with a leader underscore to indicate that it
only aims to provide very specific functionality within the private scope
of this module.

r   rO   z5Cannot compute a directional atan when the numerator z  is numeric and the denominator z is symbolic.z! is symbolic and the denominator z is numeric.   z0Cannot compute a directional atan for the value rY   )	is_numberr   r   NotImplementedErrorr	   r   rQ   r
   argsis_Mulr   )	numeratordenominatorangler]   ratios        r   r   r   J  sO   2 {44i-19QVOE6 L5 
		CI; O..9]-I 	 "#&&			CI; O//:m<I 	 "#&&!89:eS!!JJqME L LL

1,5::a=#..FUZZ]//22E
 L EUG1MC%c**r   N)r5   abcr   r   sympyr   r   r   r   r	   r
   sympy.core.relationalr   (sympy.functions.elementary.trigonometricr   sympy.polys.polytoolsr   sympy.physics.vectorr   r   sympy.simplify.simplifyr   __all__r   r   r   r   r   r   r   <module>r      sY    4 # 7 7 $ : ( , ,?.3 ?.DV
) V
rX
+ X
v7r   