diff --git a/src/Mod/Part/App/Geometry.cpp b/src/Mod/Part/App/Geometry.cpp index 4503eda494..c76881fb4d 100644 --- a/src/Mod/Part/App/Geometry.cpp +++ b/src/Mod/Part/App/Geometry.cpp @@ -96,6 +96,7 @@ # include # include # include +# include # include # include #endif @@ -448,6 +449,41 @@ bool GeomCurve::normalAt(double u, Base::Vector3d& dir) const return false; } +bool GeomCurve::intersect( GeomCurve * c, + std::vector>& points, + double tol) const +{ + Handle(Geom_Curve) curve1 = Handle(Geom_Curve)::DownCast(handle()); + Handle(Geom_Curve) curve2 = Handle(Geom_Curve)::DownCast(c->handle()); + + try { + + if(!curve1.IsNull() && !curve2.IsNull()) { + + GeomAPI_ExtremaCurveCurve intersector(curve1, curve2); + + if (intersector.NbExtrema() == 0 || intersector.LowerDistance() > tol) { + // No intersection + return false; + } + + for (int i = 1; i <= intersector.NbExtrema(); i++) { + if (intersector.Distance(i) > tol) + continue; + + gp_Pnt p1, p2; + intersector.Points(i, p1, p2); + points.emplace_back(Base::Vector3d(p1.X(),p1.Y(),p1.Z()),Base::Vector3d(p2.X(),p2.Y(),p2.Z())); + } + + return points.size()>0?true:false; + } + } + catch (Standard_Failure& e) { + return false; + } +} + bool GeomCurve::closestParameter(const Base::Vector3d& point, double &u) const { Handle(Geom_Curve) c = Handle(Geom_Curve)::DownCast(handle()); @@ -1597,6 +1633,44 @@ void GeomArcOfConic::setXAxisDir(const Base::Vector3d& newdir) } } +bool GeomArcOfConic::intersectBasisCurves( const GeomArcOfConic * c, + std::vector>& points, + double tol) const +{ + Handle(Geom_TrimmedCurve) curve1 = Handle(Geom_TrimmedCurve)::DownCast(handle()); + Handle(Geom_TrimmedCurve) curve2 = Handle(Geom_TrimmedCurve)::DownCast(c->handle()); + + Handle(Geom_Conic) bcurve1 = Handle(Geom_Conic)::DownCast( curve1->BasisCurve() ); + Handle(Geom_Conic) bcurve2 = Handle(Geom_Conic)::DownCast( curve2->BasisCurve() ); + + try { + + if(!bcurve1.IsNull() && !bcurve2.IsNull()) { + + GeomAPI_ExtremaCurveCurve intersector(bcurve1, bcurve2); + + if (intersector.NbExtrema() == 0 || intersector.LowerDistance() > tol) { + // No intersection + return false; + } + + for (int i = 1; i <= intersector.NbExtrema(); i++) { + if (intersector.Distance(i) > tol) + continue; + + gp_Pnt p1, p2; + intersector.Points(i, p1, p2); + points.emplace_back(Base::Vector3d(p1.X(),p1.Y(),p1.Z()),Base::Vector3d(p2.X(),p2.Y(),p2.Z())); + } + + return points.size()>0?true:false; + } + } + catch (Standard_Failure& e) { + return false; + } +} + // ------------------------------------------------- TYPESYSTEM_SOURCE(Part::GeomCircle,Part::GeomConic) diff --git a/src/Mod/Part/App/Geometry.h b/src/Mod/Part/App/Geometry.h index 42387f6d07..50ea19a682 100644 --- a/src/Mod/Part/App/Geometry.h +++ b/src/Mod/Part/App/Geometry.h @@ -171,6 +171,9 @@ public: double curvatureAt(double u) const; double length(double u, double v) const; bool normalAt(double u, Base::Vector3d& dir) const; + bool intersect(GeomCurve * c, + std::vector>& points, + double tol = Precision::Confusion()) const; void reverse(void); }; @@ -366,6 +369,10 @@ public: virtual PyObject *getPyObject(void) = 0; const Handle(Geom_Geometry)& handle() const = 0; + + bool intersectBasisCurves( const GeomArcOfConic * c, + std::vector>& points, + double tol = Precision::Confusion()) const; }; class PartExport GeomCircle : public GeomConic