Normal vector on a closed polysurface

Using python, what is the best way of getting the normal vector of a closed polysurface on a specific point (on that polysurface)?

Rhinoscriptsyntax has SurfaceNormal but it doesn’t work on polysurfaces I don’t think, and I would like to avoid exploding it.

It sounds like you need to sub select the surface (ctrl + click). In your script sub select can be enabled like so:

sid = rs.GetObject(subobjects=True)

Thanks Alain, but that wouldn’t quite work for me. I actually have heaps of points on different parts of the polysurface and the script should move each point based on the normal vector at that location. So I can’t rely on user input for that.

Does this help?

from scriptcontext import doc

b = SomeBrep()
p = SomePoint()
for s in b.Surfaces:
    b, u,v = s.ClosestPoint(p)
    cp = s.PointAt(u,v)
    if p.DistanceTo(cp) <= doc.ModelAbsoluteTolerance: # p is on srf
        v = s.NormalAt(u,v)
        print(v)

If not, could you share your script?

1 Like

That actually solved my issue Alain, thank you!