+/// \brief Find intersections of line shifted along normal direction in both sides
+/// and a circle with extended radius
+void possibleFilletCenterLineArc(
+ std::shared_ptr<GeomAPI_XY> theStartLine, std::shared_ptr<GeomAPI_Dir2d> theDirLine,
+ std::shared_ptr<GeomAPI_XY> theCenterArc, double theRadiusArc,
+ double theRadius, std::list< std::shared_ptr<GeomAPI_XY> >& theCenters)
+{
+ std::shared_ptr<GeomAPI_Dir2d> aDirT(new GeomAPI_Dir2d(-theDirLine->y(), theDirLine->x()));
+ std::shared_ptr<GeomAPI_XY> aPnt;
+ double aDirNorm2 = theDirLine->dot(theDirLine);
+ double aRad = 0.0;
+ double aDirX = theDirLine->x();
+ double aDirX2 = theDirLine->x() * theDirLine->x();
+ double aDirY2 = theDirLine->y() * theDirLine->y();
+ double aDirXY = theDirLine->x() * theDirLine->y();
+ for (double aStepA = -1.0; aStepA <= 1.0; aStepA += 2.0) {
+ aPnt = theStartLine->added(aDirT->xy()->multiplied(aStepA * theRadius));
+ double aCoeff = aDirT->xy()->dot(aPnt->decreased(theCenterArc));
+ double aCoeff2 = aCoeff * aCoeff;
+ for (double aStepB = -1.0; aStepB <= 1.0; aStepB += 2.0) {
+ aRad = theRadiusArc + aStepB * theRadius;
+ double aD = aRad * aRad * aDirNorm2 - aCoeff2;
+ if (aD < 0.0)
+ continue;
+ double aDs = sqrt(aD);
+ double x1 = theCenterArc->x() + (aCoeff * aDirT->x() - aDirT->y() * aDs) / aDirNorm2;
+ double x2 = theCenterArc->x() + (aCoeff * aDirT->x() + aDirT->y() * aDs) / aDirNorm2;
+ double y1 = (aDirX2 * aPnt->y() + aDirY2 * theCenterArc->y() -
+ aDirXY * (aPnt->x() - theCenterArc->x()) - theDirLine->y() * aDs) / aDirNorm2;
+ double y2 = (aDirX2 * aPnt->y() + aDirY2 * theCenterArc->y() -
+ aDirXY * (aPnt->x() - theCenterArc->x()) + theDirLine->y() * aDs) / aDirNorm2;
+
+ std::shared_ptr<GeomAPI_XY> aPoint1(new GeomAPI_XY(x1, y1));
+ theCenters.push_back(aPoint1);
+ std::shared_ptr<GeomAPI_XY> aPoint2(new GeomAPI_XY(x2, y2));
+ theCenters.push_back(aPoint2);
+ }
+ }
+}
+
+/// \brief Find intersections of two circles with extended radii
+void possibleFilletCenterArcArc(
+ std::shared_ptr<GeomAPI_XY> theCenterA, double theRadiusA,
+ std::shared_ptr<GeomAPI_XY> theCenterB, double theRadiusB,
+ double theRadius, std::list< std::shared_ptr<GeomAPI_XY> >& theCenters)
+{
+ std::shared_ptr<GeomAPI_XY> aCenterDir = theCenterB->decreased(theCenterA);
+ double aCenterDist2 = aCenterDir->dot(aCenterDir);
+ double aCenterDist = sqrt(aCenterDist2);
+
+ double aRadA, aRadB;
+ for (double aStepA = -1.0; aStepA <= 1.0; aStepA += 2.0) {
+ aRadA = theRadiusA + aStepA * theRadius;
+ for (double aStepB = -1.0; aStepB <= 1.0; aStepB += 2.0) {
+ aRadB = theRadiusB + aStepB * theRadius;
+ if (aRadA + aRadB < aCenterDist || fabs(aRadA - aRadB) > aCenterDist)
+ continue; // there is no intersections
+
+ double aMedDist = (aRadA * aRadA - aRadB * aRadB + aCenterDist2) / (2.0 * aCenterDist);
+ double aHeight = sqrt(aRadA * aRadA - aMedDist * aMedDist);
+
+ double x1 = theCenterA->x() + (aMedDist * aCenterDir->x() + aCenterDir->y() * aHeight) / aCenterDist;
+ double y1 = theCenterA->y() + (aMedDist * aCenterDir->y() - aCenterDir->x() * aHeight) / aCenterDist;
+
+ double x2 = theCenterA->x() + (aMedDist * aCenterDir->x() - aCenterDir->y() * aHeight) / aCenterDist;
+ double y2 = theCenterA->y() + (aMedDist * aCenterDir->y() + aCenterDir->x() * aHeight) / aCenterDist;
+
+ std::shared_ptr<GeomAPI_XY> aPoint1(new GeomAPI_XY(x1, y1));
+ theCenters.push_back(aPoint1);
+ std::shared_ptr<GeomAPI_XY> aPoint2(new GeomAPI_XY(x2, y2));
+ theCenters.push_back(aPoint2);
+ }
+ }
+}
+