B
    Mô`ª  ã               @   s’   d Z ddlZddlmZ dd„ Zddd„Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZeZdd„ Zdd„ Zdd„ Zdd„ ZdS ) z,
Various transforms used for by the 3D code
é    Nc       	      C   sš   |d | d  }|d | d  }t  |d ¡| d  }t  |d ¡| d  }|| ||  |d |d   }t  |dd¡}t  |||  |||  ¡}|S )zâ
    Return the distance(s) from line defined by p1 - p2 to point(s) p0.

    p0[0] = x(s)
    p0[1] = y(s)

    intersection point p = p1 + u*(p2-p1)
    and intersection point lies within segment if u is between 0 and 1
    r   é   é   )ÚnpZasarrayZclipÚhypot)	Úp1Úp2Zp0Zx21Zy21Zx01Zy01ÚuÚd© r
   ú?/tmp/pip-unpacked-wheel-0c1wfn4v/mpl_toolkits/mplot3d/proj3d.pyÚ_line2d_seg_dist	   s     r   c          	   C   s’   ||  }|| }|| }	|dk	rB|\}
}}||
 }|| }|	| }	t  d| dd|  | gdd| d| | gddd|	 | |	 gddddgg¡S )zŸ
    Produce a matrix that scales homogeneous coords in the specified ranges
    to [0, 1], or [0, pb_aspect[i]] if the plotbox aspect ratio is specified.
    Nr   r   )r   Úarray)ZxminZxmaxZyminZymaxZzminZzmaxZ	pb_aspectZdxZdyZdzZaxZayÚazr
   r
   r   Úworld_transformation    s    
r   c             C   sÚ   | | }|t j |¡ }t  ||¡}|t j |¡ }t  ||¡}|d |d |d dg|d |d |d dg|d |d |d dgddddgg}ddd| d  gddd| d  gddd| d  gddddgg}t  ||¡S )Nr   r   r   )r   ÚlinalgZnormZcrossÚdot)ÚEÚRÚVÚnr   ÚvZMrZMtr
   r
   r   Úview_transformation6   s    r   c          	   C   sV   | | | |  }d| |  | |  }t  ddddgddddgdd||gddddgg¡S )Néþÿÿÿr   r   éÿÿÿÿ)r   r   )ÚzfrontÚzbackÚaÚbr
   r
   r   Úpersp_transformationV   s    

r   c          	   C   sF   | |  }| |  }t  ddddgddddgddddgdd||gg¡S )Nr   r   r   )r   r   )r   r   r   r   r
   r
   r   Úortho_transformation_   s    



r   c             C   sF   t  || ¡}|d }|d | |d | |d |   }}}|||fS )Né   r   r   r   )r   r   )ÚvecÚMÚvecwÚwÚtxsÚtysÚtzsr
   r
   r   Ú_proj_transform_veci   s    (r(   c             C   sŽ   t  || ¡}|d }|d | |d | |d |   }}}d|d k|d dk@ d|d k@ |d dk@ }t  |¡r‚|d dk }||||fS )Nr    r   r   r   )r   r   Úany)r!   r"   r#   r$   r%   r&   r'   Ztisr
   r
   r   Ú_proj_transform_vec_clipq   s    (0
r*   c             C   s^   t  |¡}t| ||ƒ}t ||¡}y||d  }W n tk
rF   Y nX |d |d |d fS )Nr    r   r   r   )r   ÚinvÚ_vec_pad_onesr   r   ÚOverflowError)ÚxsÚysÚzsr"   ZiMr!   Zvecrr
   r
   r   Úinv_transform|   s    
r1   c             C   s   t  | ||t  | ¡g¡S )N)r   r   Z	ones_like)r.   r/   r0   r
   r
   r   r,   ‡   s    r,   c             C   s   t | ||ƒ}t||ƒS )z7
    Transform the points by the projection matrix
    )r,   r(   )r.   r/   r0   r"   r!   r
   r
   r   Úproj_transform‹   s    r2   c             C   s   t | ||ƒ}t||ƒS )zy
    Transform the points by the projection matrix
    and return the clipping result
    returns txs, tys, tzs, tis
    )r,   r*   )r.   r/   r0   r"   r!   r
   r
   r   Úproj_transform_clip–   s    r3   c             C   s   t  t| |ƒ¡S )N)r   Zcolumn_stackÚproj_trans_points)Úpointsr"   r
   r
   r   Úproj_points    s    r6   c             C   s   t | Ž \}}}t||||ƒS )N)Úzipr2   )r5   r"   r.   r/   r0   r
   r
   r   r4   ¤   s    r4   c          	   C   sV   t  |¡t  |¡ }}t  ddddgd|| dgd||dgddddgg¡}t  || ¡S )Nr   r   )r   ÚcosÚsinr   r   )r   ÚalphaZcosaZsinaZM1r
   r
   r   Úrot_x©   s    
r;   )N)Ú__doc__Znumpyr   Znumpy.linalgr   r   r   r   r   r   r(   r*   r1   r,   r2   Z	transformr3   r6   r4   r;   r
   r
   r
   r   Ú<module>   s"   
 	

