
    l0j                     ~   d Z ddlZddlZddlZddlmZmZmZm	Z	 ddlm
Z ddlmZ ddlmZmZ ddlmZmZmZ dd	lmZ dd
lmZmZmZmZmZmZ 	 ddlmZ ddl m!Z" n2# e#$ r*Z$ ej%        e$          Z ej%        e$          Z"Y dZ$[$ndZ$[$ww xY w ed          Z&d e	j'        d          fd e	j'        d          fd e	j'        d          fgZ(	 	 	 dWdedee         dee         dee         def
dZ)	 dXdddedee         defdZ*	 	 	 	 dYdddedee         d e+d!e+d"ee         defd#Z,d$ed%edefd&Z-	 dXd'ed(ededee         def
d)Z.	 dZd*ee/         d+ee/         fd,Z0defd-Z1	 	 	 dWd.ee         dee         d/ee         fd0Z2defd1Z3d[d4ed5efd6Z4	 	 	 d\d5ed7ee         dee         defd8Z5	 	 	 	 d]ded5ed7ee         dee         fd9Z6	 	 dZd5ededee         dee         def
d:Z7	 	 	 	 d^d5edee         dee         d;ee         dee         f
d<Z8	 	 	 	 d^d=ed>edee         dee         dee         d;ee         fd?Z9d;efd@Z:d_dBefdCZ;	 	 	 	 	 d`dEedee         dFee         dGee         dHee         f
dIZ<	 dadKedEee         fdLZ=	 	 dZdMedNee         dOee         fdPZ>	 	 	 dbdRedSedTedUedee         f
dVZ?dS )czP
creation.py
--------------

Create meshes from primitives, or with operations.
    N   )
exceptionsgrouping	trianglesutil)transformations)Trimesh)logtol)align_vectorsfaces_to_edgesplane_transform)get_json)	ArrayLikeDictIntegerNDArrayNumberOptional)Polygon)loadszcreation.jsonearcutmapbox_earcutmanifold
manifold3dtriangle
linestringanglesections	transformreturnc           	         t          j        | t           j                  } t          | j                  dk    s| j        d         dk    rt          d          |t           j        dz  }d}n$t          j        |t           j        dz  d	          }|"t          |t           j        dz  z  d
z            }|dz  }t          j
        d||          }t          j        t          j        |          t          j        |          f          }t          |           }| dddf         }	| dddf         }
t          j        t          j        |d|f                              d          t          j        |	t          |                                        d          z  t          j        |
t          |                    f          }|rAt           j        r*t          j        |d|         || d         d	          sJ |d|          }|t'          j        ||          }t          |          dz
  }t          j        d|dd||dz   g          }t          j        ||                              d          }|t          j        t          j        |          d          j                            d          z  }|t1          j        ||                   t           j        k             }t          j        t          j        |          |z  t          |          df          j                            d          }t          j        |                                |                              d          }t           j        r;t          j        |                    d|j        d         df          |z
  d          sJ ||z   t          |          z  }t9          d||d|}t           j        rXt          j        |	ddg         d          s!t          j        | d         | d                   r|sJ |j        sJ |j        dk    sJ |S )a  
    Revolve a 2D line string around the 2D Y axis, with a result with
    the 2D Y axis pointing along the 3D Z axis.

    This function is intended to handle the complexity of indexing
    and is intended to be used to create all radially symmetric primitives,
    eventually including cylinders, annular cylinders, capsules, cones,
    and UV spheres.

    Note that if your linestring is closed, it needs to be counterclockwise
    if you would like face winding and normals facing outwards.

    Parameters
    -------------
    linestring : (n, 2) float
      Lines in 2D which will be revolved
    angle : None or float
      Angle in radians to revolve curve by
    sections : None or int
      Number of sections result should have
      If not specified default is 32 per revolution
    transform : None or (4, 4) float
      Transform to apply to mesh after construction
    **kwargs : dict
      Passed to Trimesh constructor

    Returns
    --------------
    revolved : Trimesh
      Mesh representing revolved result
    dtype   r   zlinestring must be 2D!N       @Tg|=)atol    r   r%   r*   r   g:0yE>r*      )r%   r   r*   r-   verticesfaces         )np
asanyarrayfloat64lenshape
ValueErrorpir   iscloseintlinspacecolumn_stackcossintilereshaper   strictallclosetftransform_pointsarrayarangeTr   areamergeravelr	   	is_volume
body_count)r   r   r   r    kwargsclosedthetapointsperradiusheightr/   slicesquadsingleoffsetstackedr0   meshs                      S/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/trimesh/creation.pyrevolver\   )   s   L z<<<J :!!Z%5a%8A%=%=1222} eRUQYU;;;u	*R/00 MHK5(++E _bfUmmRVE]];<<F j//C1F1FGFQH%%--g66gfc&kk**227;;<GFCKK((	
 H  #: 	M=$3$3$%%tLLLLLL EcTE?&x;; ZZ!^F 8QQ3a011DWT3''00F
bgbinnf--/77@@@F IN8F#344sy@AF
 WRYv&&,s6{{A.>??AII'RRFgfllnnf--55g>>G
z R{7??BQ+CDDvMqQQQQQ vX.E <HE<<V<<D z $
FAr7OS))$-/[A
SU-W-W$ v~~!####K    polygonr   rT   c                 H    t          | fi |\  }}t          d||||d|}|S )a  
    Extrude a 2D shapely polygon into a 3D mesh

    Parameters
    ----------
    polygon : shapely.geometry.Polygon
      2D geometry to extrude
    height : float
      Distance to extrude polygon along Z
    transform : None or (4, 4) float
      Transform to apply to mesh after construction
    triangle_args : str or None
      Passed to triangle
    **kwargs : dict
      Passed to `triangulate_polygon`

    Returns
    ----------
    mesh : trimesh.Trimesh
      Resulting extrusion as watertight body
    )r/   r0   rT   r    r2   )triangulate_polygonextrude_triangulation)r^   rT   r    rN   r/   r0   rZ   s          r[   extrude_polygonrb      sN    2 *'<<V<<OHe  v NT D Kr]   TpathanglescapconnectrN   c                   )* t          j        |t           j                  }t          j        |d          st          d          |Nt          j        |t           j                  }|j        t          |          fk    rt          |j                  n-t          j        t          |          t           j                  }t           j	        
                    |d         |d         z
            t          j        k     }t          | fi |\  }}	t          |	          }
t          j        t          j        |
d          d	          }t          j        |
|                             d          d
          \  }}t          j        ||         t          j        t          |                    t          j        t          |                    f          *|                    d          }t          j        |dd         |dd         z
            }t          j        |dd         |dd         z             }t          j        |d         g||d         ggd          }|r5|r3t          j        |ddg                             d                    |d<   |j        |j        k    sJ t          j        |          j        \  }}t          j        |          t          j        |          }}t          j        |          t          j        |          }}t          j        |          t          j        |          }}t          j        t          |                    }t          j        t          |                    }t          j        | |z  |z  ||z  z   ||z  ||z  |z  z   ||z  |dddf         | |z  |z  ||z  z
  | |z  ||z  |z  z   ||z  |dddf         ||z  | |z  ||dddf         ||||g                              d          }t          j        rMt=          ||          D ]<\  }}t?          j         g dg|d          d         }t          j!        ||          sJ =t          j        *fd|D             d          ddddf         } t          |          }!||!z   }"t          j        ||"ddddf         |"dddddf         |ddddf         g                              d          ))fdt          j"        t          |          dz
            |!z  D             }#|r3|r1t          |          dz
  |!z  }$| d|$         } |#dxx         |$z  cc<   n|r	tG          |          $                    |	%                                          }%t          |%          dk    rtM          d          t          j        |'                                dz   t           j(                  }&t          j"        t          |                    |&|<   |&|	         }'|#)                    t          j*        |'                     |#)                    |'|!t          |          dz
  z  z              |i }d|vrd|d<   t          j        |#d          }#tW          d| |#d|}(t          j        rYt          t          j        |#                    t          |           k    sJ |r	|(j,        sJ |r|r|(j,        sJ |(j-        dk    sJ |(S )a9  
    Extrude a 2D polygon into a 3D mesh along a 3D path. Note that this
    does *not* handle the case where there is very sharp curvature leading
    the polygon to intersect the plane of a previous slice, and does *not*
    scale the polygon along the induced normal to result in a constant cross section.

    You may want to resample your path with a B-spline, i.e:
      `trimesh.path.simplify.resample_spline(path, smooth=0.2, count=100)`

    Parameters
    ----------
    polygon : shapely.geometry.Polygon
      Profile to sweep along path
    path : (n, 3) float
      A path in 3D
    angles : (n,) float
      Optional rotation angle relative to prior vertex
      at each vertex.
    cap
      If an open path is passed apply a cap to both ends.
    connect
      If a closed path is passed connect the sweep into
      a single watertight mesh.
    kwargs : dict
      Passed to the mesh constructor.
    **triangulation
      Passed to `triangulate_polygon`, i.e. `engine='triangle'`

    Returns
    -------
    mesh : trimesh.Trimesh
      Geometry of result
    r#   r,   zPath must be (n, 3)!Nr   r*   r   axisrequire_countT)return_inverser)   r%   )r*      rm   )r1   r1         ?F)	translatec                 D    g | ]}t          j        |j                  S r2   )r3   dotrH   ).0matrixvertices_tfs     r[   
<listcomp>z!sweep_polygon.<locals>.<listcomp>i  s'    @@@6VX	&	&@@@r]   r-   c                     g | ]}|z   S r2   r2   )rr   rX   faces_slices     r[   ru   z!sweep_polygon.<locals>.<listcomp>t  s    RRRf[6!RRRr]   z.triangulation added vertices: no logic to cap!processr.   r2   ).r3   r4   r5   r   is_shaper8   r7   r6   zeroslinalgnormr   rJ   r`   r   r   
group_rowssortuniquerA   r=   onesunitizeconcatenatemeanvector_to_sphericalrH   r>   r?   rB   ziprD   rE   rC   rG   set
differencerK   NotImplementedErrormaxint64appendfliplrr	   rL   rM   )+r^   rc   rd   re   rf   rN   triangulationrO   vertices_2Dfaces_2Dedgesedges_uniquer   inverseboundaryvectorvector_meannormalrP   phi	cos_theta	sin_thetacos_phisin_phicos_rollsin_rollrz   r   
transformsnrs   checkvertices_3Dstrideboundary_nextr0   
max_vertex
unconsumedmappedcap_zerorZ   rw   rt   s+                                            @@r[   sweep_polygonr      s+   V =RZ000D=w'' 1/000vRZ888<CII<''V\*** ( #d))2:666 Y^^DGd2h.//#);F/II=IIK 8$$E &rwu1'='='=QOOOLil 3 ; ;B ? ?PTUUUOFG /	V	bhs6{{33RWS[[5I5IJ K w''H \$qrr(T#2#Y.//F,vabbzF3B3K788K^fQi[+r
|D1MMMF ?' ?LB!5!51!5!=!=>>q	 <4:%%%% )&113JE3 6%=="&--yIvc{{BF3KKWGhH HSZZ  E73u::D I)+i(.BBy 7X#5	#AAiAJI	!G+h.BBI	!I$7($BBiAJhHxAJ!	
 & gj' * z )VZ00 	) 	)IAv'(96USSSTUVE;ua(((((( .@@@@Z@@@q  aa!eK
 [[Fv%M/	=BQB'qqq$$B$w)?!!!QRR%Q gg 
 SRRR	#d))a-0H0H60QRRRE  :' :$ii!mv-
!+:+.b			Z					 :
 [[++HNN,<,<==
z??Q%&VWWW &**,,*"(;;;3v;;//v (#RYx(()))X#d))a- 88999~ "y N5q)))E ?Ku????D
z 
(29U##$$K(8(88888 	">!!> 	(g 	(>!!>?a''''Kr]   abc                 h    | dddf         |dddf         z  | dddf         |dddf         z  z
  S )z<
    Numpy 2.0 depreciated cross products of 2D arrays.
    Nr   r   r2   )r   r   s     r[   	_cross_2dr     sI     QQQT7Qqqq!tWqAw111a4000r]   r/   r0   c           
      :   t          j        | t           j                  } t          |          }t          j        |t           j                  }t          j        | d          st          d          t          j        |d          st          d          t          j        |          t          j
        k     rt          d          t          t          j        | |dddd	f         j                  t          j        | |ddd
df         j                            }t          |          dk    rPt          j        |                                          t          j        |          k    rt          j        |          }t%          |          }t          j        |d
          }t)          j        |d
          }| ||                  }	t          j        |	                    d          d	                              d          }
