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.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()