 # Get the normal of a line

Hello

I need to get the normal projected onto a line each “X” line segments.

For example, in the picture I should get the normal projected on the corner lines. To divide the line into segments I use:

Line.ToNurbsCurve () DivideByLength (10, true).;

But for each segment, I don’t know how calculate the normal

I’m using c # and RhinoCommon

Find the closest point on the surface using `Rhino.Geometry.Surface.ClosestPoint`. Then use `Rhino.Geometry.Surface.NormalAt`.

If you are dealing with a planar curve, then you can also find the normals using
1- The curve plane normal (v1),
2- The tangents to your curve at each divide point (v2, v3, etc.),
Then calculate the normals using the vector cross-product operation (v2xv1, v3xv1, etc.)

And, How I can get the plane?

For example, in the image, I need calculate the normal of two lines in different planes. The following shows a sample GH script and C# sample. I hope this helps.

CrvNormals.gh (8.7 KB)

Hi again,

I reopen this post _ With your code, the line’s direction determines the normnal’s direction. For example. In the Image The normal of Line 1 is outside and the Line 2 is inside.

I’d like get some similar at command _Dir

Select a Brep Object, and in a determinated Brep point get the normal. Something like this image

With the command _Dir Try this

``````protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
ObjRef cRef;
Result res = RhinoGet.GetOneObject("Select BREP", false, ObjectType.Brep, out cRef);
if (res != Result.Success)
return res;

Brep b = cRef.Brep();

GetPoint gp = new GetPoint();
gp.SetCommandPrompt("Select point for normal");
while (true)
{
GetResult gr = gp.Get();
if (gr != GetResult.Point)
break;

Point3d pt = gp.Point();
Point3d closest;
ComponentIndex ci;
double s, t;
Vector3d normal;
if (b.ClosestPoint(pt, out closest, out ci, out s, out t, double.MaxValue, out normal))
{
doc.Views.Redraw();
RhinoApp.WriteLine("Normal is :"+normal);
}
}

return Result.Success;
}
``````
1 Like

It works perfectly!!

Thank you very much!