Beispiel #1
0
 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()
Beispiel #2
0
 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()