Project Curves onto Breps

This guide demonstrates how to project a curve onto a brep using C/C++.


You want to project curves onto a brep, but you do not function any C/C++ function to do this. Is there a solution for this?


It is true that the Rhino C/C++ SDK does not currently have a function that will project a curve onto a brep. But, using some of the existing functions, you can write your own function without too much effort.

To project a curve onto a brep, you need to do the following:

  1. Extrude the curve through the brep using the RhinoExtrudeCurveStraight() function.
  2. Intersect the two breps using RhinoIntersectBreps() function.
  3. The results of the brep intersection will be the projected curves.


The following sample code demonstrates how one might write such a function…

  Projects a curve onto a surface or polysurface
  brep  - [in] The brep to project the curve onto.
  curve - [in] The curve to project.
  dir   - [in] The direction of the projection.
  tol   - [in] The intersection tolerance.
  output_curves - [out] The output curves.
                        NOTE, the caller is responsible
                        for destroying these curves.
  true if successful.
  false if unsuccessful.
bool ProjectCurveToBrep(
        const ON_Brep& brep,
        const ON_Curve& curve,
        const ON_3dVector& dir,
        double tolerance,
        ON_SimpleArray<ON_Curve*>& output_curves
  ON_3dVector n = dir;
  if( !n.Unitize() )
    return false;

  ON_BoundingBox bbox = brep.BoundingBox();
  bbox.Union( curve.BoundingBox() );

  ON_Surface* pExtrusion = RhinoExtrudeCurveStraight( &curve, dir, bbox.Diagonal().Length() );
  if( 0 == pExtrusion )
    return false;

  ON_Brep* pBrep = ON_Brep::New();
  pBrep->Create( pExtrusion );

  BOOL rc = RhinoIntersectBreps( *pBrep, brep, tolerance, output_curves );
  delete pBrep; // Don't leak...

  return ( rc ) ? true : false;