def findHomotheticCenterOfCircles(circle1, circle2): """Calculate the homothetic center(s) of two circles. http://en.wikipedia.org/wiki/Homothetic_center http://mathworld.wolfram.com/HomotheticCenter.html """ if (geomType(circle1) == "Circle") and (geomType(circle2) == "Circle"): if DraftVecUtils.equals(circle1.Curve.Center, circle2.Curve.Center): return None cen1_cen2 = Part.LineSegment(circle1.Curve.Center, circle2.Curve.Center).toShape() cenDir = vec(cen1_cen2) cenDir.normalize() # Get the perpedicular vector. perpCenDir = cenDir.cross(Vector(0, 0, 1)) perpCenDir.normalize() # Get point on first circle p1 = Vector.add(circle1.Curve.Center, Vector(perpCenDir).multiply(circle1.Curve.Radius)) centers = [] # Calculate inner homothetic center # Get point on second circle p2_inner = Vector.add( circle1.Curve.Center, Vector(perpCenDir).multiply(-circle1.Curve.Radius)) hCenterInner = DraftVecUtils.intersect(circle1.Curve.Center, circle2.Curve.Center, p1, p2_inner, True, True) if hCenterInner: centers.append(hCenterInner) # Calculate outer homothetic center (only exists of the circles have different radii) if circle1.Curve.Radius != circle2.Curve.Radius: # Get point on second circle p2_outer = Vector.add( circle1.Curve.Center, Vector(perpCenDir).multiply(circle1.Curve.Radius)) hCenterOuter = DraftVecUtils.intersect(circle1.Curve.Center, circle2.Curve.Center, p1, p2_outer, True, True) if hCenterOuter: centers.append(hCenterOuter) if len(centers): return centers else: return None else: FreeCAD.Console.PrintMessage( "debug: findHomotheticCenterOfCirclescleFrom3tan bad parameters!\n" ) return None
def findHomotheticCenterOfCircles(circle1, circle2): """Calculate the homothetic centers from two circles. Return None if the objects are not circles, or if they are concentric. http://en.wikipedia.org/wiki/Homothetic_center http://mathworld.wolfram.com/HomotheticCenter.html """ if (geomType(circle1) == "Circle" and geomType(circle2) == "Circle"): print("debug: findHomotheticCenterOfCircles bad parameters!") return None if DraftVecUtils.equals(circle1.Curve.Center, circle2.Curve.Center): return None cen1_cen2 = Part.LineSegment(circle1.Curve.Center, circle2.Curve.Center).toShape() cenDir = vec(cen1_cen2) cenDir.normalize() # Get the perpedicular vector. perpCenDir = cenDir.cross(App.Vector(0, 0, 1)) perpCenDir.normalize() # Get point on first circle p1 = App.Vector.add(circle1.Curve.Center, App.Vector(perpCenDir).multiply(circle1.Curve.Radius)) centers = [] # Calculate inner homothetic center # Get point on second circle p2_inner = App.Vector.add(circle1.Curve.Center, App.Vector(perpCenDir).multiply(-circle1.Curve.Radius)) hCenterInner = DraftVecUtils.intersect(circle1.Curve.Center, circle2.Curve.Center, p1, p2_inner, True, True) if hCenterInner: centers.append(hCenterInner) # Calculate outer homothetic center; it only exists if the circles # have different radii if circle1.Curve.Radius != circle2.Curve.Radius: # Get point on second circle p2_outer = App.Vector.add(circle1.Curve.Center, App.Vector(perpCenDir).multiply(circle1.Curve.Radius)) hCenterOuter = DraftVecUtils.intersect(circle1.Curve.Center, circle2.Curve.Center, p1, p2_outer, True, True) if hCenterOuter: centers.append(hCenterOuter) if centers: return centers else: return None