B
    ™‘[T  ã               @   sh   d dl mZ d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ G dd	„ d	eƒZd
S )é    )Úrange)ÚBasic)ÚVector)Ú
CoordSys3D)Ú_path)ÚSymbol)Úcacheitc                   sV   e Zd ZdZejdf‡ fdd„	Zedd„ ƒZdd„ Z	d	d
„ Z
ddd„ZeZeZ‡  ZS )ÚPointz*
    Represents a point in 3-D space.
    Nc                s´   t |ƒ}t|tƒs"tdt|ƒ ƒ‚t|tƒsD|d k	rDtdt|ƒ ƒ‚|d krftt| ƒ | t|ƒ|¡}ntt| ƒ | t|ƒ||¡}||_	||_
|d kr¢d |_||_n||_|j|_|S )Nz0position should be an instance of Vector, not %sz3parent_point should be an instance of Point, not %s)ÚstrÚ
isinstancer   Ú	TypeErrorÚtyper	   ÚsuperÚ__new__r   Ú_nameÚ_posÚ_parentZ_root)ÚclsÚnameÚpositionZparent_pointÚobj)Ú	__class__© ú1lib/python3.7/site-packages/sympy/vector/point.pyr      s,    



zPoint.__new__c             C   sÒ   t |tƒs$t |tƒs$tt|ƒd ƒ‚t |tƒr4|j}|| krBtjS || jkrR| j	S |j| krfd|j	 S t
| |ƒ\}}tj}d}xt|ƒD ]}||| j	7 }qˆW |d7 }x&|t|ƒk rÌ||| j	8 }|d7 }q¨W |S )aS  
        Returns the position vector of this Point with respect to
        another Point/CoordSys3D.

        Parameters
        ==========

        other : Point/CoordSys3D
            If other is a Point, the position of this Point wrt it is
            returned. If its an instance of CoordSyRect, the position
            wrt its origin is returned.

        Examples
        ========

        >>> from sympy.vector import Point, CoordSys3D
        >>> N = CoordSys3D('N')
        >>> p1 = N.origin.locate_new('p1', 10 * N.i)
        >>> N.origin.position_wrt(p1)
        (-10)*N.i

        zis not a Point or CoordSys3Déÿÿÿÿé   é   )r   r	   r   r   r
   Úoriginr   Úzeror   r   r   r   Úlen)ÚselfÚotherZ	rootindexÚpathÚresultÚir   r   r   Úposition_wrt-   s,    





zPoint.position_wrtc             C   s   t ||| ƒS )ap  
        Returns a new Point located at the given position wrt this
        Point.
        Thus, the position vector of the new Point wrt this one will
        be equal to the given 'position' parameter.

        Parameters
        ==========

        name : str
            Name of the new point

        position : Vector
            The position vector of the new Point wrt this one

        Examples
        ========

        >>> from sympy.vector import Point, CoordSys3D
        >>> N = CoordSys3D('N')
        >>> p1 = N.origin.locate_new('p1', 10 * N.i)
        >>> p1.position_wrt(N.origin)
        10*N.i

        )r	   )r    r   r   r   r   r   Ú
locate_new_   s    zPoint.locate_newc             C   s   |   |j¡}t| |¡ƒS )aH  
        Returns the Cartesian/rectangular coordinates of this point
        wrt the origin of the given CoordSys3D instance.

        Parameters
        ==========

        coordinate_system : CoordSys3D
            The coordinate system to express the coordinates of this
            Point in.

        Examples
        ========

        >>> from sympy.vector import Point, CoordSys3D
        >>> N = CoordSys3D('N')
        >>> p1 = N.origin.locate_new('p1', 10 * N.i)
        >>> p2 = p1.locate_new('p2', 5 * N.j)
        >>> p2.express_coordinates(N)
        (10, 5, 0)

        )r%   r   ÚtupleZ	to_matrix)r    Zcoordinate_systemZpos_vectr   r   r   Úexpress_coordinates{   s    zPoint.express_coordinatesc             C   s   | j S )N)r   )r    Zprinterr   r   r   Ú__str__˜   s    zPoint.__str__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r%   r&   r(   r)   Ú__repr__Z	_sympystrÚ__classcell__r   r   )r   r   r	   
   s   2
r	   N)Zsympy.core.compatibilityr   Zsympy.core.basicr   Zsympy.vector.vectorr   Zsympy.vector.coordsysrectr   Zsympy.vector.functionsr   Zsympyr   Zsympy.core.cacher   r	   r   r   r   r   Ú<module>   s   