Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

developer:sdksamples:projectcurvestobrep [2015/09/14] (current)
Line 1: Line 1:
 +====== Project Curves onto Breps ======
 +====== C++ ======
 +> **Summary:​** //​Demonstrates 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:
 +
 +  - Extrude the curve through the brep using the RhinoExtrudeCurveStraight() SDK function.
 +  - Intersect the two breps using RhinoIntersectBreps() SDK function.
 +  - The results of the brep intersection will be the projected curves.
 +
 +The following sample code demonstrates how one might write such a function.
 +
 +   /*
 +
 +<code c++>
 +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;
 +}
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/projectcurvestobrep.txt ยท Last modified: 2015/09/14 (external edit)