o
    gô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   úl/var/www/html/academy/tools/voices/clone/sv-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ÚvxZ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   

r2   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   r3   r   r   r   )r4   r5   r8   r9   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=   )Úvecr1   Úvecwr)   ÚtxsÚtysÚtzsr   r   r   Ú_proj_transform_vec†   s   (
rF   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?   r@   r=   Úmasked_array)	rA   r1   r6   rB   r)   rC   rD   rE   Útisr   r   r   Ú_proj_transform_vec_clip“   s    (
(rN   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%   rJ   ÚreshapeÚrange)ÚxsÚysÚzsÚinvMrA   ZvecrÚir   r   r   Úinv_transform¨   s   

(€rW   c                 C   sV   t j | ¡st j |¡st j |¡rt j | ||t  | ¡g¡S t  | ||t  | ¡g¡S ©N)r   r?   r@   r   Ú	ones_like)rR   rS   rT   r   r   r   rO   ¶   s   $rO   c                 C   s   t | ||ƒ}t||ƒS )z<
    Transform the points by the projection matrix *M*.
    )rO   rF   )rR   rS   rT   r1   rA   r   r   r   Úproj_transform½   s   
rZ   z3.10c                 C   s   t | |||tjd�S )N)r6   )Ú_proj_transform_clipr   Úinf)rR   rS   rT   r1   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
    )rO   rN   )rR   rS   rT   r1   r6   rA   r   r   r   r[   Ê   s   r[   c                 C   s   t  t| |ƒ¡S rX   )r   Úcolumn_stackÚ_proj_trans_points)Úpointsr1   r   r   r   Ú_proj_pointsÔ   s   ra   c                 C   sL   t  | ¡} | d d …df | d d …df | d d …df }}}t||||ƒS )Nr   r   r   )r   Ú
asanyarrayrZ   )r`   r1   rR   rS   rT   r   r   r   r_   Ø   s   
4r_   rX   )Ú__doc__Únumpyr   Ú
matplotlibr   r   r#   r+   r2   r;   r<   rF   rN   rW   rO   rZ   Ú
deprecatedr]   r[   ra   r_   r   r   r   r   Ú<module>   s(    
þ'

