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()
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 GetRadiusPointFromExt(self, x, y): """ get The intersecrion point from the line(x,y,cx,cy) and the circle """ _cx, _cy = self.center.getCoords() _r = self.radius centerPoint = Point(_cx, _cy) outPoint = Point(x, y) vector = Vector(outPoint, centerPoint) vNorm = vector.Norm() newNorm = abs(vNorm - _r) magVector = vector.Mag() magVector.Mult(newNorm) newPoint = magVector.Point() intPoint = Point(outPoint + newPoint) return intPoint.getCoords()
def GetRadiusPointFromExt(self,x,y): """ get The intersecrion point from the line(x,y,cx,cy) and the circle """ _cx, _cy = self.center.getCoords() _r = self.radius centerPoint=Point(_cx,_cy) outPoint=Point(x,y) vector=Vector(outPoint,centerPoint) vNorm=vector.norm() newNorm=abs(vNorm-_r) magVector=vector.mag() magVector.mult(newNorm) newPoint=magVector.point() intPoint=Point(outPoint+newPoint) return intPoint.getCoords()
def decodeText(self, value): """ encode the text given from the user """ point = None distance = None entitys = None text = None angle = None try: try: raise self.kernelCommand.activeException()(None) except ExcPoint: if value.find(',') > -1: # ABSOLUTE CARTESIAN INPUT x, y = value.split(',') point = Point(float(x), float(y)) elif value.find('*') > -1: # RELATIVE CARTESIAN INPUT x, y = value.split('*') x = self.scene.fromPoint.getx() + float(x) y = self.scene.fromPoint.gety() + float(y) point = Point(x, y) # implement here relative coordinates elif value.find('<') > -1: pass # implement here polar coordinates else: # DISTANCE+ANGLE FROM SCENE set coordinate based on distance input and angle from mouse position on the scene d = float(value) pX = self.scene.mouseOnSceneX pY = self.scene.mouseOnSceneY if self.scene.forceDirection is not None: pc = Point(pX, pY) pc = self.correctPositionForcedDirection( pc, self.scene.forceDirection) pX, pY = pc.getCoords() # if frompoint is not none else exception dx = pX - self.scene.fromPoint.getx() dy = pY - self.scene.fromPoint.gety() a = math.atan2(dy, dx) x = self.scene.fromPoint.getx() + d * math.cos(a) y = self.scene.fromPoint.gety() + d * math.sin(a) point = Point(x, y) except (ExcEntity, ExcMultiEntity): entitys = self.getIdsString(value) except ExcEntityPoint: #(4@10,20) id, p = value.split('@') x, y = p.split(',') point = Point(float(x), float(y)) entitys = self.getIdsString(id) return except (ExcLenght, ExcInt, ExcBool): distance = value except (ExcAngle): angle = value except (ExcText): text = value except: raise PyCadWrongImputData( "BaseCommand : Wrong imput parameter for the command") return (point, entitys, distance, angle, text)
def decodeText(self, value): """ encode the text given from the user """ point = None distance = None entitys = None text = None angle = None try: try: raise self.kernelCommand.activeException()(None) except ExcPoint: if value.find(',') > -1: # ABSOLUTE CARTESIAN INPUT x, y = value.split(',') point = Point(float(x), float(y)) elif value.find('*') > -1: # RELATIVE CARTESIAN INPUT x, y = value.split('*') x = self.scene.fromPoint.getx() + float(x) y = self.scene.fromPoint.gety() + float(y) point = Point(x, y) # implement here relative coordinates elif value.find('<') > -1: pass # implement here polar coordinates else: # DISTANCE+ANGLE FROM SCENE set coordinate based on distance input and angle from mouse position on the scene d = float(value) pX = self.scene.mouseOnSceneX pY = self.scene.mouseOnSceneY if self.scene.forceDirection is not None: pc = Point(pX, pY) pc = self.correctPositionForcedDirection(pc, self.scene.forceDirection) pX, pY = pc.getCoords() # if frompoint is not none else exception dx = pX - self.scene.fromPoint.getx() dy = pY - self.scene.fromPoint.gety() a = math.atan2(dy, dx) x = self.scene.fromPoint.getx() + d * math.cos(a) y = self.scene.fromPoint.gety() + d * math.sin(a) point = Point(x, y) except (ExcEntity, ExcMultiEntity): entitys = self.getIdsString(value) except ExcEntityPoint: #(4@10,20) id, p = value.split('@') x, y = p.split(',') point = Point(float(x), float(y)) entitys = self.getIdsString(id) return except (ExcLenght, ExcInt, ExcBool): distance = value except(ExcAngle): angle = value except(ExcText): text = value except: raise PyCadWrongImputData("BaseCommand : Wrong imput parameter for the command") return (point,entitys, distance,angle, text)