Part: New routines for curve intersection

This commit is contained in:
Abdullah Tahiri
2018-10-15 14:46:54 +02:00
committed by wmayer
parent cec4fd1012
commit 8a134466ed
2 changed files with 81 additions and 0 deletions

View File

@@ -96,6 +96,7 @@
# include <GCPnts_AbscissaPoint.hxx>
# include <Precision.hxx>
# include <GeomAPI_ProjectPointOnCurve.hxx>
# include <GeomAPI_ExtremaCurveCurve.hxx>
# include <ShapeConstruct_Curve.hxx>
# include <LProp_NotDefined.hxx>
#endif
@@ -448,6 +449,41 @@ bool GeomCurve::normalAt(double u, Base::Vector3d& dir) const
return false;
}
bool GeomCurve::intersect( GeomCurve * c,
std::vector<std::pair<Base::Vector3d, Base::Vector3d>>& 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<std::pair<Base::Vector3d, Base::Vector3d>>& 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)

View File

@@ -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<std::pair<Base::Vector3d, Base::Vector3d>>& 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<std::pair<Base::Vector3d, Base::Vector3d>>& points,
double tol = Precision::Confusion()) const;
};
class PartExport GeomCircle : public GeomConic