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 circlefrom1Line2Points(edge, p1, p2): """Return a list of circles created from an edge and two points. It calculates up to 2 possible centers. """ p1_p2 = edg(p1, p2) s = findIntersection(edge, p1_p2, True, True) if not s: return None s = s[0] v1 = p1.sub(s) v2 = p2.sub(s) projectedDist = math.sqrt(abs(v1.dot(v2))) edgeDir = vec(edge) edgeDir.normalize() projectedCen1 = App.Vector.add(s, App.Vector(edgeDir).multiply(projectedDist)) projectedCen2 = App.Vector.add( s, App.Vector(edgeDir).multiply(-projectedDist)) perpEdgeDir = edgeDir.cross(App.Vector(0, 0, 1)) perpCen1 = App.Vector.add(projectedCen1, perpEdgeDir) perpCen2 = App.Vector.add(projectedCen2, perpEdgeDir) mid = findMidpoint(p1_p2) x = DraftVecUtils.crossproduct(vec(p1_p2)) x.normalize() perp_mid = App.Vector.add(mid, x) cen1 = findIntersection(edg(projectedCen1, perpCen1), edg(mid, perp_mid), True, True) cen2 = findIntersection(edg(projectedCen2, perpCen2), edg(mid, perp_mid), True, True) circles = [] if cen1: radius = DraftVecUtils.dist(projectedCen1, cen1[0]) circles.append(Part.Circle(cen1[0], NORM, radius)) if cen2: radius = DraftVecUtils.dist(projectedCen2, cen2[0]) circles.append(Part.Circle(cen2[0], NORM, radius)) if circles: return circles else: return None