Site Tools


Differences

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

Link to this comparison view

developer:sdksamples:principalcurvaturelines [2015/09/14] (current)
Line 1: Line 1:
 +====== Create Principal Curvature Curves ======
 +====== C++ ======
 +> **Summary:​** //​Demonstrates how to use the ON_EvPrincipalCurvatures function in the Rhino SDK.//
 +
 +=====Question=====
 +Is there a method in C++ SDK to create Principal Curvature lines starting with points on surface? I see that [[developer:​opennurbs:​home|opennurbs]] has an **ON_EvPrincipalCurvatures** function, but I am not sure how I would use it.
 +
 +=====Answer=====
 +To answer your question, no, the Rhino SDK does not have a function to create these curves. But, using **ON_EvPrincipalCurvatures**,​ you can calculate them.
 +
 +Before using **ON_EvPrincipalCurvatures**,​ you will need to calculate the second derivative of the surface that the test location. Then, it is just a matter or cooking up some curves based on the results.
 +
 +The following is an example of how you might write such a command.
 +
 +===== C++ =====
 +<code c++>
 +
 +CRhinoCommand::​result CCommandTest::​RunCommand( const CRhinoCommandContext&​ context )
 +{
 +  CRhinoGetObject go;
 +  go.SetCommandPrompt( L"​Select surface"​ );
 +  go.SetGeometryFilter( CRhinoGetObject::​surface_object );
 +  go.GetObjects( 1, 1 );
 +  if( go.CommandResult() != CRhinoCommand::​success )
 +    return go.CommandResult();​
 +
 +  const CRhinoObject* obj = go.Object(0).Object();​
 +  const ON_BrepFace* face = go.Object(0).Face();​
 +  if( 0 == obj | 0 == face )
 +    return CRhinoCommand::​failure;​
 +
 +  CRhinoGetPoint gp;
 +  gp.SetCommandPrompt( L"​Select point on surface"​ );
 +  gp.Constrain( *face, obj->​Attributes().m_wire_density );
 +  gp.GetPoint();​
 +  if( gp.CommandResult() != CRhinoCommand::​success )
 +    return gp.CommandResult();​
 +
 +  double s, t;
 +  const ON_Surface* srf = gp.PointOnSurface( &s, &t );
 +  if( 0 == srf )
 +    return CRhinoCommand::​failure;​
 +
 +  ON_3dPoint P;
 +  ON_3dVector Ds, Dt, Dss, Dst, Dtt;
 +  if( !srf->​Ev2Der(s,​ t, P, Ds, Dt, Dss, Dst, Dtt) )
 +    return CRhinoCommand::​failure;​ // failed to evaluate derivatives
 +
 +  ON_3dVector N;
 +  if( !srf->​EvNormal(s,​ t, N) )
 +    return CRhinoCommand::​failure;​ // failed to evaluate normal
 +
 +  double gauss, mean, k[2];
 +  ON_3dVector K[2];
 +  if( !ON_EvPrincipalCurvatures(Ds,​ Dt, Dss, Dst, Dtt, N, &gauss, &mean, &k[0], &k[1], K[0], K[1]) )
 +    return CRhinoCommand::​failure;​ // failed to evaluate principal curvatures
 +
 +  int i;
 +  for( i = 0; i < 2; i++ ) 
 +  {
 +    if( fabs(k[i]) <= 1.0e-4 | fabs(k[i]) >= 1.0e4 ) 
 +    {
 +      // just draw a line as curvature is huge/tiny
 +      ON_Line line( P - K[i] * 5.0, P + K[i] * 5.0 );
 +      context.m_doc.AddCurveObject( line );
 +    }
 +    else 
 +    {
 +      double r = 1.0 / k[i];
 +      ON_3dPoint center = P + r * N;
 +      ON_3dPoint start = center - r * K[i];
 +      ON_3dPoint end = center + r * K[i];
 +      ON_Arc arc( start, P, end );
 +      context.m_doc.AddCurveObject( arc );
 +    }
 +  }
 +  context.m_doc.Redraw();​
 +
 +  return CRhinoCommand::​success;​
 +}
 +</​code>​
 +
 +
 +{{tag>​Developer cplusplus}}
  
developer/sdksamples/principalcurvaturelines.txt ยท Last modified: 2015/09/14 (external edit)