B
    q\P                 @   s^   d dl Zd dlmZ d dlmZ d dlmZ d dl	m
Z
mZ dgZdd ZG d	d deZdS )
    N)Polygon)units)UnitSphericalRepresentation)rotation_matrixmatrix_productSphericalCirclec             C   sj   t | |d}tdtj tj |  dd}t| dd}t||}| }||}t 	|}|j
|jfS )a&  
    Given a polygon with vertices defined by (lon, lat), rotate the polygon
    such that the North pole of the spherical coordinates is now at (lon0,
    lat0). Therefore, to end up with a polygon centered on (lon0, lat0), the
    polygon should initially be drawn around the North pole.
    )lonlatg      ?y)Zaxisz)r   r   nppiuradianr   Zto_cartesianZ	transformZfrom_cartesianr   r	   )r   r	   Zlon0Zlat0ZpolygonZm1Zm2Ztransform_matrix r   Dlib/python3.7/site-packages/astropy/visualization/wcsaxes/patches.py_rotate_polygon   s    	


r   c                   s(   e Zd ZdZdejf fdd	Z  ZS )r   a  
    Create a patch representing a spherical circle - that is, a circle that is
    formed of all the points that are within a certain angle of the central
    coordinates on a sphere. Here we assume that latitude goes from -90 to +90

    This class is needed in cases where the user wants to add a circular patch
    to a celestial image, since otherwise the circle will be distorted, because
    a fixed interval in longitude corresponds to a different angle on the sky
    depending on the latitude.

    Parameters
    ----------
    center : tuple or `~astropy.units.Quantity`
        This can be either a tuple of two `~astropy.units.Quantity` objects, or
        a single `~astropy.units.Quantity` array with two elements.
    radius : `~astropy.units.Quantity`
        The radius of the circle
    resolution : int, optional
        The number of points that make up the circle - increase this to get a
        smoother circle.
    vertex_unit : `~astropy.units.Unit`
        The units in which the resulting polygon should be defined - this
        should match the unit that the transformation (e.g. the WCS
        transformation) expects as input.

    Notes
    -----
    Additional keyword arguments are passed to `~matplotlib.patches.Polygon`
    d   c                s   |\}}t ddt j |d d d tj }t dt j |tj |tj }	t||	||\}}	||}|	|}	t ||	g	 }
t
 j|
f| d S )Ng              g      ?)r   Zlinspacer   r   r   repeatZto_valuer   ZarrayZ	transposesuper__init__)selfcenterZradiusZ
resolutionZvertex_unitkwargsZ	longitudeZlatituder   r	   Zvertices)	__class__r   r   r   G   s    &$

zSphericalCircle.__init__)__name__
__module____qualname____doc__r   Zdegreer   __classcell__r   r   )r   r   r   (   s   )Znumpyr   Zmatplotlib.patchesr   Zastropyr   r   Z"astropy.coordinates.representationr   Z$astropy.coordinates.matrix_utilitiesr   r   __all__r   r   r   r   r   r   <module>   s   