
    ^jN                         d Z ddlZddlm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d Z ej$                  d      d        Zd Zd Zd Zy)z,
Various transforms used for by the 3D code
    N)_apic           	          || 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.
       r   )r   r   r   r   nparray)xminxmaxyminymaxzminzmax	pb_aspectdxdydzaxayazs                T/opt/ringagent/.cad-venv/lib/python3.12/site-packages/mpl_toolkits/mplot3d/proj3d.pyworld_transformationr   
   s     
B	B	B
B
b
b
b88adqQb1AbDQb1q!B$b113 4 4    c                    | t         j                  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   linalgnormsincosr   )	vanglevxvyvzsctRs	            r   _rotation_about_vectorr(       s    RYY^^A&&JBB
uA
uA	"&&q/1
A
	
2b12b2a42b2a48	
2b2a42b12b2a48	
2b2a42b2a42b157 	8A
 Hr   c                 r   | |z
  }|t         j                  j                  |      z  }t        j                  ||      }|t         j                  j                  |      z  }t        j                  ||      }|dk7  r9t	        ||       }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   crossr(   dot)Er'   Vrollwur   Rrolls           r   
_view_axesr2   1   s    0 
QA	"))..
A
AA	"))..
A
AA qy&q4%0FF5!FF5!a7Nr   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   eyer+   )r0   r   r/   r,   MrMtMs          r   _view_transformation_uvwr;   X   s`     
B	BQBrr2A2vJBrr2vJ
r2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   r6   r   r   )zfrontzbackfocal_lengtheabr%   proj_matrixs           r   _persp_transformationrE   o   sw    A	A	u%A
F5L6%<(A((Q!aO!aO!aO+- .K r   c           	      d    | |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   r=   r   r   r   )r>   r?   rB   rC   rD   s        r   _ortho_transformationrG   {   sH    
5.A
5.A((M))AqM+ ,K r   c                 d   d } || |j                         } |||j                        } |||j                        }| ||fD cg c]!  }t        j                  j                  |      # }	}t        d |	D              rt        j                  j                  t        j                  j                  |	d   |	d         |	d         }
t        j                  j                  ||
      }t        j                  j                  ||
      }t        j                  j                  ||
      }|||fS c c}w )z
    Apply axis scale transforms to 3D coordinates.

    Transforms data coordinates to transformed coordinates (applying log,
    symlog, etc.) for 3D projection. Preserves masked arrays.
    c                     t        j                  |       } t         j                  j                  |       j	                         }|j                         j                  |      j                  | j                        S N)	r   
asanyarraymagetdataravelget_transform	transformreshapeshape)coordaxisdatas      r   transform_coordz0_apply_scale_transforms.<locals>.transform_coord   sT    e$uu}}U#))+!!#--d3;;EKKHHr   c              3   T   K   | ]   }|t         j                  j                  u " y wrJ   )r   rL   nomask).0ms     r   	<genexpr>z*_apply_scale_transforms.<locals>.<genexpr>   s     
0Q1BEELL 
0s   &(r   r   r   mask)	xaxisyaxiszaxisr   rL   getmaskanymask_orr   )xsyszsaxesrV   	xs_scaled	ys_scaled	zs_scaledrB   maskscombineds              r   _apply_scale_transformsrm      s    I
  DJJ/IDJJ/IDJJ/I )+B|4!RUU]]14E4

0%
0055==uQxq!BE!HMEEKK	K9	EEKK	K9	EEKK	K9	i** 5s   &D-c                    t        j                  || j                        }|dd |d   z  }t         j                  j	                  |       r+t         j                  j                  || j                        }|d   |d   |d   fS )Nr   r5   r\   r   r   )r   r+   rU   rL   isMAr   r]   )vecr:   vecwtss       r   _proj_transform_vecrs      sl    66!SXXD	a47	B	uuzz#UU[[#(([+a5"Q%Ar   c                 J   | j                   }t        | d   | d   | d   |      \  }}}t        |j                         |j                         |j                               }t	        j
                  |j                  |      }|dd |d   z  }|j                  j                  |      S )z
    Apply scale transforms and project vectors.

    Parameters
    ----------
    vecs : ... x 3 np.ndarray
        Input vectors.
    axes : Axes3D
        The 3D axes (used for scale transforms and projection matrix).
    ).r   ).r   ).r   Nr5   )	rR   rm   _vec_pad_onesrN   r   r+   r:   TrQ   )	vecsrg   result_shaperd   re   rf   rp   producttvecss	            r   _scale_proj_transform_vectorsr{      s     ::L(Vd6lDL$8JBB

BHHJ

;CffTVVS!GBQK'!*$E77??<((r   c                     t        j                  || j                        }|dd |d   z  \  }}}t        j                  |      r&t        j                  |j
                  t              }nd|k  |dk  z  d|k  z  |dk  z  |dk  z  }t         j                  j                  | d         r|| d   j                   z  }t         j                  j                  | d         r|| d   j                   z  }t         j                  j                  | d         r|| d   j                   z  }t         j                  j                  ||       }t         j                  j                  ||       }t         j                  j                  ||       }||||fS )Nr   r5   )dtyper6   r   r   )r   r+   rU   isinfonesrR   boolrL   ro   r]   masked_array)rp   r:   r@   rq   txstystzstiss           r   _proj_transform_vec_clipr      sL   66!SXXD1IQ'MCc	xxggciit,SySAX&")4qASAXN	uuzz#a&SV[[L 	uuzz#a&SV[[L 	uuzz#a&SV[[L 
%%

S3$
'C
%%

S3$
'C
%%

S3$
'CS#r   c                 (   t        | ||      }t        j                  ||      }|j                  dk(  r|j	                  d      }t        |j                  d         D ]'  }|d   |   dk7  s|dd|f   |d   |   z  |dd|f<   ) |d   |d   |d   fS )zO
    Transform the points by the inverse of the projection matrix, *invM*.
    )r4   )r4   r   r   r5   r   Nr   )ru   r   r+   rR   rQ   range)rd   re   rf   invMrp   vecris          r   inv_transformr      s     B
#C66$DzzT||F#4::a=! 171:?add1gaj0DAJ1 7DGT!W$$r   c                    t         j                  j                  |       s>t         j                  j                  |      st         j                  j                  |      r6t         j                  j                  | ||t        j                  |       g      S t        j                  | ||t        j                  |       g      S rJ   )r   rL   ro   r   	ones_like)rd   re   rf   s      r   ru   ru      ss    	uuzz"~B255::b>uu{{BBR(89::xxRR\\"%5677r   c                 4    t        | ||      }t        ||      S )z<
    Transform the points by the projection matrix *M*.
    )ru   rs   rd   re   rf   r:   rp   s        r   proj_transformr      s     B
#CsA&&r   z3.10c                 T    t        | ||      }t        ||t        j                        S )N)r@   )ru   r   r   infr   s        r   proj_transform_clipr      s#    
B
#C#C@@r   c                     t        | |||      \  } }}t        | ||      }t        ||j                  |j                        S )zg
    Apply scale transforms, project, and return clipping result.

    Returns txs, tys, tzs, tis.
    )rm   ru   r   r:   _focal_length)rd   re   rf   rg   rp   s        r   _scale_proj_transform_clipr      sA     )RT:JBB
B
#C#C1C1CDDr   c                 ~    t        j                  |       } | d d df   | d d df   | d d df   }}}t        ||||      S )Nr   r   r   )r   rK   r   )pointsr:   rd   re   rf   s        r   _proj_trans_pointsr      sF    ]]6"F1vad|VAqD\BB"b"a((r   c                 V    t        | |||      \  } }}t        | |||j                        S )z
    Apply scale transforms and project.

    Combines `_apply_scale_transforms` and `proj_transform` into a single
    call. Returns txs, tys, tzs.
    )rm   r   r:   )rd   re   rf   rg   s       r   _scale_proj_transformr     s/     )RT:JBB"b"dff--r   rJ   )__doc__numpyr   
matplotlibr   r   r(   r2   r;   rE   rG   rm   rs   r{   r   r   ru   r   
deprecatedr   r   r   r    r   r   <module>r      s     
 044,"$N.	+6)((%8' A A
E).r   