o
    lôjÍ  ã                   @   s¢   d Z ddlZddlm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dd„ Zdd„ Ze d¡dd„ ƒZdd„ Zdd „ Zd!d"„ ZdS )$z,
Various transforms used for by the 3D code
é    N)Ú_apic              	   C   sŽ   ||  }|| }|| }	|dur!|\}
}}||
 }|| }|	| }	t  d| dd|  | gdd| d| | gddd|	 | |	 gg d¢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.
    Né   r   )r   r   r   r   ©ÚnpÚarray)ÚxminÚxmaxÚyminÚymaxÚzminÚzmaxÚ	pb_aspectÚdxÚdyÚdzÚaxÚayÚaz© r   ún/var/www/html/academy/tools/voices/clone/cosy-venv/lib/python3.10/site-packages/mpl_toolkits/mplot3d/proj3d.pyÚworld_transformation
   s   
ýr   c           	      C   sê   | t j | ¡ \}}}t  |¡}t  |¡}dt  |d ¡d  }t  || | | || | ||  || | ||  g|| | ||  || | | || | ||  g|| | ||  || | ||  || | | gg¡}|S )zK
    Produce a rotation matrix for an angle in radians about a vector.
    é   )r   ÚlinalgÚnormÚsinÚcosr   )	ÚvÚangleÚvxÚvyZvzÚsÚcÚtÚRr   r   r   Ú_rotation_about_vector    s   

444ýr$   c                 C   sv   | | }|t j |¡ }t  ||¡}|t j |¡ }t  ||¡}|dkr6t|| ƒ}t  ||¡}t  ||¡}|||fS )aŸ  
    Get the unit viewing axes in data coordinates.

    Parameters
    ----------
    E : 3-element numpy array
        The coordinates of the eye/camera.
    R : 3-element numpy array
        The coordinates of the center of the view box.
    V : 3-element numpy array
        Unit vector in the direction of the vertical axis.
    roll : float
        The roll angle in radians.

    Returns
    -------
    u : 3-element numpy array
        Unit vector pointing towards the right of the screen.
    v : 3-element numpy array
        Unit vector pointing towards the top of the screen.
    w : 3-element numpy array
        Unit vector pointing out of the screen.
    r   )r   r   r   Úcrossr$   Údot)ÚEr#   ÚVÚrollÚwÚur   ZRrollr   r   r   Ú
_view_axes1   s   
r,   c                 C   sP   t  d¡}t  d¡}| ||g|dd…dd…f< | |dd…df< t  ||¡}|S )aœ  
    Return the view transformation matrix.

    Parameters
    ----------
    u : 3-element numpy array
        Unit vector pointing towards the right of the screen.
    v : 3-element numpy array
        Unit vector pointing towards the top of the screen.
    w : 3-element numpy array
        Unit vector pointing out of the screen.
    E : 3-element numpy array
        The coordinates of the eye/camera.
    é   Né   éÿÿÿÿ)r   Úeyer&   )r+   r   r*   r'   ÚMrZMtÚMr   r   r   Ú_view_transformation_uvwX   s   

r3   c                 C   sb   |}d}| | | |  }d| |  | |  }t  |dddgd|| ddgdd||gg d¢g¡}|S )Nr   éþÿÿÿr   )r   r   r/   r   r   )ÚzfrontÚzbackÚfocal_lengthÚeÚaÚbr!   Úproj_matrixr   r   r   Ú_persp_transformationo   s   
ýr<   c              	   C   s>   | |  }| |  }t  g d¢g d¢g d¢dd||gg¡}|S )N)r   r   r   r   )r   r   r   r   )r   r   r4   r   r   r   )r5   r6   r9   r:   r;   r   r   r   Ú_ortho_transformation{   s   



ýr=   c                 C   sº   t  || j¡}|d }|d | |d | |d | }}}t j | d ¡r2t jj|| d jd�}t j | d ¡rEt jj|| d jd�}t j | d ¡rXt jj|| d jd�}|||fS )Nr.   r   r   r   )Úmask)r   r&   ÚdataÚmaÚisMAr   r>   )Úvecr2   Úvecwr*   ÚtxsÚtysÚtzsr   r   r   Ú_proj_transform_vec†   s   (
rG   c           	      C   s  t  || j¡}|d }|d | |d | |d | }}}t  |¡r-t j|jtd�}nd|k|dk@ d|k@ |dk@ |dk@ }t j | d ¡rQ|| d j	 @ }t j | d ¡ra|| d j	 @ }t j | d ¡rq|| d j	 @ }t j 
|| ¡}t j 
|| ¡}t j 
|| ¡}||||fS )Nr.   r   r   r   )Údtyper/   )r   r&   r?   ÚisinfÚonesÚshapeÚboolr@   rA   r>   Úmasked_array)	rB   r2   r7   rC   r*   rD   rE   rF   Útisr   r   r   Ú_proj_transform_vec_clip“   s    (
(rO   c                 C   sŽ   t | ||ƒ}t ||¡}|jdkr| d¡}t|jd ƒD ]}|d | dkr;|dd…|f |d |  |dd…|f< q|d |d |d fS )zO
    Transform the points by the inverse of the projection matrix, *invM*.
    )r-   )r-   r   r   r.   r   Nr   )Ú_vec_pad_onesr   r&   rK   ÚreshapeÚrange)ÚxsÚysÚzsÚinvMrB   ZvecrÚir   r   r   Úinv_transform¨   s   

(€rX   c                 C   sV   t j | ¡st j |¡st j |¡rt j | ||t  | ¡g¡S t  | ||t  | ¡g¡S ©N)r   r@   rA   r   Ú	ones_like)rS   rT   rU   r   r   r   rP   ¶   s   $rP   c                 C   s   t | ||ƒ}t||ƒS )z<
    Transform the points by the projection matrix *M*.
    )rP   rG   )rS   rT   rU   r2   rB   r   r   r   Úproj_transform½   s   
r[   z3.10c                 C   s   t | |||tjd�S )N)r7   )Ú_proj_transform_clipr   Úinf)rS   rT   rU   r2   r   r   r   Úproj_transform_clipÅ   s   r^   c                 C   s   t | ||ƒ}t|||ƒS )zy
    Transform the points by the projection matrix
    and return the clipping result
    returns txs, tys, tzs, tis
    )rP   rO   )rS   rT   rU   r2   r7   rB   r   r   r   r\   Ê   s   r\   c                 C   s   t  t| |ƒ¡S rY   )r   Úcolumn_stackÚ_proj_trans_points)Úpointsr2   r   r   r   Ú_proj_pointsÔ   s   rb   c                 C   sL   t  | ¡} | d d …df | d d …df | d d …df }}}t||||ƒS )Nr   r   r   )r   Ú
asanyarrayr[   )ra   r2   rS   rT   rU   r   r   r   r`   Ø   s   
4r`   rY   )Ú__doc__Únumpyr   Ú
matplotlibr   r   r$   r,   r3   r<   r=   rG   rO   rX   rP   r[   Ú
deprecatedr^   r\   rb   r`   r   r   r   r   Ú<module>   s(    
þ'

