0001"""
0002**point** determined as a defined center of a given geometric object
0003"""
0004
0005__Def__ =       ['Center']
0006
0007__Classes__=    ['Centroid','OrthoCenter', 'InCenter',
0008                'ExCenter', 'CircumCenter', 'TetraCenter']
0009
0010__all__= __Classes__ + __Def__
0011
0012__doc_hints__=  {'m_type':'factory'}
0013
0014
0015import pygeo.base.abstracts._real as Real
0016
0017
0018class Centroid(Real._Point):
0019    """
0020*point* at center of mass of the given **3 points'** triangle
0021    
0022    inherits
0023    
0024        `_Point`__
0025
0026__ base.abstracts._real._Point.html        
0027    
0028    """
0029    __doc_hints__=  {'factory':'Center',
0030                    'args':['point1, point2, point3','triangle'],
0031                    'qualifier':'CENTROID',
0032                    'conditions':['points distinct'],
0033                    'otherwise':'the LineDivider with ratio=1/3'}
0034
0035
0036    def __init__(self,p1,p2,p3,**kws):
0037        self.p1=p1
0038        self.p2=p2
0039        self.p3=p3
0040        Real._Point.__init__(self,*[p1,p2,p3],**kws)
0041        self.init()
0042
0043    def findSelf(self):
0044        return self.toCentroid(self.p1,self.p2,self.p3)
0045
0046class OrthoCenter(Real._Point):
0047    """
0048*point* of intersection of the altitude of the given **3 points'** triangle
0049    
0050    inherits
0051    
0052        `_Point`__
0053
0054__ base.abstracts._real._Point.html        
0055    
0056    """
0057
0058    __doc_hints__=  {'factory':'Center',
0059                    'args':['point1, point2, point3','triangle'],
0060                    'qualifier':'ORTHO',
0061                    'conditions':['points distinct'],
0062                    'otherwise':'undefined'}
0063
0064    def __init__(self,p1,p2,p3,**kws):
0065        self.p1=p1
0066        self.p2=p2
0067        self.p3=p3
0068        Real._Point.__init__(self,*[p1,p2,p3],**kws)
0069        self.init()
0070
0071    def findSelf(self):
0072        return self.toOrthoCenter(self.p1,self.p2,self.p3)
0073
0074
0075class InCenter(Real._Point):
0076    """
0077    
0078    *point* at center of the circle inscribed in the given **3 points'** triangle
0079    
0080    inherits
0081    
0082        `_Point`__
0083
0084__ base.abstracts._real._Point.html        
0085    
0086    """
0087    __doc_hints__=  {'factory':'Center',
0088                    'args':['point1, point2, point3','triangle'],
0089                    'qualifier':'INCENTER',
0090                    'conditions':['points distinct'],
0091                    'otherwise':'undefined'}
0092
0093    def __init__(self,p1,p2,p3,**kws):
0094        self.p1=p1
0095        self.p2=p2
0096        self.p3=p3
0097        Real._Point.__init__(self,*[p1,p2,p3],**kws)
0098        self.init()
0099
0100    def findSelf(self):
0101        return self.toInCenter(self.p1,self.p2,self.p3)
0102
0103
0104class ExCenter(Real._Point):
0105    """
0106    *point* at center of the circle exscribed opposite 1st point in the 
0107    **3 points'** triangle
0108   
0109    inherits
0110    
0111        `_Point`__
0112
0113__ base.abstracts._real._Point.html        
0114    
0115    """
0116    __doc_hints__=  {'factory':'Center',
0117                    'args':['point1, point2, point3','triangle' ],
0118                    'qualifier':'EXCENTER',
0119                    'conditions':['points distinct'],
0120                    'otherwise':'undefined'}
0121
0122    def __init__(self,p1,p2,p3,**kws):
0123        self.p1=p1
0124        self.p2=p2
0125        self.p3=p3
0126        Real._Point.__init__(self,*[p1,p2,p3],**kws)
0127        self.init()
0128
0129    def findSelf(self):
0130        return self.toExCenter(self.p1,self.p2,self.p3)
0131
0132class CircumCenter(Real._Point):
0133    """
0134    
0135    *point* at center of the circle circumscribing the given **3 points'** triangle
0136    
0137    inherits
0138    
0139        `_Point`__
0140
0141__ base.abstracts._real._Point.html        
0142    
0143    """
0144    __doc_hints__=  {'factory':'Center',
0145                    'args':['point1, point2, point3','triangle' ],
0146                    'qualifier':'CIRCUM',
0147                    'conditions':['points distinct'],
0148                    'otherwise':'undefined'}
0149
0150    def __init__(self,p1,p2,p3,**kws):
0151       self.p1=p1
0152       self.p2=p2
0153       self.p3=p3
0154       Real._Point.__init__(self,*[p1,p2,p3],**kws)
0155       self.init()
0156
0157    def findSelf(self):
0158        return self.toCircumCenter(self.p1,self.p2,self.p3)
0159
0160
0161class TetraCenter(Real._Point):
0162    """
0163    
0164    *point* at center of sphere circumscribing the given **4 points'** tetrahedron
0165    
0166    inherits
0167    
0168        `_Point`__
0169
0170__ base.abstracts._real._Point.html        
0171    
0172    """
0173    __doc_hints__=  {'factory':'Center',
0174                    'args':['point1, point2, point3, point4'],
0175                    'conditions':['points distinct'],
0176                    'otherwise':'undefined'}
0177
0178    def __init__(self,p1,p2,p3,p4,**kws):
0179        self.p1=p1
0180        self.p2=p2
0181        self.p3=p3
0182        self.p4=p4
0183        Real._Point.__init__(self,*[p1,p2,p3,p4],**kws)
0184        self.init()
0185
0186    def findSelf(self):
0187        return self.toSphereCenter(self.p1,self.p2,self.p3,self.p4)
0188
0189
0190def Center(*args,**kws):
0191    """
0192    'class factory' function returns instance of object derived from the 
0193    *_Point* abstract class determined as a defined center of a given geometric object
0194    """
0195
0196    from pygeo.base.abstracts._element import method_get
0197    from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0198    from pygeo.base.analytics.pygeomath import vector
0199    from pygeo.base.support.pygeoconstants import CENTROID, ORTHO, CIRCUM,                                           INCENTER, EXCENTER
0201
0202    __sigs__ = [[vector, vector, vector],[Real._Triangle],
0203                 [vector, vector, vector,float],[Real._Triangle,float],
0204                 [vector, vector, vector, vector]]
0205
0206    t,i = method_get(__sigs__,args)
0207
0208    if t is None:
0209        raise Argument_Type_Error(__sigs__,args)
0210    else:
0211        if i==0:
0212            return CircumCenter(t[0],t[1],t[2],**kws)
0213        elif i ==1:
0214            return CircumCenter(t[0].p1,t[0].p2,t[0].p3,**kws)
0215        elif i==2:
0216            if t[3] ==ORTHO:
0217                return OrthoCenter(t[0],t[1],t[2],**kws)
0218            elif t[3]==INCENTER:
0219                return InCenter(t[0],t[1],t[2],**kws)
0220            elif t[3] ==EXCENTER:
0221                return ExCenter(t[0],t[1],t[2],**kws)
0222            elif t[3] ==CIRCUM:
0223                return CircumCenter(t[0],t[1],t[2],**kws)
0224            elif t[3] ==CENTROID:
0225                return Centroid(t[0],t[1],t[2],**kws)
0226            else:
0227                 raise Argument_Type_Error(__sigs__,args)
0228        elif i==3:
0229            if t[1] ==ORTHO:
0230                return OrthoCenter(t[0].p1,t[0].p2,t[0].p3,**kws)
0231            elif t[1]==INCENTER:
0232                return InCenter(t[0].p1,t[0].p2,t[0].p3,**kws)
0233            elif t[1] ==EXCENTER:
0234                return ExCenter(t[0].p1,t[0].p2,t[0].p3,**kws)
0235            elif t[1] ==CIRCUM:
0236                return CircumCenter(t[0].p1,t[0].p2,t[0].p3,**kws)
0237            elif t[1] ==CENTROID:
0238                return Centroid(t[0].p1,t[0].p2,t[0].p3,**kws)
0239            else:
0240                raise Argument_Type_Error(__sigs__,args)
0241        elif i==4:
0242            return TetraCenter(t[0],t[1],t[2],t[3],**kws)
0243        else:
0244            raise Argument_Type_Error(__sigs__,args)