Which class should I use for extremum computation?

Hello,

I want to compute the minimum distance between a gp_Pnt and an Adaptor3d_Curve and between an Adaptor3d_Curve and an Adaptor3d_Surface. For point and curve I have used the class Extrema_ExtPC and it works fine. Therefore I wanted to use Extrema_ExtCS for point and surface, but I have found that there is also another class Extrema_GenExtCS, which seems to do the same.

Which class should I use? Extrema_ExtCS or Extrema_GenExtCS? What does "Gen" stand for? Or is there even a better algorithm somewhere?

Thank you very much!
Benjamin

Rodrigo Castro Andrade's picture

Hello Benjamin,

I'm REALLY new to OCC, but I suppose the following may help you (copied from the OCC User Guide, and I don't know how up-to-date that is):

"
Extrema

The classes to calculate the minimum distance between points, curves, and surfaces in 2d and 3d are provided by GeomAPI and Geom2dAPI packages.

These packages calculate the extrema of distance between:

point and a curve,
point and a surface,
two curves,
a curve and a surface,
two surfaces.

Extrema between Curves

The Geom2dAPI_ExtremaCurveCurve class allows calculation of all extrema between two 2D geometric curves. Extrema are the lengths of the segments orthogonal to two curves.

The GeomAPI_ExtremaCurveCurve class allows calculation of all extrema between two 3D geometric curves. Extrema are the lengths of the segments orthogonal to two curves.
Extrema between Curve and Surface

The GeomAPI_ExtremaCurveSurface class allows calculation of all extrema between a 3D curve and a surface. Extrema are the lengths of the segments orthogonal to the curve and the surface.
Extrema between Surfaces

The GeomAPI_ExtremaSurfaceSurface class allows calculation of all extrema between two surfaces. Extrema are the lengths of the segments orthogonal to two surfaces."

In case this does not work, I would also like to know the solution for your problem.

Rodrigo

Benjamin Bihler's picture

Hello Rodrigo,

thank you for your answer, but those classes I cannot use. I OCC there is a distinction between pure geometry and topology. GeomAPI_ExtremaCurveSurface takes Handle(Geom_Curve) and Handle(Geom_Surface) as input, but my input is of the type Adaptor3d_Curve and Adaptor3d_Surface.

Both classes, Extrema_GenExtCS and Extrema_ExtCS, take the input I have, but I don't know the difference between them.

Regards,
Benjamin

pizibing's picture

I am also tried the Extrema_ExtPC, but found that this class does not work robust for a given points to compute the min distance from a point to a curve.

Have you try the other class, have any progress?

Thanks

Yi

Benjamin Bihler's picture

Hi Yi,

I am using Extrema_ExtPC like this:

double GeometricUtilities::getDistance(const gp_Pnt& point,
const BRepAdaptor_CompCurve& curve)
{
Extrema_ExtPC extrema(point, curve);

if (extrema.IsDone() && (0 != extrema.NbExt()))
{
double minimumDistance = RealLast();

for (int extremumIndex = 1; extremumIndex <= extrema.NbExt();
++extremumIndex)
{
if (extrema.IsMin(extremumIndex))
{
double distance = sqrt(extrema.SquareDistance(extremumIndex));

if (distance < minimumDistance)
{
minimumDistance = distance;
}
}
}

return minimumDistance;
}

throw new Exception("Distance could not be computed.", __TRACE__);
}

Up to now I have never seen the exception. Therefore actually for me it has worked stable yet.

Regards,
Benjamin

jelle's picture

Thanks for sharing Benjamin,

double distance = sqrt(extrema.SquareDistance(extremumIndex));
^
Are you sure the call to sqrt is needed, since you are calling the SqrtDistance method, I'd find it a little confusing?

-jelle

Benjamin Bihler's picture

With SquareDistance they do not mean the square root of the distance but distance*distance. Therefore to get the distance I have to compute the square root of the square of this distance.