mesh.NormalAt() sometimes not returning a unit vector

Not sure if this is a bug, but the mesh.NormalAt method sometimes doesn’t return unit vectors. Is this on purpose and should I trust the non unit vector directions as correct normals? This issue is easy to reproduce.

Hi @visose,

Can you show us how to reproduce?

– Dale

For example:
image

All inputs with default values. Code in the C# component is:

  private void RunScript(Mesh M, Point3d P, ref object A)
  {
    var mp = M.ClosestMeshPoint(P, double.MaxValue);
    A = M.NormalAt(mp);
  }

Yes I can see that. I’ve logged the issue.

https://mcneel.myjetbrains.com/youtrack/issue/RH-48292

In the mean time, you can just unitize the vector yourself.

var dir = M.NormalAt(mp);
dir.Unitize();
A = dir;

– Dale

Thanks, mesh.PointAt() seems to also return wrong values. I guess its an issue with ClosestMeshPoint().

Using mesh.ClosestPoint(point, out closestPoint, out normal, distance) returns the correct closest point and unit normal.

1 Like

This has been logged as a Rhinocommon issue, but it might not be. Both NormalAt and ClosestMeshPoint methods just wrap native methods.

Hi @visose,

Trust me, it’s a RhinoCommon issue…

– Dale

1 Like

Mmmmmmkaaaay, that explains a lot.

Now I can let my bald spots grow out again…

// Rolf