o
    h                     @   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   o/var/www/html/construction_image-detection-poc/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vy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   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(   MrMtMr   r   r   _view_transformation_uvwX   s   

r6   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   r1   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   r7   r   r   r   )r8   r9   r<   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 )Nr0   r   r   r   )mask)r   r'   datamaisMAr   rA   )vecr5   vecwr+   txstystzsr   r   r   _proj_transform_vec   s   (
rJ   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 )Nr0   r   r   r   )dtyper1   )r   r'   rB   isinfonesshapeboolrC   rD   rA   masked_array)	rE   r5   r:   rF   r+   rG   rH   rI   tisr   r   r   _proj_transform_vec_clip   s    (
(rR   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   r0   r   Nr   )_vec_pad_onesr   r'   rN   reshaperange)xsyszsinvMrE   vecrir   r   r   inv_transform   s   

(r\   c                 C   sV   t j| st j|st j|rt j| ||t | gS t | ||t | gS N)r   rC   rD   r   	ones_like)rV   rW   rX   r   r   r   rS      s   $rS   c                 C   s   t | ||}t||S )z<
    Transform the points by the projection matrix *M*.
    )rS   rJ   )rV   rW   rX   r5   rE   r   r   r   proj_transform   s   
r_   z3.10c                 C   s   t | |||tjdS )N)r:   )_proj_transform_clipr   inf)rV   rW   rX   r5   r   r   r   proj_transform_clip   s   rb   c                 C   s   t | ||}t|||S )zy
    Transform the points by the projection matrix
    and return the clipping result
    returns txs, tys, tzs, tis
    )rS   rR   )rV   rW   rX   r5   r:   rE   r   r   r   r`      s   r`   c                 C   s   t t| |S r]   )r   column_stack_proj_trans_points)pointsr5   r   r   r   _proj_points   s   rf   c                 C   sL   t | } | d d df | d d df | d d df }}}t||||S )Nr   r   r   )r   
asanyarrayr_   )re   r5   rV   rW   rX   r   r   r   rd      s   
4rd   r]   )__doc__numpyr   
matplotlibr   r   r%   r.   r6   r?   r@   rJ   rR   r\   rS   r_   
deprecatedrb   r`   rf   rd   r   r   r   r   <module>   s(    
'

