0001"""
0002**array of spheric sections** of the Riemann sphere
0003"""
0004
0005__Def__ = ['uCirclePencil']
0006
0007__Classes__ = ['uSphereSlices', 'z_to_uCirclePencil']
0008
0009__all__ = __Classes__ + __Def__
0010
0011__doc_hints__={'m_type':'factory'}
0012
0013import pygeo.base.abstracts._usphere as USphere
0014
0015from pygeo.base.analytics.pygeomath import matrixmultiply, multiply, sqrt, vector, array
0016
0017
0018class uSphereSlices(USphere._uCirclePencil):
0019    """
0020*array of spheric sections of the Riemann sphere* formed by the intersection of  
0021planes of the given **plane array** with the Riemann sphere    
0022    
0023    
0024    inherits
0025    
0026        `_uCirclePencil`__
0027
0028__ class-base.abstracts._usphere._uCirclePencil.html        
0029    
0030    """
0031
0032    __doc_hints__=  {'factory':'uCirclePencil',
0033                    'args':['planepencil']}
0034
0035    def __init__(self,pencil,**kws):
0036        self.pencil=pencil
0037        USphere._uCirclePencil.__init__(self,*[pencil],**kws)
0038        self.density=self.pencil.density
0039        self.init()
0040
0041    def findSelf(self):
0042        for i,circle in enumerate(self.circles):
0043            plane=self.pencil.planes[i]
0044            circle._center.set(vector(0,0,0))
0045            circle._u.set(plane._u)
0046            circle._d= d = plane._d
0047            u=circle._u
0048            circle.set_s_from_u(u)
0049            pt=-u.homogenous()
0050            equat=array([u.x,u.y,u.z,-d])
0051            mat= multiply.outer(equat,pt)
0052            k=matrixmultiply(pt,equat)
0053            for i in range(4):
0054                mat[i,i]-=k
0055            circle._center.to_3d(matrixmultiply(circle._center.homogenous(),mat))
0056            rsqr = 1.0-circle._center.mag2
0057            if rsqr < 0:
0058                rsqr = 0
0059            circle._cpoint.set(circle._s*sqrt(rsqr)+circle._center)
0060            circle._radiusSquared=circle._center.distanceSquared(circle._cpoint)
0061            circle._radius=sqrt(circle._radiusSquared)
0062        return True
0063
0064
0065class z_to_uCirclePencil(USphere._uCirclePencil):
0066    """
0067*array of spheric sections of the Riemann sphere* formed by the stereographic projection 
0068to the sphere of an **array of circles of the complex plane**    
0069    
0070    inherits
0071    
0072        `_uCirclePencil`__
0073
0074__ class-base.abstracts._usphere._uCirclePencil.html        
0075    
0076    """
0077
0078    __doc_hints__=  {'factory':'uCirclePencil',
0079                    'args':['zcirclepencil']}
0080
0081    def __init__(self,zpencil,**kw):
0082        self.zpencil=zpencil
0083        self.density=self.zpencil.density
0084        USphere._uCirclePencil.__init__(self,*[zpencil],**kw)
0085        self.init()
0086
0087    def findSelf(self):
0088        for zcircle, ucircle in zip(self.zpencil,self.circles):
0089            zcircle.to_uSphere(ucircle)
0090        return True
0091
0092
0093def uCirclePencil(*args,**kws):
0094    """
0095'class factory' function returns instance of object derived from the 
0096_uCirclePencil abstract class representing an 
0097array of spheric sections of the Riemann sphere
0098    """
0099
0100    import pygeo.base.abstracts._real as Real
0101    from pygeo.base.abstracts._element import method_get
0102    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0103    import pygeo.base.abstracts._complex as Complex
0104
0105    __sigs__=[[Real._PlaneArray],
0106            [Complex._zCirclePencil]]
0107
0108    t,i = method_get(__sigs__,args)
0109
0110    if t is None:
0111        raise Argument_Type_Error(__sigs__,args)
0112    else:
0113        if i==0:
0114            return uSphereSlices(t[0],**kws)
0115        elif i==1:
0116            return z_to_uCirclePencil(t[0],**kws)
0117        else:
0118            raise Argument_Type_Error(__sigs__,args)