McNeel Wiki
Project Curves onto Breps
edit · print · help · all topics
Main Pages

AccuRender

Bongo

Brazil r/s

Developer

Flamingo

Penguin

Rhino Blogs

Rhino

Search

Languages

Česky

Deutsch

English

Español

Français

Italiano

Polish

日本語

한국어

中文(繁體)

 
.
DeveloperC++
SummaryDemonstrates how to project a curve onto a brep using the Rhino SDK.

Question

I need to be able to project curves onto a brep, but I do not function any SDK function. Is there a solution for this?

Answer

It is true that the Rhino SDK does not, currently have a function that will project a curve onto a brep. But, using some of the existing SDK 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() SDK function.
  2. Intersect the two breps using RhinoIntersectBreps() SDK 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.

  /*
  Description:
    Projects a curve onto a surface or polysurface
  Parameters:
    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.
  Returns:
    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;
  }
rename · changes · history · subscriptions · lost and found · references · file upload