0001"""
0002**point** determined as the intersection of given geometric objects
0003"""
0004
0005__Def__ = ['Intersect']
0006
0007__Classes__ = ['PlaneLineIntersect', 'LinesIntersect',
0008 'PlanesIntersect']
0009
0010__all__= __Classes__ + __Def__
0011
0012__doc_hints__= {'m_type':'factory'}
0013
0014import pygeo.base.abstracts._real as Real
0015
0016from pygeo.base.analytics.pygeomath import vector,solve, array, AlgebraError
0017from pygeo.base.support.pygeoopts import DO_TESTS
0018
0019
0020
0021
0022class PlaneLineIntersect(Real._Point):
0023 """
0024*point* of intersection of given **plane** and given **line**
0025
0026 inherits
0027
0028 `_Point`__
0029
0030__ base.abstracts._real._Point.html
0031
0032 """
0033
0034 __doc_hints__= {'factory':'Intersect',
0035 'args':['plane, line'],
0036 'conditions': ['line not on the plane'],
0037 'otherwise': 'None'}
0038
0039 def __init__(self,plane,line,**kws):
0040 self.plane=plane
0041 self.line=line
0042 Real._Point.__init__(self,*[plane,line],**kws)
0043 self.extend=kws.get("extend",True)
0044 self.lines=[self.line]
0045 self.init()
0046
0047 def findSelf(self):
0048 return self.toPlaneIntersection(self.plane,self.line.p1,self.line.p2)
0049
0050
0051class LinesIntersect(Real._Point):
0052 """
0053*point* of intersection of **2 given coplanar lines**
0054
0055 inherits
0056
0057 `_Point`__
0058
0059__ base.abstracts._real._Point.html
0060
0061 """
0062 __doc_hints__= {'factory':'Intersect',
0063 'args':['line1,line2'],
0064 'conditions': ['lines are coplanar'],
0065 'otherwise': 'None'}
0066
0067 def __init__(self,line1,line2,**kws):
0068 self.line1=line1
0069 self.line2=line2
0070 self.line=line1
0071 Real._Point.__init__(self,*[line1,line2],**kws)
0072 self.extend=kws.get("extend",True)
0073 self.lines=[self.line1,self.line2]
0074 self.init()
0075
0076 def findSelf(self):
0077 line1=self.line1
0078 line2=self.line2
0079 if self.toInterSection(line1.p1,line1.p2,line2.p1,line2.p2,
0080 test=DO_TESTS):
0081 return True
0082 else:
0083 print self.__class__.__name__
0084 print "lines are skew, no intersetion defined, returned False"
0085 return False
0086
0087
0088class PlanesIntersect(Real._Point):
0089 """
0090*point* of intersection of **3 given planes**
0091
0092 inherits
0093
0094 `_Point`__
0095
0096__ base.abstracts._real._Point.html
0097
0098 """
0099 __doc_hints__= {'factory':'Intersect',
0100 'args':['plane1,plane2,plane3'],
0101 'conditions': ['planes are distinct','no planes parallel'],
0102 'otherwise': 'None'}
0103
0104 def __init__(self,plane1,plane2,plane3,**kws):
0105 self.plane1=plane1
0106 self.plane2=plane2
0107 self.plane3=plane3
0108 Real._Point.__init__(self,*[plane1,plane2,plane3],**kws)
0109 self.init()
0110
0111 def findSelf(self):
0112 try:
0113 self.set(vector(solve(
0114 array([self.plane1._u,self.plane2._u,self.plane3._u]),
0115 array([self.plane1._d,self.plane2._d,self.plane3._d]))))
0116 return True
0117 except AlgebraError:
0118 print self.__class__
0119 print """defining planes are parallel ornot distinct,
0120 no intersection found, returning False"""
0121 return False
0122
0123
0124def Intersect(*args,**kws):
0125 """
0126'class factory' function returns instance of object derived from the _Point abstract
0127class determined as the intersection of given geometric objects
0128 """
0129
0130 from pygeo.base.abstracts._element import method_get
0131 from pygeo.base.support.pygeoexceptions import Argument_Type_Error
0132
0133 __sigs__=[[Real._Plane,Real._Line],[Real._Circle,Real._Line],
0134 [Real._Line,Real._Line], [Real._Plane,Real._Plane,Real._Plane]]
0135
0136 t,i = method_get(__sigs__,args)
0137
0138 if t is None:
0139 raise Argument_Type_Error(__sigs__,args)
0140 else:
0141 if i==0 or i==1:
0142 return PlaneLineIntersect(t[0],t[1],**kws)
0143 elif i==2:
0144 return LinesIntersect(t[0],t[1],**kws)
0145 elif i==3:
0146 return PlanesIntersect(t[0],t[1],t[2],**kws)
0147 else:
0148 raise Argument_Type_Error(__sigs__,args)