a
    ߙfb^"                     @   s   d Z g dZddlZddlmZ ddlmZm	Z	 dd Z
dd Zd	d
 Zdd ZdddZdddZddlmZ ddlmZ g dZeD ]*Zede de ddeeee e< qdS )z
This module contains utility functions for working with angles. These are both
used internally in astropy.coordinates.angles, and of possible
)angular_separationposition_angle	offset_bygolden_spiral_grid uniform_spherical_random_surfaceuniform_spherical_random_volume    N)UnitSphericalRepresentationSphericalRepresentationc                 C   s   t ||  }t ||  }t |}t |}t |}t |}	|	| }
|| ||	 |  }|| ||	 |  }t t |
||S )a-  
    Angular separation between two points on a sphere.

    Parameters
    ----------
    lon1, lat1, lon2, lat2 : `~astropy.coordinates.Angle`, `~astropy.units.Quantity` or float
        Longitude and latitude of the two points. Quantities should be in
        angular units; floats in radians.

    Returns
    -------
    angular separation : `~astropy.units.Quantity` ['angle'] or float
        Type depends on input; ``Quantity`` in angular units, or float in
        radians.

    Notes
    -----
    The angular separation is calculated using the Vincenty formula [1]_,
    which is slightly more complex and computationally expensive than
    some alternatives, but is stable at at all distances, including the
    poles and antipodes.

    .. [1] https://en.wikipedia.org/wiki/Great-circle_distance
    )npsincosarctan2Zhypot)lon1lat1lon2lat2ZsdlonZcdlonZslat1Zslat2Zclat1Zclat2Znum1Znum2denominator r   Blib/python3.9/site-packages/astropy/coordinates/angle_utilities.pyr      s    



r   c           	      C   sx   ddl m} ||  }t|}t|t| |t| t|  }t|| }|t||tjdtj	 S )aX  
    Position Angle (East of North) between two points on a sphere.

    Parameters
    ----------
    lon1, lat1, lon2, lat2 : `~astropy.coordinates.Angle`, `~astropy.units.Quantity` or float
        Longitude and latitude of the two points. Quantities should be in
        angular units; floats in radians.

    Returns
    -------
    pa : `~astropy.coordinates.Angle`
        The (positive) position angle of the vector pointing from position 1 to
        position 2.  If any of the angles are arrays, this will contain an array
        following the appropriate `numpy` broadcasting rules.

       Angleih  )
anglesr   r
   r   r   r   uradianwrap_atdeg)	r   r   r   r   r   ZdeltalonZcolatxyr   r   r   r   >   s    
,r   c                 C   s0  ddl m} t|}t|}t|}t|}t|}	t|}
|| || |	  }||
 | }|||  }|t||tj}|dk }| rdtj	 |dtj	 ||tj   
tj}|jrt||j}|| ||< n|}|| tj| dtj	 
tj	}|t|tj
tj	}||fS )a  
    Point with the given offset from the given point.

    Parameters
    ----------
    lon, lat, posang, distance : `~astropy.coordinates.Angle`, `~astropy.units.Quantity` or float
        Longitude and latitude of the starting point,
        position angle and distance to the final point.
        Quantities should be in angular units; floats in radians.
        Polar points at lat= +/-90 are treated as limit of +/-(90-epsilon) and same lon.

    Returns
    -------
    lon, lat : `~astropy.coordinates.Angle`
        The position of the final point.  If any of the angles are arrays,
        these will contain arrays following the appropriate `numpy` broadcasting rules.
        0 <= lon < 2pi.
    r   r   g-q=Z   g     v@)r   r   r
   r   r   r   r   r   anyr   toradshapeZbroadcast_tor   arcsin)lonlatZposangZdistancer   Zcos_aZsin_aZcos_cZsin_cZcos_BZsin_BZcos_bZxsin_AZxcos_AAZsmall_sin_cZA_poleZoutlonZoutlatr   r   r   r   [   s*    	





,$r   c                 C   sV   d}t jd| tdd }dt j | | tj }t dd| |   tj }t||S )a  Generate a grid of points on the surface of the unit sphere using the
    Fibonacci or Golden Spiral method.

    .. seealso::

        `Evenly distributing points on a sphere <https://stackoverflow.com/questions/9600801/evenly-distributing-n-points-on-a-sphere>`_

    Parameters
    ----------
    size : int
        The number of points to generate.

    Returns
    -------
    rep : `~astropy.coordinates.UnitSphericalRepresentation`
        The grid of points.
    gw?r   )Zdtypeg      ?   r   )r
   Zarangefloatpir   r"   r$   r   )sizeZgolden_rZgridr%   r&   r   r   r   r      s
    r   r   c                 C   sF   t j}|ddt j | tj }t |jdd| dtj }t||S )a  Generate a random sampling of points on the surface of the unit sphere.

    Parameters
    ----------
    size : int
        The number of points to generate.

    Returns
    -------
    rep : `~astropy.coordinates.UnitSphericalRepresentation`
        The random points.
    r   r(   r   r+   )r
   randomuniformr*   r   r"   r$   r   )r+   rngr%   r&   r   r   r   r      s    r   c                 C   s@   t j}t| d}t |j| dtj|dd }t|j|j	|S )a  Generate a random sampling of points that follow a uniform volume
    density distribution within a sphere.

    Parameters
    ----------
    size : int
        The number of points to generate.
    max_radius : number, quantity-like, optional
        A dimensionless or unit-ful factor to scale the random distances.

    Returns
    -------
    rep : `~astropy.coordinates.SphericalRepresentation`
        The random points.
    r-   F)copy)
r
   r.   r   Zcbrtr/   r   ZQuantityr	   r%   r&   )r+   Z
max_radiusr0   Zusphrr   r   r   r      s    
 r   )
deprecated)angle_formats)Zcheck_hms_rangesZdegrees_to_dmsZdegrees_to_stringZdms_to_degreesformat_exceptionZhms_to_degreesZ
hms_to_dmsZhms_to_hoursZhms_to_radiansZhours_to_decimalZhours_to_hmsZhours_to_radiansZhours_to_stringZparse_angleZradians_to_degreesZradians_to_dmsZradians_to_hmsZradians_to_hoursZsexagesimal_to_stringz$astropy.coordinates.angle_utilities.z"astropy.coordinates.angle_formats.zv4.3)nameZalternativeZsince)r   )r   r   )__doc____all__Znumpyr
   Zastropy.unitsZunitsr   Z"astropy.coordinates.representationr   r	   r   r   r   r   r   r   Zastropy.utils.decoratorsr3   Zastropy.coordinatesr4   Z__old_angle_utilities_funcsfuncnamegetattrvarsr   r   r   r   <module>   s(   (B


