§
    ‡Ûg  ã                   óŒ   — d Z ddlZddlmZ d„ Z	 dd„Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ ZeZd„ Zd„ Zd„ Zd„ ZdS )z,
Various transforms used for by the 3D code
é    Nc                 ó,  — t          j        |¦  «        }||z
  }| |z
  }||z  }t          j        ||d¦  «        }|t           j                             t          j        ||z  |z  dd¦  «        |¦  «        z   }| |z
  dz                       d¬¦  «        dz  S )a7  
    Return the distance(s) from point(s) *p* to segment(s) (*s0*, *s1*).

    Parameters
    ----------
    p : (ndim,) or (N, ndim) array-like
        The points from which the distances are computed.
    s0, s1 : (ndim,) or (N, ndim) array-like
        The xy(z...) coordinates of the segment endpoints.
    é   r   é   éÿÿÿÿ)Úaxisg      à?)ÚnpÚasarrayÚwhereÚmultiplyÚouterÚclipÚsum)ÚpÚs0Ús1Ús01Ús0pÚl2Úp1s          úQ/granary/edev/quantum/lib/python3.11/site-packages/mpl_toolkits/mplot3d/proj3d.pyÚ_line2d_seg_distr   	   s—   € õ 
Œ�B‰Œ€BØ
ˆr‰'€CØ
ˆb‰&€CØ	ˆs‰€Bõ 
Œ�"�b˜!Ñ	Ô	€Bà	�bŒk×Ò¥¤¨¨c©	°B©¸¸1Ñ =Ô =¸sÑCÔCÑ	C€BØ�‰V˜‰M×Ò BÐÑ'Ô'¨CÑ0Ð0ó    c           	      óÄ   — || z
  }||z
  }||z
  }	|�|\  }
}}||
z  }||z  }|	|z  }	t          j        d|z  dd|  |z  gdd|z  d| |z  gddd|	z  | |	z  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Úazs                r   Úworld_transformationr*       s®   € ð 
�‰€BØ	�‰€BØ	�‰€BØÐØ‰
ˆˆB�Ø
ˆb‰ˆØ
ˆb‰ˆØ
ˆb‰ˆåŒ8�a˜‘d˜A !¨¨¨b©Ð1Ø˜A˜b™D !¨¨¨b©Ð1Ø˜A ! B¡$¨¨¨b©Ð1Ø*Ð*Ð*ð,ñ -ô -ð -r   c                 óâ  — | t           j                             | ¦  «        z  \  }}}t          j        |¦  «        }t          j        |¦  «        }dt          j        |dz  ¦  «        dz  z  }t          j        ||z  |z  |z   ||z  |z  ||z  z
  ||z  |z  ||z  z   g||z  |z  ||z  z   ||z  |z  |z   ||z  |z  ||z  z
  g||z  |z  ||z  z
  ||z  |z  ||z  z   ||z  |z  |z   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ÚvyÚvzÚsÚcÚtÚRs	            r   Úrotation_about_vectorr9   6   s  € ð •R”Y—^’^ AÑ&Ô&Ñ&�J€BˆˆBÝ
Œˆu‰Œ€AÝ
Œˆu‰Œ€AØ	�"Œ&��q‘‰/Œ/˜1Ñ
Ñ€Aå
ŒØ	
ˆ2‰ˆb‰�1‰˜˜2™˜b™ 2 a¡4™¨¨2©¨b©°2°a±4©Ð8Ø	
ˆ2‰ˆb‰�2�a‘4‰˜˜2™˜b™ 1™¨¨2©¨b©°2°a±4©Ð8Ø	
ˆ2‰ˆb‰�2�a‘4‰˜˜2™˜b™ 2 a¡4™¨¨2©¨b©°1©Ð5ð7ñ 	8ô 	8€Að
 €Hr   c                 ót  — | |z
  }|t           j                             |¦  «        z  }t          j        ||¦  «        }|t           j                             |¦  «        z  }t          j        ||¦  «        }|dk    r;t	          || ¦  «        }t          j        ||¦  «        }t          j        ||¦  «        }|||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-   Úcrossr9   Údot)ÚEr8   ÚVÚrollÚwÚur0   ÚRrolls           r   Ú
