0001"""
0002**spheric section** of the Riemann sphere
0003"""
0004
0005__Def__ = ['uCircle']
0006
0007__Classes__ = ['uCircumCircle', 'z_to_uCircle',
0008 'uCircleFromNormal','uPolarCircle', 'uSphereSlice']
0009
0010__all__ = __Classes__ + __Def__
0011
0012__doc_hints__={'m_type':'factory'}
0013
0014import pygeo.base.abstracts._usphere as USphere
0015
0016from pygeo.base.analytics.pygeomath import sqrt, vector
0017
0018
0019class uCircumCircle(USphere._uCircle):
0020 """
0021*spheric section of the Riemann sphere* through **3 given points on the sphere**
0022
0023 inherits
0024
0025 `_uCircle`__
0026
0027__ class-base.abstracts._usphere._uCircle.html
0028
0029 """
0030
0031 __doc_hints__= {'factory':'uCircle',
0032 'args':['upoint1,upoint2,upoint3']}
0033
0034 def __init__(self,p1,p2,p3,**kws):
0035 USphere._uCircle.__init__(self,*[p1,p2,p3],**kws)
0036 self.p1=p1
0037 self.p2=p2
0038 self.p3=p3
0039 self._cpoint=self.p2
0040 self.deps=[self._center]
0041 self.init()
0042
0043 def findSelf(self):
0044 if self._center.toCircumCenter(self.p1,self.p2,self.p3):
0045 self._radiusSquared=self._center.distanceSquared(self._cpoint)
0046 self._radius=sqrt(self._radiusSquared)
0047 self.set_uds_fromPoints()
0048 return True
0049 else:
0050 self._u.set(vector(0,0,1))
0051 self._s.set(vector(0,0,1))
0052 self._d=0
0053 return False
0054
0055
0056class z_to_uCircle(USphere._uCircle):
0057 """
0058*spheric section of the Riemann sphere* stereographically projected from the
0059given **circle of the complex plane**
0060
0061 inherits
0062
0063 `_uCircle`__
0064
0065__ class-base.abstracts._usphere._uCircle.html
0066
0067 """
0068
0069 __doc_hints__= {'factory':'uCircle',
0070 'args':['zcircle']}
0071
0072 def __init__(self,zcircle,**kws):
0073 USphere._uCircle.__init__(self,*[zcircle],**kws)
0074 self.zcircle=zcircle
0075 self.deps=[self._cpoint,self._center]
0076 self.init()
0077
0078 def findSelf(self):
0079 self.zcircle.to_uSphere(self)
0080 return True
0081
0082
0083class uCircleFromNormal(USphere._uCircle):
0084 """
0085**spheric section of the Riemann sphere** cut by the plane
0086at the initial point argument and normal to the direction determined
0087by the given **2 point**
0088
0089 inherits
0090
0091 `_uCircle`__
0092
0093__ class-base.abstracts._usphere._uCircle.html
0094
0095 """
0096
0097 __doc_hints__= {'factory':'uCircle',
0098 'args':['point1,point2'],
0099 'conditions': ['normal plane cuts unit sphere'],
0100 'otherwise': 'None'}
0101
0102 def __init__(self,p1,p2,**kws):
0103 self.p1=p1
0104 self.p2=p2
0105 USphere._uCircle.__init__(self,*[p1,p2],**kws)
0106 self.deps=[self._center,self._cpoint]
0107 self.init()
0108
0109 def findSelf(self):
0110 self._u.set((self.p2-self.p1).norm())
0111 self._d = self._u.dot(self.p2)
0112 self._center.set(self._u*self._d)
0113 self._radiusSquared =rqsr=1. - self._center.mag2
0114 if rqsr < 0:
0115 self._radiusSquared =rqsr = 0
0116 print "plane does not cut the unit sphere, returned false"
0117 return False
0118 self._radius=rad=sqrt(rqsr)
0119 self.set_s_from_u(self._u)
0120 self._cpoint.set(self._s*rad+self._center)
0121 return True
0122
0123
0124class uPolarCircle(USphere._uCircle):
0125 """
0126*spheric section of Riemann sphere* cut by the plane
0127polar to the given **point** with respect to Riemann sphere
0128
0129 inherits
0130
0131 `_uCircle`__
0132
0133__ class-base.abstracts._usphere._uCircle.html
0134
0135 """
0136
0137 __doc_hints__= {'factory':'uCircle',
0138 'args':['point'],
0139 'conditions': ['polar plane cuts unit sphere'],
0140 'otherwise': 'None'}
0141
0142 def __init__(self,pole,**kws):
0143 USphere._uCircle.__init__(self,*[pole],**kws)
0144 self.pole=pole
0145 self.deps=[self._center,self._cpoint]
0146 self.init()
0147
0148 def findSelf(self):
0149 self._u.set(self.pole.norm())
0150 self._d = self._u.dot(self._u)*(1./self.pole.mag)
0151 self._center.set(self._u*self._d)
0152 self._radiusSquared =rqsr=1.0 -self._center.mag2
0153 if rqsr < 0:
0154 self._radiusSquared =rqsr = 0
0155 return False
0156 self._radius=rad=sqrt(rqsr)
0157 self.set_s_from_u(self._u)
0158 self._cpoint.set(self._s*rad+self._center)
0159 return True
0160
0161class uSphereSlice(USphere._uCircle):
0162 """
0163*spheric section of Riemann sphere* cut by the plane
0164polar to the given **point** with respect to Riemann sphere
0165
0166 inherits
0167
0168 `_uCircle`__
0169
0170__ class-base.abstracts._usphere._uCircle.html
0171
0172 """
0173
0174 __doc_hints__= {'factory':'uCircle',
0175 'args':['plane'],
0176 'conditions': ['plane cuts unit sphere'],
0177 'otherwise': 'None'}
0178
0179 def __init__(self,plane,**kws):
0180 USphere._uCircle.__init__(self,*[plane],**kws)
0181 self.plane=plane
0182 self.deps=[self._center,self._cpoint]
0183 self._center=USphere._rPoint()
0184 self.init()
0185
0186 def findSelf(self):
0187 self._d = self.plane._d
0188 self._u.set(self.plane._u)
0189 self._s.set(self.plane._s)
0190 self._center.toPlane(self.plane)
0191 self._radiusSquared = rsqr=1-self._center.mag2
0192 if rsqr < 0:
0193 print self.__class__.__name__
0194 print "no real plane, sphere intersection, returned false"
0195 return False
0196 self._radius=rad=sqrt(rsqr)
0197 self._cpoint.set(self._s*rad+self._center)
0198 return True
0199
0200def uCircle(*args,**kws):
0201 """
0202'class factory' function returns instance of object derived from the
0203_zCircle abstract class representing a spheric section of the Riemann sphere
0204 """
0205
0206 from pygeo.base.abstracts._element import method_get
0207 from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0208 import pygeo.base.abstracts._complex as Complex
0209 import pygeo.base.abstracts._real as Real
0210
0211 __sigs__=[[USphere._uPoint,USphere._uPoint,USphere._uPoint],
0212 [Real._Point,Real._Point],
0213 [Real._Point],
0214 [Complex._zCircle],[Complex._zLine]]
0215
0216 t,i = method_get(__sigs__,args)
0217
0218 if t is None:
0219 raise Argument_Type_Error(__sigs__,args)
0220 else:
0221 if i==0:
0222 return uCircumCircle(t[0],t[1],t[2],**kws)
0223 elif i==1:
0224 return uCircleFromNormal(t[0],t[1],**kws)
0225 elif i==2:
0226 return uPolarCircle(t[0],**kws)
0227 elif i==3 or i==4:
0228 return z_to_uCircle(t[0],**kws)
0229 else:
0230 raise Argument_Type_Error(__sigs__,args)