Constructing a Median Curve

The function

MbResultType MedianCurve( const MbCurve &              baseCurve,
                          const MbCurve &              responseCurve,
                          const MbMedianCurveParams &  params,
                                MbMedianCurveResults & results );

constructs a NURBS approximation of a median curve.

A median curve is the locus of points equidistant from two given chains of curves. A base curve and a response curve are specified for construction. The position of the median curve is determined by the normal directions of the input curves and the parameters that control normal inversion. The input curves must not contain kinks or self-intersections.

Figs. 1 and 2 show examples of median curves between closed and open input curves. The input curves are shown in light blue, and the median curves are shown in lilac:

../../../../_images/Constructing_a_Median_Curve1.png

Fig. 1

../../../../_images/Constructing_a_Median_Curve2.png

Fig. 2

Function parameters:

  • baseCurve – the base curve;

  • responseCurve – the response curve;

  • params – the median curve construction parameters;

  • results – the construction results.

If the function completes successfully, it returns rt_Success. Otherwise, it may return the following error codes from the MbResultType enumeration:

  • rt_IncorrectInitialData – the response curve or the base curve has first-derivative discontinuities;

  • rt_Error – a construction error;

  • rt_TooFewPoints – a construction error caused by an insufficient number of median curve points found;

  • rt_ApproxError – an error constructing the smoothing NURBS-curve.

The function is declared in the action_curve.h file.

The construction parameters are specified by an object of the MbMedianCurveParams class, declared in the op_curve_parameter.h file:

  • invNormals – a pair of normal inversion flags. The combination of normal directions determines the region in which the median curve is constructed. If the parameters are set to true, the median curve is constructed on the outer side of the curves. If normal inversion is disabled (false), the median curve is constructed on the inner side of the curves;

  • respCurveExt – a flag that enables the use of the response curve extension. If the parameter is set to true, points on the response curve extension may be used for construction. If it is set to false, portions of the median curve that require extending the response curve are excluded from the result;

  • smoothing – a flag that specifies whether to construct a smoothing spline. If set to true, a smoothing spline is constructed; if set to false, an interpolating spline is constructed;

  • smoothingTolerance – the required approximation accuracy for constructing the smoothing spline (used when smoothing is set to true).

Normal inversion, response curve extension, and smoothing are disabled by default.

For each input curve, either the original or the opposite normal direction can be used. The combination of invNormals flags allows selecting one of the possible regions in which the median curve can lie (see Figs. 3 and 4; the curve normals are shown in green):

../../../../_images/Constructing_a_Median_Curve3.png

Fig. 3

../../../../_images/Constructing_a_Median_Curve4.png

Fig. 4

If response curve extension is disabled, the result is limited to portions corresponding to the original parameter range of the response curve. Therefore, certain combinations of normal directions and disabled response curve extension may yield no result.

The operation results are returned in an object of the MbMedianCurveResults class.

The constructed curve can be retrieved using the method

const c3d::PlaneCurveSPtr & GetMedianCurve() const;

In general, the locus of equidistant points may consist of several disconnected curves. In the current implementation, the function returns a single curve - the longest of the portions found.

Usage Example

In the following example, a median curve is constructed between two arcs. The normal direction of the response curve is inverted, and its extension is disabled:

MbArc baseCurve( MbCartPoint( 0.0, 0.0 ), 3.0 );
MbArc responseCurve( MbCartPoint( 0.0, 0.0 ), 1.0, 0.0, 4.0, true );

MbMedianCurveParams params( { false, true }, false );
MbMedianCurveResults results;

MbResultType result = ::MedianCurve( baseCurve,
                                    responseCurve,
                                    params,
                                    results );

if ( result == rt_Success ) {
  const c3d::PlaneCurveSPtr & medianCurve = results.GetMedianCurve();
}