def getIntersection(self, entity, point): """ this function compute the snap intersection point """ returnVal=None distance=None if entity!=None: geoEntityFrom=entity.geoItem entityList=self._scene.collidingItems(entity) for ent in entityList: if not isinstance(ent,BaseEntity): continue if isinstance(ent, BaseEntity): intPoint=find_intersections(ent.geoItem,geoEntityFrom) for tp in intPoint: iPoint=Point(tp[0], tp[1]) if distance==None: distance=iPoint.dist(point) returnVal=iPoint else: spoolDist=iPoint.dist(point) if distance>spoolDist: distance=spoolDist returnVal=iPoint return returnVal
def getIntersection(self, entity, point): """ this function compute the snap intersection point """ returnVal = None distance = None if entity != None: geoEntityFrom = entity.geoItem entityList = self._scene.collidingItems(entity) for ent in entityList: if not isinstance(ent, BaseEntity): continue if isinstance(ent, BaseEntity): intPoint = find_intersections(ent.geoItem, geoEntityFrom) for tp in intPoint: iPoint = Point(tp[0], tp[1]) if distance == None: distance = iPoint.dist(point) returnVal = iPoint else: spoolDist = iPoint.dist(point) if distance > spoolDist: distance = spoolDist returnVal = iPoint return returnVal
def GetTangentPoint(self,x,y,outx,outy): """ Get the tangent from an axternal point args: x,y is a point near the circle xout,yout is a point far from the circle return: a tuple(x,y,x1,xy) that define the tangent line """ firstPoint=Point(x,y) fromPoint=Point(outx,outy) twoPointDistance=self.center.dist(fromPoint) if(twoPointDistance<self.radius): return None,None originPoint=Point(0.0,0.0) tanMod=math.sqrt(pow(twoPointDistance,2)-pow(self.radius,2)) tgAngle=math.asin(self.radius/twoPointDistance) #Compute the x versor xPoint=Point(1.0,0.0) xVector=Vector(originPoint,xPoint) twoPointVector=Vector(fromPoint,self.center) rightAngle=twoPointVector.ang(xVector) cx,cy=self.center.getCoords() if(outy>cy): # stupid situation rightAngle=-rightAngle posAngle=rightAngle+tgAngle negAngle=rightAngle-tgAngle # Compute the Positive Tangent xCord=math.cos(posAngle) yCord=math.sin(posAngle) dirPoint=Point(xCord,yCord) # Versor that point at the tangentPoint ver=Vector(originPoint,dirPoint) ver.mult(tanMod) tangVectorPoint=ver.Point() posPoint=Point(tangVectorPoint+(outx,outy)) # Compute the Negative Tangent xCord=math.cos(negAngle) yCord=math.sin(negAngle) dirPoint=Point(xCord,yCord)#Versor that point at the tangentPoint ver=Vector(originPoint,dirPoint) ver.mult(tanMod) tangVectorPoint=ver.point() negPoint=Point(tangVectorPoint+(outx,outy)) if(firstPoint.dist(posPoint)<firstPoint.dist(negPoint)): return posPoint.getCoords() else: return negPoint.getCoords()
def GetTangentPoint(self, x, y, outx, outy): """ Get the tangent from an axternal point args: x,y is a point near the circle xout,yout is a point far from the circle return: a tuple(x,y,x1,xy) that define the tangent line """ firstPoint = Point(x, y) fromPoint = Point(outx, outy) twoPointDistance = self.center.dist(fromPoint) if (twoPointDistance < self.radius): return None, None originPoint = Point(0.0, 0.0) tanMod = math.sqrt(pow(twoPointDistance, 2) - pow(self.radius, 2)) tgAngle = math.asin(self.radius / twoPointDistance) #Compute the x versor xPoint = Point(1.0, 0.0) xVector = Vector(originPoint, xPoint) twoPointVector = Vector(fromPoint, self.center) rightAngle = twoPointVector.ang(xVector) cx, cy = self.center.getCoords() if (outy > cy): # stupid situation rightAngle = -rightAngle posAngle = rightAngle + tgAngle negAngle = rightAngle - tgAngle # Compute the Positive Tangent xCord = math.cos(posAngle) yCord = math.sin(posAngle) dirPoint = Point(xCord, yCord) # Versor that point at the tangentPoint ver = Vector(originPoint, dirPoint) ver.mult(tanMod) tangVectorPoint = ver.Point() posPoint = Point(tangVectorPoint + (outx, outy)) # Compute the Negative Tangent xCord = math.cos(negAngle) yCord = math.sin(negAngle) dirPoint = Point(xCord, yCord) #Versor that point at the tangentPoint ver = Vector(originPoint, dirPoint) ver.mult(tanMod) tangVectorPoint = ver.point() negPoint = Point(tangVectorPoint + (outx, outy)) if (firstPoint.dist(posPoint) < firstPoint.dist(negPoint)): return posPoint.getCoords() else: return negPoint.getCoords()