0001"""
0002**collection of circles** with a defined geometric relationship
0003"""
0004
0005__Def__ = ['CircleArray']
0006
0007__Classes__ = ['CirclePencil']
0008
0009__all__= __Classes__ + __Def__
0010
0011__doc_hints__={'m_type':'factory'}
0012
0013import pygeo.base.abstracts._real as Real
0014
0015from pygeo.base.analytics.pygeomath import array, multiply, matrixmultiply, sqrt, homogenous
0016
0017
0018class CirclePencil(Real._CirclePencil):
0019 """
0020*array of circle sections* which the given **plane sheaf** cuts from the given **sphere**.
0021
0022 inherits
0023
0024 `_CirclePencil`__
0025
0026__ class-base.abstracts._real._CirclePencil.html
0027
0028
0029 """
0030 __doc_hints__= {'factory':'CircleArray',
0031 'args':['sphere,planearray']}
0032
0033 def __init__(self,sphere,pencil,**kws):
0034 self.sphere=sphere
0035 self.pencil=pencil
0036 self.density=self.pencil.density
0037 Real._CirclePencil.__init__(self,*[sphere,pencil],**kws)
0038 self.init()
0039
0040 def findSelf(self):
0041 for circle,plane in zip(self,self.pencil):
0042 circle._center.set(self.sphere._center)
0043 circle._u.set(plane._u)
0044 u=circle._u
0045 circle.set_s_from_u(u)
0046 circle._d= d = plane._d
0047 pt=homogenous(circle._center-u)
0048 equat=array([u.x,u.y,u.z,-d])
0049 mat= multiply.outer(equat,pt)
0050 k=matrixmultiply(pt,equat)
0051 for i in range(4):
0052 mat[i,i]-=k
0053 circle._center.to_3d(matrixmultiply(circle._center.homogenous()
0054 ,mat))
0055 pdist = circle._center.distanceSquared(self.sphere._center)
0056 circle._radiusSquared=rsqr=self.sphere._radiusSquared-pdist
0057 if rsqr < 0:
0058 rsqr = 0
0059 circle._radius=rad=sqrt(rsqr)
0060 circle._cpoint.set(circle._s*rad+circle._center)
0061 return True
0062
0063def CircleArray(*args,**kws):
0064 """
0065'class factory' function returns instance of object derived from the
0066_CircleArray abstract class representing an array of circles with a
0067defined geoemtric relationship
0068 """
0069
0070 from pygeo.base.abstracts._element import method_get
0071 from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0072
0073 __sigs__=[[Real._Sphere,Real._PlaneArray]]
0074
0075 t,i = method_get(__sigs__,args)
0076
0077 if t is None:
0078 raise Argument_Type_Error(__sigs__,args)
0079 else:
0080 if i==0:
0081 return CirclePencil(t[0],t[1],**kws)
0082 else:
0083 raise Argument_Type_Error(__sigs__,args)