0001"""
0002**array of planes** with a defined geometric relationship
0003"""
0004__Def__ =       ['PlaneArray']
0005
0006__Classes__  =  ['PlaneSheaf']
0007
0008__all__= __Classes__+ __Def__
0009
0010__doc_hints__={'m_type':'factory'}
0011
0012import pygeo.base.abstracts._real as Real
0013
0014from pygeo.base.analytics.pygeomath import PI, vector, cross3, hypot
0015from pygeo.base.support.pygeoopts import EPS
0016
0017
0018class PlaneSheaf(Real._PlaneArray):
0019    """
0020*sheaf of planes* through the given **line**
0021    
0022    inherits
0023    
0024        `_PlaneArray`__
0025
0026__ class-base.abstracts._real._PlaneArray.html      
0027    
0028    """
0029
0030    __doc_hints__=  {'factory':'PlaneArray',
0031                    'args':['line']}
0032
0033    def __init__(self,line,**kws):
0034        self.line=line
0035        Real._PlaneArray.__init__(self,*[line],**kws)
0036        self.div=PI/self.density
0037        self.init()
0038
0039    def findSelf(self):
0040        line=self.line
0041        dir=line.getDirection()
0042        st=(line.p2+line.p1)*.5
0043        lxy = hypot(st.x,st.y)
0044        if (lxy >= EPS):
0045            try:
0046                s=vector(-dir.y/lxy,dir.x/lxy,0.).norm()
0047            except ZeroDivisionError:
0048                print self.__class__.__name__
0049                print """line segment's points coincident, no array of planes 
0050                        defined, returned False"""
0051                return False
0052        else:
0053            s=vector(1.,0.,0.)
0054        for i,plane  in enumerate(self.planes):
0055            rad=i*self.div
0056            r=s.rotate(rad,dir)+st
0057            u=cross3(line.p1,line.p2,r).norm()
0058            d=line.p1.dot(u)
0059            plane._u=u
0060            plane._d=d
0061            plane.set_s_from_u(u)
0062        return True
0063
0064
0065def  PlaneArray(*args,**kws):
0066    """
0067'class factory' function returns instance of object derived from the  
0068_PlaneArray abstract class representing an array of planes with a defined 
0069geometric relationship
0070    
0071    """
0072
0073    from pygeo.base.abstracts._element import method_get
0074    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0075
0076    __sigs__=[[Real._Line]]
0077
0078
0079    t,i = method_get(__sigs__,args)
0080
0081    if t is None:
0082        raise Argument_Type_Error(__sigs__,args)
0083    else:
0084        if i==0:
0085            return PlaneSheaf(t[0],**kws)
0086        else:
0087            raise Argument_Type_Error(__sigs__,args)