usingRhino;usingRhino.Input.Custom;usingRhino.DocObjects;usingRhino.Commands;namespace examples_cs
{publicclassNormalDirectionOfBrepFaceCommand:Command{publicoverridestringEnglishName{get{return"csDetermineNormalDirectionOfBrepFace";}}protectedoverrideResultRunCommand(RhinoDoc doc,RunMode mode){// select a surfacevar gs =newGetObject();
gs.SetCommandPrompt("select surface");
gs.GeometryFilter=ObjectType.Surface;
gs.DisablePreSelect();
gs.SubObjectSelect=false;
gs.Get();if(gs.CommandResult()!=Result.Success)return gs.CommandResult();// get the selected facevar face = gs.Object(0).Face();if(face ==null)returnResult.Failure;// pick a point on the surface. Constain// picking to the face.var gp =newGetPoint();
gp.SetCommandPrompt("select point on surface");
gp.Constrain(face,false);
gp.Get();if(gp.CommandResult()!=Result.Success)return gp.CommandResult();// get the parameters of the point on the// surface that is clesest to gp.Point()double u, v;if(face.ClosestPoint(gp.Point(),out u,out v)){var direction = face.NormalAt(u, v);if(face.OrientationIsReversed)
direction.Reverse();RhinoApp.WriteLine(string.Format("Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})",
u, v, direction.X, direction.Y, direction.Z));}returnResult.Success;}}}
import rhinoscriptsyntax as rs
from scriptcontext import*importRhinofromRhino.CommandsimportResultdefRunCommand():# select a surface
gs =Rhino.Input.Custom.GetObject()
gs.SetCommandPrompt("select surface")
gs.GeometryFilter=Rhino.DocObjects.ObjectType.Surface
gs.DisablePreSelect()
gs.SubObjectSelect=False
gs.Get()if gs.CommandResult()!=Result.Success:return gs.CommandResult()# get the selected face
face = gs.Object(0).Face()if face ==None:return# pick a point on the surface. Constain# picking to the face.
gp =Rhino.Input.Custom.GetPoint()
gp.SetCommandPrompt("select point on surface")
gp.Constrain(face,False)
gp.Get()if gp.CommandResult()!=Result.Success:return gp.CommandResult()# get the parameters of the point on the# surface that is clesest to gp.Point()
b, u, v = face.ClosestPoint(gp.Point())if b:
dir = face.NormalAt(u, v)if face.OrientationIsReversed:
dir.Reverse()
print "Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})".format(
u, v, dir.X, dir.Y, dir.Z)if __name__ =="__main__":RunCommand()
ImportsRhinoImportsRhino.Input.CustomImportsRhino.DocObjectsImportsRhino.CommandsNamespace examples_vb
PublicClassNormalDirectionOfBrepFaceCommandInheritsCommandPublicOverridesReadOnlyPropertyEnglishName()AsStringGetReturn"vbDetermineNormDirectionOfBrepFace"EndGetEndPropertyProtectedOverridesFunctionRunCommand(doc AsRhinoDoc, mode AsRunMode)AsResult' select a surfaceDim gs =NewGetObject()
gs.SetCommandPrompt("select surface")
gs.GeometryFilter=ObjectType.Surface
gs.DisablePreSelect()
gs.SubObjectSelect=False
gs.[Get]()If gs.CommandResult()<>Result.SuccessThenReturn gs.CommandResult()EndIf' get the selected faceDim face = gs.[Object](0).Face()If face IsNothingThenReturnResult.FailureEndIf' pick a point on the surface. Constain' picking to the face.Dim gp =NewGetPoint()
gp.SetCommandPrompt("select point on surface")
gp.Constrain(face,False)
gp.[Get]()If gp.CommandResult()<>Result.SuccessThenReturn gp.CommandResult()EndIf' get the parameters of the point on the' surface that is clesest to gp.Point()Dim u AsDouble, v AsDoubleIf face.ClosestPoint(gp.Point(), u, v)ThenDim direction = face.NormalAt(u, v)If face.OrientationIsReversedThen
direction.Reverse()EndIfRhinoApp.WriteLine(String.Format("Surface normal at uv({0:f},{1:f}) = ({2:f},{3:f},{4:f})", u, v, direction.X, direction.Y, direction.Z))EndIfReturnResult.SuccessEndFunctionEndClassEndNamespace