I needed the exact thing back when H13 was released. Thanks to SESI for adding numpy, I wrote a Best Fit Line SOP pretty quickly. It works great, but be wary of using it on millions of points as numpy's svd consumes a lot of memory for some reason. I don't think it's a bug though.
I should upload it on Orbolt so it's a one click solution. Here is the code:
import numpy as np
node = hou.pwd()
geo = node.geometry()
p =
for pt in geo.points ( ):
p.append ( pt.position ( ) )
c = np.mean ( p, axis = 0, dtype = np.float64 )
u, s, v = np.linalg.svd ( p - c, full_matrices = False )
geo.addAttrib ( hou.attribType.Global, “bNormal”, v )
geo.addAttrib ( hou.attribType.Global, “bCenter”, c )
Paste it inside a Python SOP, and then reference the normal and center attributes anywhere you want.
I also have one to calculate the Best Fit Plane on Orbolt if you ever need that:
https://www.orbolt.com/asset/animatrix::bestFitPlane::1.00 [
orbolt.com]
This one is written in VEX and can run through millions of points without any issues or performance penalties and hardly uses any memory. It uses a different technique though, which is why the difference.
Just recently I used it to have a boat react to the waves of a sea. Using Align SOP is very jittery, especially if the sea is not calm. Getting the Best Fit Plane of the sea bbox'ed by the boat and reorienting the boat worked really well. Just an unusual usage I thought I would mention in the hopes that SESI might add similar functionality to H14. They are very welcome to add mines too if they are feeling tired