t          j        |
t          j        d|d|gt          |	                    f          }
t          j        g dt          |	          d
f          }|t          j        t          |	                                        d          dz  z  }|                    d          }t          j        |           }|dddddf         |                                |g}||                                dd|gz   |
g}t          j        ||          \  } }|Ot;          j        | |          } t;          j        |          r&t          j         t          j        |                    }tC          d| |d|}t          j"        r|j#        dk    sJ |S )a  
    Extrude a 2D triangulation into a watertight mesh.

    Parameters
    ----------
    vertices : (n, 2) float
      2D vertices
    faces : (m, 3) int
      Triangle indexes of vertices
    height : float
      Distance to extrude triangulation
    transform : None or (4, 4) float
      Transform to apply to mesh after construction
    **kwargs : dict
      Passed to Trimesh constructor

    Returns
    ---------
    mesh : trimesh.Trimesh
      Mesh created from extrusion
    r#   r)   zVertices must be (n,2)r,   zFaces must be (n,3)zHeight must be nonzero!N
   r%   r   r   rh   rj   )r-   r   r%   r%   r   r   r+   rm   r*   r1   r.   r2   )$r3   r4   r5   floatr   r   ry   r8   absr   rJ   r   subtractrH   r6   signr   r   r   r~   r   r}   r@   rA   r=   rG   stack_3Dcopyappend_facesrD   rE   flips_windingascontiguousarrayr	   rB   volume)r/   r0   rT   r    rN   signsr   edges_sortedr   r   verticalvertical_facesr   	faces_seqvertices_seqrZ   s                   r[   ra   ra     sD   8 }XRZ888H6]]FM%rx000E=7++ 31222=(( 0.///	vf~~	!!2333 
XeCRC!Gn./0"+xcrcSTSUSUgHX?Y2Z E 5zzA~~"'%**,,//276??BB	%   5!!E75q)))L &|1EEEL l+,H wx''00!44<<WEEH"'1fa2H#h--*X*XYZZHW///#h--1CDDNbiH..66w??!CCN#++G44N -))K qqq$$B$w~>I!1!1!3!3sAv6F!FQL 'i@@OHe&x;; I&& 	;(5)9)9::E<HE<<V<<D
z !{S    Kr]   triangle_argsenginec                    |t          d t          D             d          }| | j        rg g fS |dk    rddlm} t          j        | j        j                  g}|	                    d | j
        D                        t          j        d |D                       }t          j        |          } |||                              d                              t
          j                                      d          }||fS |d	k    rddl}t          j        | j        j                  dd| j        j        rd