_view_axesrC   G   s¤   € ð0 
ˆQ‰€AØ	�"Œ)�.Š.˜Ñ
Ô
Ñ€AÝ
Œ��A‰Œ€AØ	�"Œ)�.Š.˜Ñ
Ô
Ñ€AÝ
Œ��A‰Œ€Að ˆq‚y€yå% a¨$¨Ñ/Ô/ˆÝŒF�5˜!ÑÔˆÝŒF�5˜!ÑÔˆØˆa�ˆ7€Nr   c                 ó°   — t          j        d¦  «        }t          j        d¦  «        }| ||g|dd…dd…f<   | |dd…df<   t          j        ||¦  «        }|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   )r   Úeyer<   )rA   r0   r@   r=   ÚMrÚMtÚMs          r   Ú_view_transformation_uvwrK   n   s`   € õ 
Œ�‰Œ€BÝ	Œ�‰Œ€BØ�Q˜�€B€rˆ€rˆ2ˆAˆ2€v�JØ�€B€rˆ€rˆ2€v�JÝ
Œˆr�2‰Œ€AØ€Hr   c                 óV   — t          | |||¦  «        \  }}}t          |||| ¦  «        }|S )az  
    Return the view transformation matrix.

    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.
    )rC   rK   )r=   r8   r>   r?   rA   r0   r@   rJ   s           r   Úview_transformationrM   …   s5   € õ ˜˜A˜q $Ñ'Ô'�G€A€qˆ!Ý   A q¨!Ñ,Ô,€AØ€Hr   c                 ó’   — |}d}| |z   | |z
  z  }d| |z  z  | |z
  z  }t          j        |dddgd||z  ddgdd||gg d¢g¦  «        }|S )Nr   éþÿÿÿr   )r   r   r   r   r   )ÚzfrontÚzbackÚfocal_lengthÚeÚaÚbr6   Úproj_matrixs           r   Úpersp_transformationrW   ™   s~   € Ø€AØ	€AØ	�‰˜˜u™Ñ%€AØ
ˆF�5‰LÑ˜6 %™<Ñ(€AÝ”(˜Q ! a¨˜OØ  !¡ a¨˜OØ ! a¨˜OØ+˜O˜Oð-ñ .ô .€Kð Ðr   c           	      ób   — | |z    }| |z
   }t          j        g d¢g d¢g d¢dd||gg¦  «        }|S )N)r   r   r   r   )r   r   r   r   )r   r   rO   r   r   r   )rP   rQ   rT   rU   rV   s        r   Úortho_transformationrY   ¥   sW   € à
�5‰.Ð€AØ
�5‰.Ð€AÝ”(˜M˜M˜MØ)˜M˜MØ)˜M˜MØ  A q˜Mð+ñ ,ô ,€Kð Ðr   c                 óˆ   — t          j        || ¦  «        }|d         }|d         |z  |d         |z  |d         |z  }}}|||fS ©NrF   r   r   r   )r   r<   )ÚvecrJ   Úvecwr@   ÚtxsÚtysÚtzss          r   Ú_proj_transform_vecra   °   sK   € ÝŒ6�!�S‰>Œ>€DØˆQŒ€Aà˜”G˜A‘I˜t Aœw q™y¨$¨q¬'°!©)ˆcˆ€CØ��Sˆ=Ðr   c                 ó0  — t          j        || ¦  «        }|d         }|d         |z  |d         |z  |d         |z  }}}d|d         k    |d         dk    z  d|d         k    z  |d         dk    z  }t          j        |¦  «        r|d         dk     }||||fS r[   )r   r<   Úany)r\   rJ   r]   r@   r^   r_   r`   Útiss           r   Ú_proj_transform_vec_clipre   ¸   sŸ   € ÝŒ6�!�S‰>Œ>€DØˆQŒ€Aà˜”G˜a‘K  a¤¨1¡¨d°1¬g¸©kˆcˆ€CØ��Q”Š<˜D œG qšLÑ
)¨Q°$°q´'ª\Ñ
:¸dÀ1¼gÈºlÑ
K€CÝ	„vˆc�{„{ð Ø�1Œg˜ŠkˆØ��S˜#ÐÐr   c                 óÞ   — t          j        |¦  «        }t          | ||¦  «        }t          j        ||¦  «        }	 ||d         z  }n# t
          $ r Y nw xY w|d         |d         |d         fS )zK
    Transform the points by the inverse of the projection matrix *M*.
    rF   r   r   r   )r,   ÚinvÚ_vec_pad_onesr   r<   ÚOverflowError)ÚxsÚysÚzsrJ   ÚiMr\   Úvecrs          r   Úinv_transformro   Ã   s~   € õ 
