o
    ¹iª  ã                   @   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   é   é   )ÚnpÚasarrayÚclipÚhypot)	Úp1Úp2Úp0Úx21Úy21Úx01Úy01ÚuÚd© r   úV/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/mpl_toolkits/mplot3d/proj3d.pyÚ_line2d_seg_dist	   s    r   c              	   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.
    Nr   r   ©r   r   r   r   ©r   Úarray)ÚxminÚxmaxÚyminÚymaxÚzminÚzmaxÚ	pb_aspectÚdxÚdyÚdzÚaxÚ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g d¢g}ddd| d  gddd| d  gddd| d  gg d¢g}t  ||¡S )Nr   r   r   r   )r   ÚlinalgÚnormÚcrossÚdot)ÚEÚRÚVÚnr   ÚvÚMrÚMtr   r   r   Úview_transformation6   s    ýýr0   c                 C   sJ   | | | |  }d| |  | |  }t  g d¢g d¢dd||gg d¢g¡S )Néþÿÿÿ©r   r   r   r   )r   r   r   r   r   )r   r   éÿÿÿÿr   r   ©ÚzfrontÚzbackÚaÚbr   r   r   Úpersp_transformationV   s   

ýr9   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   r1   r   r   r   r4   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   (
rD   c                 C   sŽ   t  || ¡}|d }|d | |d | |d | }}}d|d k|d dk@ d|d k@ |d dk@ }t  |¡rA|d dk }||||fS r;   )r   r(   Úany)r=   r>   r?   r@   rA   rB   rC   Útisr   r   r   Ú_proj_transform_vec_clipq   s   (0
rG   c                 C   s\   t  |¡}t| ||ƒ}t ||¡}z||d  }W n	 ty"   Y nw |d |d |d fS r;   )r%   ÚinvÚ_vec_pad_onesr   r(   ÚOverflowError)ÚxsÚysÚzsr>   ÚiMr=   Úvecrr   r   r   Úinv_transform|   s   
ÿrP   c                 C   s   t  | ||t  | ¡g¡S ©N)r   r   Ú	ones_like)rK   rL   rM   r   r   r   rI   ‡   s   rI   c                 C   ó   t | ||ƒ}t||ƒS )z7
    Transform the points by the projection matrix
    )rI   rD   ©rK   rL   rM   r>   r=   r   r   r   Úproj_transform‹   s   
rU   c                 C   rS   )zy
    Transform the points by the projection matrix
    and return the clipping result
    returns txs, tys, tzs, tis
    )rI   rG   rT   r   r   r   Úproj_transform_clip–   s   
rV   c                 C   s   t  t| |ƒ¡S rQ   )r   Úcolumn_stackÚproj_trans_points)Úpointsr>   r   r   r   Úproj_points    s   rZ   c                 C   s   t | Ž \}}}t||||ƒS rQ   )ÚziprU   )rY   r>   rK   rL   rM   r   r   r   rX   ¤   s   rX   c                 C   sN   t  |¡t  |¡}}t  g d¢d|| dgd||dgg d¢g¡}t  || ¡S )Nr2   r   r   )r   ÚcosÚsinr   r(   )r+   ÚalphaÚcosaÚsinaÚM1r   r   r   Úrot_x©   s   

ýrb   rQ   )Ú__doc__Únumpyr   Únumpy.linalgr%   r   r$   r0   r9   r:   rD   rG   rP   rI   rU   Ú	transformrV   rZ   rX   rb   r   r   r   r   Ú<module>   s&    
þ 	

