
    MiQ                        S SK rSSKJrJrJrJrJrJr  SSK	J
r
Jr  SSKJrJr   S SKJr  S SKJr   S S	KJr  \R0                  " \R2                  S
-  S9rS\R6                  l        SS jrSS jrSS jrS r S r!S\S\S\\RD                     4S jr#g! \ a4  rSSKJr  \R,                  " \5      r\R,                  " \5      r SrCNSrCff = f! \ a    \r Nf = f)    N   )convexgeometrygroupingnspheretransformationsutil)lognow)	ArrayLikeNDArray)optimize)
ConvexHull)
exceptions)
QhullError   )thetaFc           	      (   [        XS9nUR                  UR                     nUR                  UR                     nUSS2S4   USS2S4   -
  n[        R
                  " [        R                  " US-  SS/5      5      nUS:  nXW   Xg   R                  S5      -  n[        R                  " U5      SS	/-  n[        R                  " XTR                  5      n	[        R                  " XR                  5      n
[        R                  " U	R                  SS
9U
R                  SS
9U	R                  SS
9U
R                  SS
945      n[        R                  " UR                  S5      SS
9R                  S5      n[        R                  " USS
9nUR                  5       nX   nX   SS * US-  -
  n[        R                   " X^   SSS2   6 n["        R$                  " UU5      nUS   US   :  a#  [        R                  " [&        U5      nUSSS2   nUU4$ )a  
Find an oriented bounding box for an array of 2D points.

Details on qhull options:
  http://www.qhull.org/html/qh-quick.htm#options

Parameters
----------
points : (n,2) float
  Points in 2D.

Returns
----------
transform : (3,3) float
  Homogeneous 2D transformation matrix to move the
  input points so that the axis aligned bounding box
  is CENTERED AT THE ORIGIN.
rectangle : (2,) float
   Size of extents once input points are transformed
   by transform
)qhull_optionsNr   r   r   绽|=r               ?axis)r   r   r   r   r         ?r   )r   points	simplicesverticesnpsqrtdotreshapefliplrTcolumn_stackminmaxdiffprodargminarctan2r   planar_matrix_flip)r   r   r   
hull_edgeshull_pointsedge_vectors	edge_normedge_nonzeroperp_vectorsxyboundsextentsareaarea_min	rectangleoffsetr   	transforms                      h/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/bounds.pyoriented_bounds_2DrA      s   2 <F v//0J--0K ad#jA&66L|QA78Iu$L-	0G0O0OPW0XXL 99\*dC[8L 	|]]+A
|]]+A __aeeemQUUU]AEEqEM155VW5=YZF ggfnnZ0q9AA'JG777#D{{}H !I r""i#o6FJJ.tt45E--fe<I
 |il"FF5),	ddO	i    c           	      >  ^ U4S jn [        U S5      (       a  U R                  nO[        R                  " U 5      (       az  [        R
                  " U 5      n[        R                  " US5      (       a  [        U5      $ [        R                  " US5      (       a  [        R                  " USS9nO[        S5      e[        S5      eUR                  nUR                  R                  n	UR                   n
UR"                  nUc  [        R$                  " [        R&                  " U5      5      n[(        R*                  " XS9S   nX    Vs/ s H   n[,        R.                  " U6 R                  PM"     nn[        R0                  " X   5      nO[2        R4                  " U/ SQ5      /nU/n[7        5       nS
n[        R8                  n[;        UU5       GH  u  nn[        R<                  " X5      S:  nUR?                  5       (       d  M7  U
[        R@                  " UU	   6    n[        R<                  " US
S2S
S24   UR                  5      R                  S
S
2S
S24   nUS
S
2S
S24   U   nUS
S
2SS
S
24   US
S
2SS
S
24   -
  n[        RB                  " [        R<                  " US-  SS/5      5      nUS:  nUU   UU   RE                  S5      -  n[        RF                  " U5      SS/-  n[        R<                  " UUS
S
2SS
S24   R                  5      n[        R<                  " UUS
S
2SS
S24   R                  5      nURI                  SS9URK                  SS9-
  URI                  SS9URK                  SS9-
  -  RK                  5       nU[        RL                  " US
S
2S4   5      -  n U U:  d  GM  U nUnGM     [        RN                  " U[        RP                  " [S        U5      5      45      R                  n![        R<                  " UU!5      R                  S
S
2S
S24   n[        RL                  " US
S
2S4   5      n"[        US
S
2S
S24   5      u  n#n$[        RT                  " U$U"5      n%SU#S
S2S4'   [,        RV                  " U#5      n&[        R<                  " U&U5      n'[,        RX                  " UU'5      n(U(RK                  SS9[        RL                  " U(SS9S-  -   n)U)* U'S
S2S4'   U(       a  U%R[                  5       n*[        R\                  " S5      n+[        R\                  " S5      U*   * U+S
S2S
S24'   [        R^                  " [        R`                  Rc                  U+S
S2S
S24   5      S5      (       d>  [        R<                  " U+S
S2S
S24   [        R\                  " S5      * 5      U+S
S2S
S24'   [        R<                  " U+U'5      n'U%U*   n%[d        Rf                  " S[S        U5      [7        5       U-
  5        U'U%4$ ! [         ay    [        U S	5      (       a*  U R                  R                  [        R                  5      nO3[        R                  " U 5      (       a  [        R
                  " U 5      nOe U" U5      s $ f = fs  snf )a  
Find the oriented bounding box for a Trimesh

Parameters
----------
obj : trimesh.Trimesh, (n, 2) float, or (n, 3) float
   Mesh object or points in 2D or 3D space
angle_digits : int
   How much angular precision do we want on our result.
   Even with less precision the returned extents will cover
   the mesh albeit with larger than minimal volume, and may
   experience substantial speedups.
ordered : bool
  Return a consistent order for bounds
normal : None or (3,) float
  Override search for normal on 3D meshes.
coplanar_tol : float
  If a convex hull fails and we are checking to see if the
  points are coplanar this is the maximum deviation from
  a plane where the points will be considered coplanar.

Returns
----------
to_origin : (4,4) float
  Transformation matrix which will move the center of the
  bounding box of the input mesh to the origin.
extents: (3,) float
  The extents of the mesh once transformed with to_origin
c                 r  > [         R                  " U SS9nX-
  n[         R                  R                  USS9u    p4[         R                  " X$R
                  5      n[         R                  " [         R                  " USS2S4   5      T:  5      (       a  [        S5      e[         R                  " S5      nXFSS	2SS	24'   [         R                  " XA5      * USS	2S	4'   [        USS2SS24   5      u  px[         R                  " US
5      n	[         R                  " [        R                  " U5      U5      n
X4$ )a  
Find an oriented bounding box for an array of coplanar 3D points.

Parameters
----------
points : (n, 3) float
  Points in 3D that occupy a 2D subspace.

Returns
----------
to_origin : (4, 4) float
  Transformation matrix which will move the center of the
  bounding box of the input mesh to the origin.
extents : (3,) float
  The extents of the mesh once transformed with to_origin
r   r   F)full_matricesNr   zPoints must be coplanar              )r"   meanlinalgsvdmatmulr'   anyabs
ValueErroreyerA   appendr   planar_matrix_to_3D)r   points_meanpoints_demeaned_vh	points_2dto_2dto_origin_2d
extents_2dr:   	to_origincoplanar_tols              r@   oriented_bounds_coplanar1oriented_bounds.<locals>.oriented_bounds_coplanar   s
   $ ggf1- .99===F1IIott4	66"&&1a4)L899677 q	bqb"1"f		"22bqb!e $6i2A26F#G ))J,IIoAA,OQVW	!!rB   convex_hullr   r   rG   T)repairzPoints are not (n,3) or (n,2)!z9Oriented bounds must be passed a mesh or a set of points!r!   N)digitsr   )r   r   r   g|۽rG   r   r   r   r   r   r   r   rH   r   rF   z,oriented_bounds checked %d vectors in %0.4fs)4hasattrr_   r	   is_sequencer"   
asanyarrayis_shaperA   r   rO   r   r!   viewndarrayface_adjacencyr'   face_adjacency_edgesface_normalsvector_to_sphericalvector_hemispherer   unique_rowsr   spherical_matrixspherical_to_vectorr   align_vectorsr   infzipr$   rM   bitwise_xorr#   r%   r&   r*   r)   ptpr(   oneslenrQ   rR   transform_pointsargsortrP   iscloserJ   detr
   debug),objangle_digitsorderednormalr\   r]   hullr   r!   hull_adj	hull_edgehull_normalsspherical_coordsspherical_uniquesmatricesnormalsticmin_2D
min_volumeto_2Dsideedges	projected	edge_vertr3   r4   r5   r6   r7   r8   r;   volume	vert_onesheightrotation_2Dboxmin_extents
rotation_Zr[   transformed
box_centerorderflips,       `                                       r@   oriented_boundsr   k   s   >$"L 0 3&& ??Dc""]]3'F}}VW--)&11vw//))&> !ABBXYY }}H""$$H))I$$L ~  33D4J4J<4XY $//0@VWXY &7
7 ,,a0227 	 
 **+;+MN **69=>(
%CFJ Wh/
 vvl+f4xxzz "..$x.9: FF5!RaR=(**5772A2>	a!e$U+	 Aq)IaAg,>>GGBFF<?QF;<	 5(#L1Il4K4S4S5
 
 yy.$< FF<1a!8!4!6!67FF<1a!8!4!6!67AA.155a5=155a5=3PQVVX yA// JJFW 0^ 2773x=+A BCEEIvy)++ArrE2IVVIadO$F))ArrE*:;K))C(KKA 44[AJ z6*I "228YGKa(266+A+F+LLJ"{Ibqb!e ##% vvayq	%((RaR!V zz"))--RaR!V5s;;66$rr2A2v,
;D!RaRL FF4+	!%(II<c(mSUUX[Yk!!}  	0 3
##\\&&rzz2Fc""]]3'F'//	04
s*   X AX ?1X 1X 'ZB ZZc                 @  ^ SU4S jjn[        U S5      (       Ga;  U R                  S:X  Ga*  U R                  (       a  U R                  nOU R                  R                  n[
        R                  " X@R                  S9n[        R                  " U R                  U5      n[        R                  " USS2S4   5      n[        R                  " SSUS-  USS2S4   R                  5       -
  /5      n[        R                  " X5      nUSS2SS24   S-  R!                  S	S
9R                  5       S-  n	Xy[        R"                  R%                  U5      S.n
U
$ [&        R(                  " U 5      m[*        R,                  " TS5      (       d  [/        S5      e[*        R0                  " SS/[        R2                  [        R2                  //U5      n[        U S5      (       a6  [        R4                  " U[*        R6                  " U R8                  5      45      n[;        5       /n[        R<                  " U Vs/ s H
  o" U5      PM     sn5      nXR?                  5          nURA                  [;        5       5        S[        R2                  -  U-  nUS   U-
  US   U-   4US	   U-
  US	   U-   4/n[B        RD                  " X?USUS9nURA                  [;        5       5        [F        RH                  " S/[        RJ                  " U5      Q76   U" US   SS9u  npUXS.n
U
$ s  snf )a  
Find the approximate minimum volume cylinder which contains
a mesh or a a list of points.

Samples a hemisphere then uses scipy.optimize to pick the
final orientation of the cylinder.

A nice discussion about better ways to implement this is here:
https://www.staff.uni-mainz.de/schoemer/publications/ALGO00.pdf


Parameters
----------
obj : trimesh.Trimesh, or (n, 3) float
  Mesh object or points in space
sample_count : int
  How densely should we sample the hemisphere.
  Angular spacing is 180 degrees / this number

Returns
----------
result : dict
  With keys:
    'radius'    : float, radius of cylinder
    'height'    : float, height of cylinder
    'transform' : (4,4) float, transform from the origin
                  to centered cylinder
c                 V  > [         R                  " U SS06n[         R                  " T
US9n[        R                  " USS2S4   5      n [
        R                  " USS2SS24   5      u  pV[        R                  U-  US-  -  nU(       a}  [        R                  " XSSS2S4   R                  5       US-  -   5      n[        R                  " [        R                  R                  U5      [         R                  " U5      5      n	XU4$ U$ ! [         a    [        R                  s $ f = f)a:  
Takes spherical coordinates and calculates the volume
of a cylinder along that vector

Parameters
---------
spherical : (2,) float
   Theta and phi
return_data : bool
   Flag for returned

Returns
--------
if return_data:
    transform ((4,4) float)
    radius (float)
    height (float)
else:
    volume (float)
axesrxyz)matrixNr   r   )r   ro   rx   r"   ru   r   minimum_nsphererO   rr   pirQ   r)   r$   rJ   invtranslation_matrix)	sphericalreturn_datar   r   r   	center_2Dradiusr   	center_3Dr?   r   s             r@   volume_from_angles,minimum_cylinder.<locals>.volume_from_anglesf  s   *  00)I&I#44T%H		!Q$(	 ' 7 7	!RaR%8H II 619-		)q!t_-@-@-Bfsl-STI		e$o&H&H&SI f,,  	66M	s   !D D('D(symmetryradial)originr   Nr   r   g       @r   r   r   )r   r   r?   r`   z%Input must be reducable to 3D points!principal_inertia_vectorsSLSQP)tolmethodr9   z)Performed search in %f and minimize in %fr7   T)r   )r?   r   r   )F)&rc   r   is_watertightcenter_massr_   r   plane_transformsymmetry_axisr   rx   r!   r"   ru   r   r*   r$   sumrJ   r   r   r2   r	   rf   rO   grid_linspacer   vstackrl   r   r   arrayr-   rQ   r   minimizer
   r|   r+   )r}   sample_count	angle_tolr   r   r   on_planer   slider   resultsamplesr   ivolumesbeststepr9   rr?   r   s                       @r@   minimum_cylinderr   H  s   <%R sJCLLH$<__F __00F((?P?PQ"33CLL%HA'  22FSLHQTN$6$6$889
 u$1bqb5/Q&+++3779S@"299==QVCWX c"D==w''@AA   1a&255"%%.!9<HG s/00))d..s/L/LMN
 5'Chhw?w!*1-w?@G>>#$DJJsu ruu9|#DAw~tAw~.a4a40PQFi	A JJsuII9IBGGCLI !31S6t LIv$IFM+ @s   3Lc                    [         R                  " U [         R                  S9n U R                  S:w  a  [	        S5      e[         R
                  " U SS9n[         R                  " S5      nU R                  SS9USS2S4'   X4$ )	a!  
Convert an axis aligned bounding box to extents and
transform.

Parameters
------------
bounds : (2, 3) float
  Axis aligned bounds in space

Returns
------------
extents : (3,) float
  Extents of the bounding box
transform : (4, 4) float
  Homogeneous transform moving extents to bounds
dtyper   rG   zbounds must be (2, 3)r   r   rF   NrG   )r"   re   float64shaperO   ru   rP   rI   )r9   r:   r?   s      r@   
to_extentsr     ss    " ]]64F||v011ffV!$Gq	I{{{*Ibqb!erB   c                    [         R                  " U [         R                  S9n [        R                  " U S5      (       a  [         R
                  " U SS/45      n O'[        R                  " U S5      (       d  [        S5      e[         R                  " S5      u  pp4pV[         R                  " UUUUUUUUUUUUUUUUUUUUUUUU/5      R                  S5      nU R                  S5      U   nU$ )	z
Given a pair of axis aligned bounds, return all
8 corners of the bounding box.

Parameters
----------
bounds : (2,3) or (2,2) float
  Axis aligned bounds

Returns
----------
corners : (8,3) float
  Corner vertices of the cube
r   )r   r   r   r   zbounds must be (2,2) or (2,3)!   r`   r   )
r"   re   r   r	   rf   r(   rO   aranger   r%   )	r9   minxminyminzmaxxmaxymaxzcorner_indexcornerss	            r@   r   r     s      ]]64F}}VV$$&1a&!12]]66**9::)+1&DD881	
6 gg7 : nnR .GNrB   r9   r   returnc                    [         R                  " U [         R                  S9n [         R                  " U[         R                  S9n[        U 5      S:w  a  [	        S5      e[
        R                  " USU R                  S   45      (       d  [	        S5      e[         R                  " XS   :  R                  SS9XS   :  R                  SS95      nU$ )	a  
Do an axis aligned bounding box check on an array of points.

Parameters
-----------
bounds : (2, dimension) float
   Axis aligned bounding box
points : (n, dimension) float
   Points in space

Returns
-----------
points_inside : (n,) bool
  True if points are inside the AABB
r   r   zbounds must be (2,dimension)!r   r   zbounds shape must match points!r   r   )
r"   re   r   rw   rO   r	   rf   r   logical_andall)r9   r   points_insides      r@   containsr   (  s    " ]]64F]]64F
6{a899=="fll1o!677:;; NN	)	  a (61I+=*B*B*B*JM rB   )QbB)r   TNg-q=)r   gMbP?)$numpyr"    r   r   r   r   r   r	   	constantsr
   r   typedr   r   scipyr   scipy.spatialr   BaseExceptionEr   ExceptionWrapperr   r/   r   r0   flags	writeablerA   r   r   r   r   bool_r    rB   r@   <module>r      s     H H  %	.((
 	%%BEEAI6 L ^Z"zHV86rY 	 gbhh6G {  .,,Q/J**1-H.  Js(   B C C*C

CCC