Œ�A‰Œ€BÝ
˜˜B Ñ
#Ô
#€CÝŒ6�"�c‰?Œ?€DðØ�d˜1”g‰~ˆˆøÝð ð ð Øˆðøøøà�Œ7�D˜”G˜T !œWÐ$Ð$s   ¼A Á
AÁAc                 óV   — t          j        | ||t          j        | ¦  «        g¦  «        S ©N)r   r   Ú	ones_like)rj   rk   rl   s      r   rh   rh   Ñ   s%   € ÝŒ8�R˜˜R¥¤¨bÑ!1Ô!1Ð2Ñ3Ô3Ð3r   c                 óD   — t          | ||¦  «        }t          ||¦  «        S )z<
    Transform the points by the projection matrix *M*.
    )rh   ra   ©rj   rk   rl   rJ   r\   s        r   Úproj_transformru   Õ   s%   € õ ˜˜B Ñ
#Ô
#€CÝ˜s AÑ&Ô&Ð&r   c                 óD   — t          | ||¦  «        }t          ||¦  «        S )zy
    Transform the points by the projection matrix
    and return the clipping result
    returns txs, tys, tzs, tis
    )rh   re   rt   s        r   Úproj_transform_cliprw   à   s%   € õ ˜˜B Ñ
#Ô
#€CÝ# C¨Ñ+Ô+Ð+r   c                 óF   — t          j        t          | |¦  «        ¦  «        S rq   )r   Úcolumn_stackÚproj_trans_points)ÚpointsrJ   s     r   Úproj_pointsr|   ê   s   € ÝŒ?Õ,¨V°QÑ7Ô7Ñ8Ô8Ð8r   c                 ó@   — t          | Ž \  }}}t          ||||¦  «        S rq   )Úzipru   )r{   rJ   rj   rk   rl   s        r   rz   rz   î   s%   € Ý�f��J€BˆˆBÝ˜"˜b " aÑ(Ô(Ð(r   c                 óÆ   — t          j        |¦  «        t          j        |¦  «        }}t          j        g d¢d|| dgd||dgg d¢g¦  «        }t          j        || ¦  «        S )N)r   r   r   r   r   r   )r   r/   r.   r   r<   )r>   ÚalphaÚcosaÚsinaÚM1s        r   Úrot_xr„   ó   sj   € Ý”˜‘”¥¤ u¡¤ˆ$€DÝ	Œ�<�<�<Ø�t˜d˜U AÐ&Ø�t˜T 1Ð%Ø�<�<ð!ñ 
"ô 
"€Bõ Œ6�"�a‰=Œ=Ðr   rq   )Ú__doc__Únumpyr   Únumpy.linalgr,   r   r*   r9   rC   rK   rM   rW   rY   ra   re   ro   rh   ru   Ú	transformrw   r|   rz   r„   © r   r   ú<module>rŠ      sJ  ððð ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ð1ð 1ð 1ð2 04ð-ð -ð -ð -ð,ð ð ð"$ð $ð $ðNð ð ð.ð ð ð(	ð 	ð 	ðð ð ðð ð ðð ð ð%ð %ð %ð4ð 4ð 4ð'ð 'ð 'ð €	ð,ð ,ð ,ð9ð 9ð 9ð)ð )ð )ð
ð ð ð ð r   