def circleFromPointLineRadius(point, edge, radius): """Return a list of circles from one point, one edge, and one radius. It calculates up to 2 possible centers. """ dist = findDistance(point, edge, False) center1 = None center2 = None if dist.Length == 0: segment = vec(edge) perpVec = DraftVecUtils.crossproduct(segment) perpVec.normalize() normPoint_c1 = App.Vector(perpVec).multiply(radius) normPoint_c2 = App.Vector(perpVec).multiply(-radius) center1 = point.add(normPoint_c1) center2 = point.add(normPoint_c2) elif dist.Length > 2 * radius: return None elif dist.Length == 2 * radius: normPoint = point.add(findDistance(point, edge, False)) dummy = (normPoint.sub(point)).multiply(0.5) cen = point.add(dummy) circ = Part.Circle(cen, NORM, radius) if circ: return [circ] else: return None else: normPoint = point.add(findDistance(point, edge, False)) normDist = DraftVecUtils.dist(normPoint, point) dist = math.sqrt(radius**2 - (radius - normDist)**2) centerNormVec = DraftVecUtils.scaleTo(point.sub(normPoint), radius) edgeDir = edge.Vertexes[0].Point.sub(normPoint) edgeDir.normalize() center1 = centerNormVec.add( normPoint.add(App.Vector(edgeDir).multiply(dist))) center2 = centerNormVec.add( normPoint.add(App.Vector(edgeDir).multiply(-dist))) circles = [] if center1: circ = Part.Circle(center1, NORM, radius) if circ: circles.append(circ) if center2: circ = Part.Circle(center2, NORM, radius) if circ: circles.append(circ) if circles: return circles else: return None
def mirror(point, edge): """Find mirror point relative to an edge.""" normPoint = point.add(findDistance(point, edge, False)) if normPoint: normPoint_point = Vector.sub(point, normPoint) normPoint_refl = normPoint_point.negative() refl = Vector.add(normPoint, normPoint_refl) return refl else: return None
def circleFrom3LineTangents(edge1, edge2, edge3): """Return a list of circles from three edges. It calculates up to 6 possible centers. """ def rot(ed): geo = Part.LineSegment(v1(ed), v1(ed).add(DraftVecUtils.rotate(vec(ed), math.pi/2))) return geo.toShape() bis12 = angleBisection(edge1, edge2) bis23 = angleBisection(edge2, edge3) bis31 = angleBisection(edge3, edge1) intersections = [] intsec = findIntersection(bis12, bis23, True, True) if intsec: radius = findDistance(intsec[0], edge1).Length intersections.append(Part.Circle(intsec[0], NORM, radius)) intsec = findIntersection(bis23, bis31, True, True) if intsec: radius = findDistance(intsec[0], edge1).Length intersections.append(Part.Circle(intsec[0], NORM, radius)) intsec = findIntersection(bis31, bis12, True, True) if intsec: radius = findDistance(intsec[0], edge1).Length intersections.append(Part.Circle(intsec[0], NORM, radius)) intsec = findIntersection(rot(bis12), rot(bis23), True, True) if intsec: radius = findDistance(intsec[0], edge1).Length intersections.append(Part.Circle(intsec[0], NORM, radius)) intsec = findIntersection(rot(bis23), rot(bis31), True, True) if intsec: radius = findDistance(intsec[0], edge1).Length intersections.append(Part.Circle(intsec[0], NORM, radius)) intsec = findIntersection(rot(bis31), rot(bis12), True, True) if intsec: radius = findDistance(intsec[0], edge1).Length intersections.append(Part.Circle(intsec[0], NORM, radius)) circles = [] for intsec in intersections: exists = False for cir in circles: if DraftVecUtils.equals(cir.Center, intsec.Center): exists = True break if not exists: circles.append(intsec) if circles: return circles else: return None
def polarInversion(circle, edge): """Return the inversion pole of a line. The edge is the polar. The nearest point on the line is inversed. http://mathworld.wolfram.com/InversionPole.html """ if geomType(circle) != "Circle" or geomType(edge) != "Line": print("debug: circleInversionPole bad parameters! Must be a circle.") return None nearest = circle.Curve.Center.add( findDistance(circle.Curve.Center, edge, False)) if nearest: inversionPole = pointInversion(circle, nearest) if inversionPole: return inversionPole return None
def circleFrom3LineTangents(edge1, edge2, edge3): """circleFrom3LineTangents(edge,edge,edge)""" def rot(ed): return Part.LineSegment( v1(ed), v1(ed).add(DraftVecUtils.rotate(vec(ed), math.pi / 2))).toShape() bis12 = angleBisection(edge1, edge2) bis23 = angleBisection(edge2, edge3) bis31 = angleBisection(edge3, edge1) intersections = [] int = findIntersection(bis12, bis23, True, True) if int: radius = findDistance(int[0], edge1).Length intersections.append(Part.Circle(int[0], NORM, radius)) int = findIntersection(bis23, bis31, True, True) if int: radius = findDistance(int[0], edge1).Length intersections.append(Part.Circle(int[0], NORM, radius)) int = findIntersection(bis31, bis12, True, True) if int: radius = findDistance(int[0], edge1).Length intersections.append(Part.Circle(int[0], NORM, radius)) int = findIntersection(rot(bis12), rot(bis23), True, True) if int: radius = findDistance(int[0], edge1).Length intersections.append(Part.Circle(int[0], NORM, radius)) int = findIntersection(rot(bis23), rot(bis31), True, True) if int: radius = findDistance(int[0], edge1).Length intersections.append(Part.Circle(int[0], NORM, radius)) int = findIntersection(rot(bis31), rot(bis12), True, True) if int: radius = findDistance(int[0], edge1).Length intersections.append(Part.Circle(int[0], NORM, radius)) circles = [] for int in intersections: exists = False for cir in circles: if DraftVecUtils.equals(cir.Center, int.Center): exists = True break if not exists: circles.append(int) if circles: return circles else: return None
def polarInversion(circle, edge): """Return the inversion pole of a line. polarInversion(circle, edge): edge ... The polar. i.e. The nearest point on the line is inversed. http://mathworld.wolfram.com/InversionPole.html """ if (geomType(circle) == "Circle") and (geomType(edge) == "Line"): nearest = circle.Curve.Center.add( findDistance(circle.Curve.Center, edge, False)) if nearest: inversionPole = pointInversion(circle, nearest) if inversionPole: return inversionPole else: FreeCAD.Console.PrintMessage( "debug: circleInversionPole bad parameters!\n") return None