nd         dd         g}|	                    d | j
        D                        |                    |          }t          j        |          }||fS |dk    r5ddlm}	 |d}t)          |           }
 |	|
|          }|d         |d         fS t+          j        d           t/          d          )a  
    Given a shapely polygon create a triangulation using a
    python interface to the permissively licensed `mapbox-earcut`
    or the more robust `triangle.c`.
    > pip install manifold3d
    > pip install triangle
    > pip install mapbox_earcut

    Parameters
    ---------
    polygon : Shapely.geometry.Polygon
        Polygon object to be triangulated.
    triangle_args : str or None
        Passed to triangle.triangulate i.e: 'p', 'pq30', 'pY'="don't insert vert"
    engine : None or str
      None or 'earcut' will use earcut, 'triangle' will use triangle

    Returns
    --------------
    vertices : (n, 2) float
       Points in space
    faces : (n, 3) int
       Index of vertices that make up triangles
    Nc              3   $   K   | ]\  }}||V  d S Nr2   )rr   nameexistss      r[   	<genexpr>z&triangulate_polygon.<locals>.<genexpr>3  s+      CCfFCtCCCCCCr]   r   r   )triangulate_float64c              3   H   K   | ]}t          j        |j                  V  d S r   )r3   rF   coords)rr   is     r[   r   z&triangulate_polygon.<locals>.<genexpr>>  s.      FFq**FFFFFFr]   c                 ,    g | ]}t          |          S r2   )r6   )rr   vs     r[   ru   z'triangulate_polygon.<locals>.<listcomp>@  s    444a3q66444r]   r,   r   r   r*   c              3   |   K   | ]7}t          j        |j                  d d |j        rdnd         d d         V  8d S )Nr*   r   )r3   rF   r   is_ccw)rr   r   s     r[   r   z&triangulate_polygon.<locals>.<genexpr>W  sa       
 
DEBHQX99#822q9:3B3?
 
 
 
 
 
r]   r   )triangulatepr/   r   ztry running `pip install manifold3d`or `triangle`, `mapbox_earcut`, then explicitly pass:
`triangulate_polygon(*args, engine="triangle")`
to use the non-FSF-approved-license triangle enginez"No available triangulation engine!)next_enginesis_emptyr   r   r3   rF   exteriorr   extend	interiorscumsumvstackrA   astyper   r   r   r   r   _polygon_to_kwargsr
   warningr8   )r^   r   r   rN   r   r/   ringsr0   r   r   argresults               r[   r`   r`     sZ   8 ~CCCCCTJJ'*2v555555 HW-4556FFG4EFFFFFF	448444559X&&  %00WWVBHWW	 	 	:		 HW%,--.W.Ww7G7N2V!!TV.WX
 	 
 
IPIZ
 
 
 	
 	
 	
 &&u--9U##	:		((((((  M ))S-00j!6+#666K	@   9
:
::r]   c                    | j         st          d          d fd}t          j                    t          j                    t          j                     || j        d          }| j        D ]6}	 | |||          z  }# t          $ r t          j        d           Y 3w xY wt          j
                  t          j
                                                  j        d         dk    rdddd	f         d
}t          j                  dd         t                    dk    r|d<   |S )a  
    Given a shapely polygon generate the data to pass to
    the triangle mesh generator

    Parameters
    ---------
    polygon : Shapely.geometry.Polygon
      Input geometry

    Returns
    --------
    result : dict
      Has keys: vertices, segments, holes
    zinvalid shapely polygon passed!c                 B   t          j        t          j        | | |z                                 d          d          }|                    d          dd                             d          }t          j        ||d         d         |d         d         gf          }|S )z
        Given a start index and length, create a series of (n, 2) edges which
        create a closed traversal.

        Examples
        ---------
        start, length = 0, 3
        returns:  [(0,1), (1,2), (2,0)]
        r+   r%   r*   r   r)   r   )r3   r@   rG   rA   r   )startlengthtileds      r[   
round_tripz&_polygon_to_kwargs.<locals>.round_trip  s     	%88@@II1MMb!!!B$'//88	559R=%(1+">?@@r]   c                    t          j        | j                  }t          j        t	          j        |          d                   }||         }	                    |                                |t          |                               t          |          }                    t          j        |	                                j                  d                    t          |          S )Nr   )
r3   rF   r   r~   r   unique_rowsr   r6   r   representative_point)
r   r   r   r   cleanedtestfacetsholesr   r/   s
         r[   add_boundaryz(_polygon_to_kwargs.<locals>.add_boundary  s    
 (/** -f55a899.   jjG55666 wRXd7799@AA!DEEE7||r]   r   zinvalid interior, continuingr   r-   Nr%   )r/   segmentsr   )is_validr8   collectionsdequer   r   BaseExceptionr
   r   r3   r   tolistr7   rF   r6   )	r^   r   r   interiorr   r   r   r   r/   s	        @@@@r[   r   r   s  s      <:;;;         2  ""H  FEL)1--E%  	\\(E222EE 	 	 	K6777H	 y""HYv%%''F ~aAAAArrE?"77F HUOOABBE
5zzA~~wMs   :B

B+*B+extentsboundsc                    t          j        t          d         d         dt           j                  }t          j        t          d         d         dt           j                  }t          j        t          d         d         dt           j                  }|t|| t          d          t          j        |t           j        	          }|j        d
k    rt          d          t          j        |d          } || z  }||d         z  }nl| Et          j        | t           j        	          } | j        dk    rt          d          |dz  }|| z  }n%|dz  }t          j	        dt           j        	          } d|vri |d<   |d         
                    d| d           t          d|||dd|}||                    |           |S )a  
    Return a cuboid.

    Parameters
    ------------
    extents : (3,) float
      Edge lengths
    transform: (4, 4) float
      Transformation matrix
    bounds : None or (2, 3) float
      Corners of AABB, overrides extents and transform.
    **kwargs:
        passed to Trimesh to create box

    Returns
    ------------
    geometry : trimesh.Trimesh
      Mesh of a cuboid
    boxr/   C)orderr$   r0   face_normalsNz)`bounds` overrides `extents`/`transform`!r#   r%   r-   z`bounds` must be (2, 3) float!r   rh   )r-   zExtents must be (3,)!      ?)rn   rn   rn   metadata)r7   r   F)r/   r0   r   rx   r2   )r3   rF   _datar5   r   r8   r7   ptpr4   asarrayupdater	   apply_transform)r   r    r   rN   r/   r0   r   r   s           r[   r   r     s   4 xeZ02:NNNHHU5\'*#RXFFFE8E%L82:VVVL  G$7HIII&
333<6!!=>>>&a(((GF1I		-rz:::=D  4555CGC*_BJ???z
:'BBCCC
 \5 TZ C
 I&&&Jr]   c            	         t          j        t          d         d         t           j                  }t          j        t          d         d         t           j                  }t          d|||                     dd          d| S )	a  
    Create an icosahedron, one of the platonic solids which is has 20 faces.

    Parameters
    ------------
    kwargs : dict
      Passed through to `Trimesh` constructor.

    Returns
    -------------
    ico : trimesh.Trimesh
      Icosahederon centered at the origin.
    icosahedronr/   r#   r0   rx   Fr/   r0   rx   r2   )r3   rF   r   r5   r   r	   pop)rN   r/   r0   s      r[   r  r    s}     xm,Z8
KKKHHU=)'2"(CCCE 

9e0L0L PV  r]   r-   rn   subdivisionsrS   c           
      d   t          |          }t          |           } t                      }d|_        t	          |           D ]}|                                }|j        }t          j        t          j	        |dz  g d                    }||
                    d          z  }|xj        |||z
  
                    d          z  z  c_        | dk    rt|j        }t          j        t          j	        |dz  g d                    }||
                    d          z  }|xj        |||z
  
                    d          z  z  c_        d|v r4t          j        dt          d           |                    d          |d	<   t          d|j        |j        d
|d|                    dd          d|S )a  
    Create an isophere centered at the origin.

    Parameters
    ----------
    subdivisions : int
      How many times to subdivide the mesh.
      Note that the number of faces will grow as function of
      4 ** subdivisions, so you probably want to keep this under ~5
    radius : float
      Desired radius of sphere
    kwargs : dict
      Passed through to `Trimesh` constructor.

    Returns
    ---------
    ico : trimesh.Trimesh
      Meshed sphere
    Fr%   )r   r   r   r+   r   colorz`icosphere(color=...)` is deprecated and will be removed in June 2024: replace with Trimesh constructor kewyword argument `icosphere(face_colors=...)`)category
stacklevelface_colorsspherer7   rS   rx   )r/   r0   r   rx   r2   )r   r;   r  	_validaterange	subdivider/   r3   sqrtrq   rA   warningswarnDeprecationWarningr  r	   r0   )r  rS   rN   ico_vectorsscalarunits           r[   	icospherer  &  s   ( 6]]F|$$L
--CCM<   B Bmmoo,
III667700088AAAA q,
III667700088AAAA&? (	
 	
 	
 	
 !'

7 3 3} i#v66

9e,,	 
   r]   countc           	         |#t          j        ddgt           j                  }nHt          j        |t           j                  }|t          j        |d          z  }|dxx         dz  cc<   t          j        dt           j        |d         	          }t          j        t          j        |          t          j        |           f          | z  }t          d||d         |d
| dd|S )a  
    Create a UV sphere (latitude + longitude) centered at the
    origin. Roughly one order of magnitude faster than an
    icosphere but slightly uglier.

    Parameters
    ----------
    radius : float
      Radius of sphere
    count : (2,) int
      Number of latitude and longitude lines
    transform : None or (4, 4) float
      Transform to apply to mesh after construction
    kwargs : dict
      Passed thgrough
    Returns
    ----------
    mesh : trimesh.Trimesh
       Mesh of UV sphere with specified parameters
    Nr(   @   r#   r%   r   r1   r   )numr  r  )r   r   r    r   r2   )
r3   rF   r   modr<   r9   r=   r?   r>   r\   )rS   r  r    rN   rP   r   s         r[   	uv_spherer!  a  s    8 }"b222bh///q!!!aA KRUa111E"&--"&--!@AAFJJ  q#v66	 
   r]   c           	         |#t          j        ddgt           j                  }n t          j        |t           j                  }|t          j        |d          z  }t	          t          |                     } t	          t          |                    }t          j        t           j         dz  t           j        dz  |d                   }t          j        t          j	        |          t          j
        |          f          |z  }t          |          dz  }|d|         dddfxx         | dz  z  cc<   ||d         dddfxx         | dz  z  cc<   t          ||d         |d	| |d
          S )az  
    Create a mesh of a capsule, or a cylinder with hemispheric ends.

    Parameters
    ----------
    height : float
      Center to center distance of two spheres
    radius : float
      Radius of the cylinder and hemispheres
    count : (2,) int
      Number of sections on latitude and longitude
    transform : None or (4, 4) float
      Transform to apply to mesh after construction
    Returns
    ----------
    capsule : trimesh.Trimesh
      Capsule geometry with:
        - cylinder axis is along Z
        - one hemisphere is centered at the origin
        - other hemisphere is centered along the Z axis at height
    Nr(   r  r#   r%   r&   r   r   capsuler7   rT   rS   )r   r    r   )r3   rF   r   r   r   r   r<   r9   r=   r>   r?   r6   r\   )rT   rS   r  r    rP   r   halfs          r[   r#  r#    sl   6 }"b222bh///	RVE1EvFvF Kbeck58<<E"&--!?@@6IJ z??aDuuaaadv|+tuuaaadv|+q$&II	   r]   c                     ddg| dgd|gg}d|vri |d<   |d                              d| |d           t          d|||d|}|S )a  
    Create a mesh of a cone along Z centered at the origin.

    Parameters
    ----------
    radius : float
      The radius of the cylinder
    height : float
      The height of the cylinder
    sections : int or None
      How many pie wedges per revolution
    transform : (4, 4) float or None
      Transform to apply after creation
    **kwargs : dict
      Passed to Trimesh constructor

    Returns
    ----------
    cone: trimesh.Trimesh
      Resulting mesh of a cone
    r   r   cone)r7   rS   rT   r   r   r    r2   )r  r\   )rS   rT   r   r    rN   r   r'  s          r[   r'  r'    s    : a&61+6{3Jz
:&FSSTTT I IO D Kr]   segmentc                    |t          |          \  }}|t          d          t          t          |                    dz  }d| g| | g| |gd|gg}d|vri |d<   |d                             d|| d           t          d
|||d	|S )a  
    Create a mesh of a cylinder along Z centered at the origin.

    Parameters
    ----------
    radius : float
      The radius of the cylinder
    height : float or None
      The height of the cylinder, or None if `segment` has been passed.
    sections : int or None
      How many pie wedges should the cylinder have
    segment : (2, 3) float
      Endpoints of axis, overrides transform and height
    transform : None or (4, 4) float
      Transform to apply to mesh after construction
    **kwargs:
        passed to Trimesh to create cylinder

    Returns
    ----------
    cylinder: trimesh.Trimesh
      Resulting mesh of a cylinder
    Nr)  ,either `height` or `segment` must be passed!r&   r   r   cylinderr$  r(  r2   )_segment_to_cylinderr8   r   r   r  r\   )rS   rT   r   r)  r    rN   r%  r   s           r[   r-  r-    s    @ 0AAA	6~GHHHuV}}#Dte*vuo~4yIJz
:
fPVWWXXX I IO  r]   r_minr_maxc                    |t          |          \  }}|t          d          t          t          |                     } | t          j        k     rt          d
||||d|S t          t          |                    }t          t          |                    dz  }| | g|| g||g| |g| | gg}d|vri |d<   |d                             d| ||d           t          d
|||d	|}	|	S )a  
    Create a mesh of an annular cylinder along Z centered at the origin.

    Parameters
    ----------
    r_min : float
      The inner radius of the annular cylinder
    r_max : float
      The outer radius of the annular cylinder
    height : float
      The height of the annular cylinder
    sections : int or None
      How many pie wedges should the annular cylinder have
    transform : (4, 4) float or None
      Transform to apply to move result from the origin
    segment : None or (2, 3) float
      Override transform and height with a line segment
    **kwargs:
        passed to Trimesh to create annulus

    Returns
    ----------
    annulus : trimesh.Trimesh
      Mesh of annular cylinder
    Nr+  r,  )rS   rT   r   r    r&   r   annulus)r7   r/  r0  rT   r(  r2   )	r.  r8   r   r   r   rJ   r-  r  r\   )
r/  r0  rT   r   r    r)  rN   r%  r   r2  s
             r[   r2  r2  #  sT   D 0AAA	6~GHHHeEsy 
(i
 
SY
 
 	
 eEuV}}#D 
				J z
:eevNN  
  I IO G Nr]   c                 p   t          j        | t           j                  } | j        dk    rt	          d          | d         | d         z
  }t           j                            |          }| d         |dz  z   }t          g d|          }t          j	        |          }t          j
        ||          }||fS )au  
    Convert a line segment to a transform and height for a cylinder
    or cylinder-like primitive.

    Parameters
    -----------
    segment : (2, 3) float
      3D line segment in space

    Returns
    -----------
    transform : (4, 4) float
      Matrix to move a Z-extruded origin cylinder to segment
    height : float
      The height of the cylinder needed
    r#   r   zsegment must be 2 3D points!r   r   r   r   r   r   )r3   r4   r5   r7   r8   r{   r|   r   rD   translation_matrixrq   )r)  r   rT   midpointrotationtranslationr    s          r[   r.  r.  l  s    " mG2:666G}7888QZ'!*$FY^^F##FqzVc\*HYYY//H'11K{H--Ifr]   d   
face_countc                     t           j                            | dz  df          dz
  }t          j        | dz                                d          }t	          ||          }|S )z
    Return random triangles as a Trimesh

    Parameters
    -----------
    face_count : int
      Number of faces desired in mesh

    Returns
    -----------
    soup : trimesh.Trimesh
      Geometry with face_count random faces
    r-   r   r,   r.   )r3   randomrG   rA   r	   )r:  r/   r0   soups       r[   random_soupr>    s_     ya 344s:HIj1n%%--g66EHE222DKr]   {Gz?origin_sizeorigin_coloraxis_radiusaxis_lengthc                    t          |           } |t          j        d          }|g d}|| dz  }|| dz  }t          |           }|                    |           ||j        _        t          j        dd|dz  g          }t          |||
                    |          	          }g d
|j        _        t          j        dd|dz  g          }t          j        t          j        d          g d          }t          |||
                    |          
                    |          	          }	g d|	j        _        t          j        dd|dz  g          }t          j        t          j        d          g d          }t          |||
                    |          
                    |          	          }
g d|
j        _        t          j        ||
|	|g          }|S )a  
    Return an XYZ axis marker as a  Trimesh, which represents position
    and orientation. If you set the origin size the other parameters
    will be set relative to it.

    Parameters
    ----------
    origin_size : float
      Radius of sphere that represents the origin
    transform : (4, 4) float
      Transformation matrix
    origin_color : (3,) float or int, uint8 or float
      Color of the origin
    axis_radius : float
      Radius of cylinder that represents x, y, z axis
    axis_length: float
      Length of cylinder that represents x, y, z axis

    Returns
    -------
    marker : trimesh.Trimesh
      Mesh geometry of axis indicators
    Nrm   )   rE  rE  rE  g      @      $@)rS   r   r%   )rS   rT   r    )r   r   rE  i)r   r   r   )r   rE  r   Z   )r   r   r   )rE  r   r   )r   r3   eyer  r  visualr  rD   r5  r-  rq   rotation_matrixradiansr   r   )r@  r    rA  rB  rC  axis_originr8  z_axisr7  y_axisx_axismarkers               r[   ri   ri     s   > $$K F1II	+++!C'!D( ;///K	*** &2K" 'A{Q(?@@K;)--:T:T  F !,FM 'A{Q(?@@K!"*S//999==H--))--k::  F !,FM 'A{Q(?@@K!"*R..)))<<H--))--k::  F !,FM {FFFCDDFMr]   皙?marker_heightc           	         ||dz  }t          |          g}	 ddlm} n(# t          $ r t	          j        dd           |cY S w xY w|t          j        t          j        | j	        d	                   d
z            z  }|t          j        t          j        | j	        d                   d
z            z  }|}t          j
        d| | |f|| |f|||f| ||fgt                    }t          j        t          j        |          |f                              d          }	t          j        |	|g d         f                              d          }	|                     ||	                     |S )a  
    Create a visual marker for a camera object, including an axis and FOV.

    Parameters
    ---------------
    camera : trimesh.scene.Camera
      Camera object with FOV and transform defined
    marker_height : float
      How far along the camera Z should FOV indicators be
    origin_size : float
      Sphere radius of the origin (default: marker_height / 10.0)

    Returns
    ------------
    meshes : list
      Contains Trimesh and Path3D objects which can be visualized
    NrF  )r@  r   )	load_pathz#unable to create FOV visualization!T)exc_infor   r&   )r   r   r   r#   r,   )r   r%   r%   r-   r-   rm   rm   r   )r*   r%   r-   )ri   path.exchange.loadrT  ImportErrorr
   r   r3   tandeg2radfovrF   r   r=   
zeros_likerA   r   r   )
camerarR  r@  meshesrT  xyzrQ   r   s
             r[   camera_markerra    s   , #d* {+++,F1111111   9DIIII 	rz&*Q-883>???Arz&*Q-883>???AA X	aR!QK!aRaAY!Q
C5  F f 5 5v>??GGPPH y(F+C+C+C$DEFFNNzZZH MM))H%%&&&Ms   ! "AAtrisoriginr   c                     |t          j        d          }nt          ||          }t          j        |                     d          |                              d          }t          j        ||f                              d          }d|ddd	ddd	f<   t          j        |                    d          t           j                            |          
          }t          j	        g dg dg dg dg dg dg dg dg          }t          j
        g dt          j        |                    d                    j                  }t          j        |t          |          df                              dt          |          df          }	t          j        |          |	|dk    <   |	t          j        t          |	                    dz                      d          z                       d          }
t%          ||
d          }|S )a  
    Return a mesh consisting of multiple watertight prisms below
    a list of triangles, truncated by a specified plane.

    Parameters
    -------------
    triangles : (n, 3, 3) float
      Triangles in space
    origin : None or (3,) float
      Origin of truncation plane
    normal : None or (3,) float
      Unit normal vector of truncation plane

    Returns
    -----------
    mesh : trimesh.Trimesh
      Triangular mesh
    Nrm   )rc  r   r,   )r*   	   )r*   r-   r-   r   r   r%   )rs   )r%   r   r   )r-   rm      )r   r   rm   )r   r%   rf  )r%   r   r-   )rm   r-   r   )rf  rm   r   )r-   rf  r%   r4  r*   r-      )r*   r   r   Fr  )r3   rH  r   rD   rE   rA   r=   r{   invrF   rq   r   crossrH   r@   r6   r   rG   r	   )rb  rc  r   r    transformedvsr/   fri  f_seqr0   rZ   s               r[   truncated_prismsrn  4  s   . ~F1II		#6&AAA	 %dll7&;&;YGGOOPWXXK 
+{3	4	4	<	<Z	H	HBBqt!tQQQzN "2::g#6#6ry}}Y?W?WXXXH 	IIIIIIIIIIIIIIII		
	 	A F999iok.A.A*.M.MNNPQQEGAK((!,--55r3q661oFFEy||E%!)biE

++a/88DDDMMgVVE HE5AAADKr]   r(   major_radiusminor_radiusmajor_sectionsminor_sectionsc                 F   t          j        ddt           j        z  |d          }t          j        |t          j        |          z  |t          j        |          z  f          | dgz   }d|vri |d<   |d                             d| |d           t          d	|||d|S )
a  Create a mesh of a torus around Z centered at the origin.

    Parameters
    ------------
    major_radius: (float)
      Radius from the center of the torus to the center of the tube.
    minor_radius: (float)
      Radius of the tube.
    major_sections: int
      Number of sections around major radius result should have
      If not specified default is 32 per revolution
    minor_sections: int
      Number of sections around minor radius result should have
      If not specified default is 32 per revolution
    transform : (4, 4) float
      Transformation matrix

    **kwargs:
      passed to Trimesh to create torus

    Returns
    ------------
    geometry : trimesh.Trimesh
      Mesh of a torus
    r   r%   F)endpointr   torus)r7   ro  rp  r(  r2   )r3   r<   r9   r=   r>   r?   r  r\   )ro  rp  rq  rr  r    rN   r   r   s           r[   ru  ru  w  s    B +aRUNU
C
C
CC	s	#\BF3KK%?@ 	qJ z
:<VV  
  ) OU  r]   )NNNr   )NTTN)NN)r-   rn   )rn   NN)rn   rn   NN)NNNN)r9  )r?  NNNN)rQ  N)r(   r(   N)@__doc__r   r  numpyr3    r   r   r   r   r   rD   baser	   	constantsr
   r   geometryr   r   r   	resourcesr   typedr   r   r   r   r   r   shapely.geometryr   shapely.wkbr   load_wkbr   EExceptionWrapperr   
has_moduler   r\   rb   boolr   r   ra   strr`   r   r   r  r  r!  r#  r'  r-  r2  r.  r>  ri   ra  rn  ru  r2   r]   r[   <module>r     s             3 3 3 3 3 3 3 3 3 3 3 3 # # # # # #               D D D D D D D D D D       F F F F F F F F F F F F F F F F.((((((------- . . . *j)!,,G*z*1--HHHHHH	. 	!! t//0../,,- #"&%)	H HHFH wH 	"	H H H H HX JN  &3;I3F   H #'!W WW
W YW 
	W
 W TNW W W W Wt1 1W 1 1 1 1 1 &*	\ \\\ \ 	"	\ \ \ \ \@ KO[; [;$SM[;:B3-[; [; [; [;|Y4 Y Y Y Yz $(%)"&> >i >	"> Y> > > >BW    ,8 8G 8 8 8 8 8x !%%). ..I. 	".
 . . . .d !%%)	2 222 I2 	"	2 2 2 2p #'%)	& &&& w& 	"	& & & & &V  $"&#'%)0 00V0 w0 i 	0
 	"0 0 0 0l  $"&%)#'F FFF VF w	F
 	"F i F F F FR)    D G    * %)(,$($(S SS	"S 9%S &!	S
 &!S S S Sn JN9 9!96>v6F9 9 9 9| #'"&@ @
@Y@ Y@ @ @ @L ! %)/ /// / 	/
 	"/ / / / / /s   A B" BB