Table of Contents
Calculate Surface Curvature
.NET
Summary: Demonstrates how to analytically solve for gaussian, mean and principal curvatures and principal directions on a surface.
The following sample code demonstrates analytically solve for gaussian, mean and principal curvatures and principal directions on a surface.
C#
public override IRhinoCommand.result RunCommand(IRhinoCommandContext context) { // Select surface to evaluate MRhinoGetObject go = new MRhinoGetObject(); go.SetCommandPrompt("Select surface for curvature measurement"); go.SetGeometryFilter(IRhinoGetObject.GEOMETRY_TYPE_FILTER.surface_object); 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"); gp.Constrain(srf); gp.GetPoint(); 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; }