std::ostringstream anOutput;
anOutput << "Length = " << std::setprecision(10) << anEdge->length();
+ if(anEdge->isLine())
+ {
+ auto point1 = anEdge->firstPoint();
+ auto point2 = anEdge->lastPoint();
+
+ anOutput <<"\n|dx| = " << std::setprecision(10) << std::abs(point2->x() - point1->x())
+ <<"\n|dy| = " << std::setprecision(10) << std::abs(point2->y() - point1->y())
+ <<"\n|dz| = " << std::setprecision(10) << std::abs(point2->z() - point1->z());
+ }
string(RESULT_ID())->setValue(anOutput.str());
AttributeDoubleArrayPtr aValues =
return;
}
- double aDistance = GeomAlgoAPI_ShapeTools::minimalDistance(aShape1, aShape2);
+ std::array<double, 3> fromShape1To2;
+ double aDistance = GeomAlgoAPI_ShapeTools::minimalDistance(aShape1, aShape2, fromShape1To2);
std::ostringstream anOutput;
- anOutput << "Distance = " << std::setprecision(10) << aDistance;
+ anOutput << "Distance = " << std::setprecision(10) << aDistance
+ <<"\n|dx| = " << std::setprecision(10) << std::abs(fromShape1To2[0])
+ <<"\n|dy| = " << std::setprecision(10) << std::abs(fromShape1To2[1])
+ <<"\n|dz| = " << std::setprecision(10) << std::abs(fromShape1To2[2]);
string(RESULT_ID())->setValue(anOutput.str());
AttributeDoubleArrayPtr aValues =
}
//==================================================================================================
-double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
- const GeomShapePtr& theShape2)
+namespace {
+
+auto getExtemaDistShape = [](const GeomShapePtr& theShape1,
+ const GeomShapePtr& theShape2) -> BRepExtrema_DistShapeShape
{
const TopoDS_Shape& aShape1 = theShape1->impl<TopoDS_Shape>();
const TopoDS_Shape& aShape2 = theShape2->impl<TopoDS_Shape>();
BRepExtrema_DistShapeShape aDist(aShape1, aShape2);
aDist.Perform();
+ return aDist;
+};
+}
+
+double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
+ const GeomShapePtr& theShape2)
+{
+ BRepExtrema_DistShapeShape aDist = getExtemaDistShape(theShape1, theShape2);
+ return aDist.IsDone() ? aDist.Value() : Precision::Infinite();
+}
+
+double GeomAlgoAPI_ShapeTools::minimalDistance(const GeomShapePtr& theShape1,
+ const GeomShapePtr& theShape2, std::array<double, 3> & fromShape1To2)
+{
+ BRepExtrema_DistShapeShape aDist = getExtemaDistShape(theShape1, theShape2);
+ const auto & pt1 = aDist.PointOnShape1(1);
+ const auto & pt2 = aDist.PointOnShape2(1) ;
+ fromShape1To2[0] = pt2.X() - pt1.X();
+ fromShape1To2[1] = pt2.Y() - pt1.Y();
+ fromShape1To2[2] = pt2.Z() - pt1.Z();
return aDist.IsDone() ? aDist.Value() : Precision::Infinite();
}
#include <GeomAPI_Shape.h>
#include <GeomAPI_Vertex.h>
-
#include <map>
#include <set>
/// \brief Calculate minimal distance between shapes
GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
const GeomShapePtr& theShape2);
+ GEOMALGOAPI_EXPORT static double minimalDistance(const GeomShapePtr& theShape1,
+ const GeomShapePtr& theShape2, std::array<double, 3> & fromShape1To2);
/// \brief Combines faces with common edges to shells, or solids to compsolids.
/// \param[in] theCompound compound of shapes.