Site Tools

Calculate Surface Curvature

Summary: Demonstrates how to analytically solve for gaussian, mean and principal curvatures and principal directions on a surface.
NOTICE: The Rhino.NET SDK is deprecated in Rhino 5. This example adapted for the new RhinoCommon SDK is here

The following sample demonstrates analytically solving for gaussian, mean and principal curvatures and principal directions on a surface.


public override IRhinoCommand.result RunCommand(IRhinoCommandContext context)
  // Select surface to evaluate
  MRhinoGetObject go = new MRhinoGetObject();
  go.SetCommandPrompt("Select surface for curvature measurement");
  go.GetObjects(1, 1);
  if (go.CommandResult() != IRhinoCommand.result.success)
    return go.CommandResult();
  // Validate selection
  MRhinoObjRef objref = go.Object(0);
  IOnSurface srf = objref.Surface();
  if (srf == null)
    return IRhinoCommand.result.failure;
  // Select surface to evaluate
  MRhinoGetPoint gp = new MRhinoGetPoint();
  gp.SetCommandPrompt("Select point on surface for curvature measurement");
  if (gp.CommandResult() != IRhinoCommand.result.success)
    return gp.CommandResult();
  // Calculate closest point on surface to test point
  double s = 0.0, t = 0.0;
  if (!srf.GetClosestPoint(gp.Point(), ref s, ref t))
    return IRhinoCommand.result.failure;
  // Calculate the second derivative of the surface at s,t
  On3dPoint P = new On3dPoint();
  On3dVector Ds = new On3dVector();
  On3dVector Dt = new On3dVector();
  On3dVector Dss = new On3dVector();
  On3dVector Dst = new On3dVector();
  On3dVector Dtt = new On3dVector();
  if (!srf.Ev2Der(s, t, ref P, ref Ds, ref Dt, ref Dss, ref Dst, ref Dtt))
    return IRhinoCommand.result.failure;
  // Calculate normal to surface at s,t
  On3dVector N = new On3dVector();
  if (!srf.EvNormal(s, t, ref N))
    return IRhinoCommand.result.failure;
  // Calculate the surface prinicpal curvatures
  double gauss = 0.0, mean = 0.0;
  double k0 = 0.0, k1 = 0.0;
  On3dVector K0 = new On3dVector();
  On3dVector K1 = new On3dVector();
  if (!OnUtil.ON_EvPrincipalCurvatures(Ds, Dt, Dss, Dst, Dtt, N, ref gauss, ref mean, ref k0, ref k1, ref K0, ref K1))
    return IRhinoCommand.result.failure;
  // Print the results
  RhUtil.RhinoApp().Print(string.Format("Surface curvature evaluation at parameter: ({0}, {1})\n", s, t));
  RhUtil.RhinoApp().Print(string.Format("  3-D Point: ({0}, {1}, {2})\n", P.x, P.y, P.z));
  RhUtil.RhinoApp().Print(string.Format("  3-D Normal: ({0}, {1}, {2})\n", N.x, N.y, N.z));
  RhUtil.RhinoApp().Print(string.Format("  Maximum principal curvature: {0} ({1}, {2}, {3})\n", k0, K0.x, K0.y, K0.z));
  RhUtil.RhinoApp().Print(string.Format("  Minimum principal curvature: {0} ({1}, {2}, {3})\n", k1, K1.x, K1.y, K1.z));
  RhUtil.RhinoApp().Print(string.Format("  Gaussian curvature: {0}\n", gauss));
  RhUtil.RhinoApp().Print(string.Format("  Mean curvature: {0}\n", mean));
  return IRhinoCommand.result.success;
developer/sdksamples/principalcurvature.txt ยท Last modified: 2014/01/23 (external edit)