
    Mi                         S r SSK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	 rSS
 jrS rg! \ a4  rSSKJr  \R                   " \5      r\R                   " \5      r
 SrCNASrCff = f)zp
nsphere.py
--------------

Functions for fitting and minimizing nspheres:
circles, spheres, hyperspheres, etc.
    N   )convexutil)logtol)spatial)leastsq)
exceptionsc           
         [         R                  " U 5      nUR                  SS9n[        R                  " USS9R                  5       nX-
  U-  n[        U5      u  pEnX-
  S-  R                  SS9R                  5       S-  U-  nXC-  U-   nUS:  a  XE4$ [        R                  " USS9n [        UR                  5      [        U5      -  S	-  nUS
:  a  [        e[        R                  R                  UR                  USS9R                  SS9n	U	R%                  5       n[        R&                  " X   5      U-  nUR                  U   U-  U-   nX:  a  XE4$ X4$ ! [         ap    [        R                   " S5        [        R"                  " UR                   V
s/ s H%  oU
-
  S-  R                  SS9R                  5       PM'     Os  sn
f sn
5      n	 Nf = f)a  
Compute the minimum n- sphere for a mesh or a set of points.

Uses the fact that the minimum n- sphere will be centered at one of
the vertices of the furthest site voronoi diagram, which is n*log(n)
but should be pretty fast due to using the scipy/qhull implementations
of convex hulls and voronoi diagrams.

Parameters
----------
obj : (n, d) float or trimesh.Trimesh
  Points or mesh to find minimum bounding nsphere

Returns
----------
center : (d,) float
  Center of fitted n- sphere
radius : float
  Radius of fitted n-sphere
r   axis   r   g      ?gư>T)furthest_site	   g    eAsqeuclidean)metricz*MemoryError: falling back to slower check!)r   hull_pointsminnpptpfit_nspheresummaxr   VoronoilenverticesMemoryErrordistancecdistr   warningarrayargminsqrt)objpointspoints_originpoints_scalefit_Cfit_Rfit_Evoronoimemory_estimateradii_2v	radii_idxradius_vcenter_vs                 i/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/nsphere.pyminimum_nspherer3      s   2 $F
 JJAJ&M66&q)--/L$4F
 &f-E%~!#((a(0446#=ME!]2Et|| oofD9G

 g../#f+=A S ""((f] ) 

#1#+ 	  I www)*\9H  +l:mKH|%  
@A((<C<L<LM<Lqza$$!$,002<LM
	
s   ,A&E >G,G
GGc                   ^ ^	 [         R                  " T [         R                  S9m [         R                  " T R                  S   5      m	U	U 4S jnUc  T R                  SS9nO[         R                  " U5      n[        X#SS9u  pEUS;  a  [        S	5      e[        R                  " T U-
  5      nUR                  5       n[         R                  " U5      nXGU4$ )
aX  
Fit an n-sphere to a set of points using least squares.

Parameters
------------
points : (n, d) float
  Points in space
prior : (d,) float
  Best guess for center of nsphere

Returns
---------
center : (d,) float
  Location of center
radius : float
  Mean radius across circle
error : float
  Peak to peak value of deviation from mean radius
)dtyper   c                 z   > [         R                  " TU -
  S-  T5      nXR                  5       [        U5      -  -
  $ )Nr   )r   dotr   r   )centerradii_sqonesr%   s     r2   	residualsfit_nsphere.<locals>.residuals   s8     666F?q0$7 <<>CM9::    r   r   g:0yE>)xtol)r   r         zLeast square fit failed!)r   
asanyarrayfloat64r:   shapemeanr	   
ValueErrorr   row_normr   )
r%   priorr;   guesscenter_resultreturn_coderadiiradiuserrorr:   s
   `        @r2   r   r   t   s    * ]]64F776<<?#D; }#e$!(!EM,&344MM&=01EZZ\FFF5ME%''r=   c                 H    [        U 5      u  pnU[        R                  :  nU$ )z
Check if a list of points is an nsphere.

Parameters
-----------
points : (n, dimension) float
  Points in space

Returns
-----------
check : bool
  True if input points are on an nsphere
)r   r   merge)r%   _center_radiusrM   checks        r2   
is_nsphererS      s&     *&1GeCIIELr=   )N)__doc__numpyr    r   r   	constantsr   r   scipyr   scipy.optimizer	   BaseExceptionEr
   ExceptionWrapperr3   r   rS    r=   r2   <module>r^      sh      	-&Wt.(bg  -))!,G))!,G-s   0 A**A%%A*