a
    SicL  ã                   @   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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Ä   t  |d ¡| d  }t  |d ¡| d  }t  | dd… |dd… k¡rVt  ||¡S |d | d  }|d | d  }|| ||  |d |d   }t  |dd¡}t  |||  |||  ¡}|S )a2  
    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.

    If p1 and p2 are identical, the distance between them and p0 is returned.
    r   é   é   )ÚnpÚasarrayÚallÚhypotÚclip)	Úp1Úp2Úp0Zx01Zy01Zx21Zy21ÚuÚd© r   úW/var/www/html/django/DPS/env/lib/python3.9/site-packages/mpl_toolkits/mplot3d/proj3d.pyÚ_line2d_seg_dist	   s     r   c              	   C   sŽ   ||  }|| }|| }	|durB|\}
}}||
 }|| }|	| }	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.
    Nr   r   ©r   r   r   r   ©r   Úarray)ÚxminÚxmaxÚyminÚymaxÚzminÚzmaxÚ	pb_aspectÚdxÚdyÚdzÚaxZayÚazr   r   r   Ú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   )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   s¸   | | }|t j |¡ }t  ||¡}|t j |¡ }t  ||¡}|dkrlt|| ƒ}t  ||¡}t  ||¡}t  d¡}t  d¡}	|||g|d d…d d…f< |  |	d d…df< t  ||	¡S )Nr   é   é   éÿÿÿÿ)r   r!   r"   Úcrossr-   ÚdotÚeye)
ÚEr,   ÚVÚrollÚnr   r%   ZRrollZMrZMtr   r   r   Úview_transformationK   s    

r8   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   r0   r   r   )ÚzfrontÚzbackÚfocal_lengthÚeÚaÚbr*   Úproj_matrixr   r   r   Úpersp_transformationa   s    
ýrA   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   r9   r   r   r   )r:   r;   r>   r?   r@   r   r   r   Úortho_transformationm   s    



ýrB   c                 C   sF   t  || ¡}|d }|d | |d | |d |   }}}|||fS ©Nr/   r   r   r   )r   r2   )ÚvecÚMÚvecwÚwÚtxsÚtysÚtzsr   r   r   Ú_proj_transform_vecx   s    (rK   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 rC   )r   r2   Úany)rD   rE   rF   rG   rH   rI   rJ   Ztisr   r   r   Ú_proj_transform_vec_clip€   s    (0
rM   c                 C   s\   t  |¡}t| ||ƒ}t ||¡}z||d  }W n tyD   Y n0 |d |d |d fS rC   )r!   ÚinvÚ_vec_pad_onesr   r2   ÚOverflowError)ÚxsÚysÚzsrE   ZiMrD   Zvecrr   r   r   Úinv_transform‹   s    
rT   c                 C   s   t  | ||t  | ¡g¡S ©N)r   r   Ú	ones_like)rQ   rR   rS   r   r   r   rO   –   s    rO   c                 C   s   t | ||ƒ}t||ƒS )z7
    Transform the points by the projection matrix
    )rO   rK   ©rQ   rR   rS   rE   rD   r   r   r   Úproj_transformš   s    rX   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   rM   rW   r   r   r   Úproj_transform_clip¥   s    rY   c                 C   s   t  t| |ƒ¡S rU   )r   Úcolumn_stackÚproj_trans_points)ÚpointsrE   r   r   r   Úproj_points¯   s    r]   c                 C   s   t | Ž \}}}t||||ƒS rU   )ÚziprX   )r\   rE   rQ   rR   rS   r   r   r   r[   ³   s    r[   c                 C   sN   t  |¡t  |¡ }}t  g d¢d|| dgd||dgg d¢g¡}t  || ¡S )N)r   r   r   r   r   r   )r   r$   r#   r   r2   )r5   ÚalphaZcosaZsinaÚM1r   r   r   Úrot_x¸   s    

ýra   )N)Ú__doc__Únumpyr   Únumpy.linalgr!   r   r    r-   r8   rA   rB   rK   rM   rT   rO   rX   Ú	transformrY   r]   r[   ra   r   r   r   r   Ú<module>   s&    þ

