Finding a 'best fit' plane through a set of 3D points

   3091   12   4
User Avatar
Member
271 posts
Joined: Aug. 2018
Online
Does anyone have a solution to finding a 'best fit' plane through a set of 3D points?
I do realise that 'best fit' is a rather ill defined requirement, but it's not critical for the project I'm thinking of.
User Avatar
Member
708 posts
Joined: Feb. 2017
Offline
Hey Mike_A,

might not work in any case, but could give you a starting point.
Edited by CYTE - Nov. 18, 2022 09:38:39

Attachments:
Bounding Rectangle.hip (109.7 KB)

User Avatar
Member
8785 posts
Joined: July 2007
Offline
https://www.orbolt.com/asset/animatrix::bestFitPlane::1.00
Tomas Slancik
FX Supervisor
Method Studios, NY
User Avatar
Member
4693 posts
Joined: Feb. 2012
Offline
Here is one way using PCA (Principal Component Analysis):



Attrib Promote (P) = Point -> Detail | Average

Compute sum (Point Wrangle):
vector centroid = detail ( 0, "centroid" );
vector p = v@P - centroid;
setdetailattrib ( geoself ( ), "sumxx", p.x * p.x, "add" );
setdetailattrib ( geoself ( ), "sumxy", p.x * p.y, "add" );
setdetailattrib ( geoself ( ), "sumxz", p.x * p.z, "add" );
setdetailattrib ( geoself ( ), "sumyy", p.y * p.y, "add" );
setdetailattrib ( geoself ( ), "sumyz", p.y * p.z, "add" );
setdetailattrib ( geoself ( ), "sumzz", p.z * p.z, "add" );

Compute PCA (Detail Wrangle):
matrix3 m = set ( @opinput1_sumxx, @opinput1_sumxy, @opinput1_sumxz, @opinput1_sumxy, @opinput1_sumyy, @opinput1_sumyz, @opinput1_sumxz, @opinput1_sumyz, @opinput1_sumzz );

matrix3 u = 0;
vector s = 0;
matrix3 v = 0;

svddecomp ( m, u, s, v );
v = transpose ( v );

vector x = set ( v.xx, v.xy, v.xz );
vector y = set ( v.yx, v.yy, v.yz );
vector z = set ( v.zx, v.zy, v.zz );

vector centroid = v@opinput1_centroid;
int pt = addpoint ( geoself ( ), centroid );

setpointattrib ( geoself ( ), "x", pt, x );
setpointattrib ( geoself ( ), "y", pt, y );
setpointattrib ( geoself ( ), "z", pt, z );

setpointattrib ( geoself ( ), "N", pt, z );
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
271 posts
Joined: Aug. 2018
Online
Thank you all - much appreciated!
User Avatar
Member
271 posts
Joined: Aug. 2018
Online
https://www.orbolt.com/asset/animatrix::bestFitPlane::1.00

That would be really good to have as a HDA - but unfortunately it doesn't seem to work in 19.5 - unless I'm missing something.
If there is a possibility of an updated version I would be very appreciative, but do understand that delivering such is work...
User Avatar
Member
4693 posts
Joined: Feb. 2012
Offline
Mike_A
https://www.orbolt.com/asset/animatrix::bestFitPlane::1.00

That would be really good to have as a HDA - but unfortunately it doesn't seem to work in 19.5 - unless I'm missing something.
If there is a possibility of an updated version I would be very appreciative, but do understand that delivering such is work...

This is a very old OTL. Many things changed in VEX since then.

The above method I posted is superior. So you can turn that into an HDA if you wanted.
Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
271 posts
Joined: Aug. 2018
Online
Thanks Animatrix - that's fine and understood. The PCA code you kindly offered above is a great solution and much appreciated I'll make a HDA from that as you suggest.
Edited by Mike_A - Nov. 19, 2022 12:00:42
User Avatar
Member
708 posts
Joined: Feb. 2017
Offline
Hey animatrix,

I'm trying your example with H 19.5.640 But it is not working. Has anything changed since you posted the PCA solution?
An update would be highly appreciated!

Cheers
CYTE
User Avatar
Member
4693 posts
Joined: Feb. 2012
Offline
Yes it still works. Are you sure you set grid geometry to XY Plane orientation before copying?

Senior FX TD @ Industrial Light & Magic
Get to the NEXT level in Houdini & VEX with Pragmatic VEX! [www.pragmatic-vfx.com]

youtube.com/@pragmaticvfx | patreon.com/animatrix | pragmaticvfx.gumroad.com
User Avatar
Member
682 posts
Joined: Sept. 2013
Offline
I've just published an example file with animatrix' code here:
https://procegen.konstantinmagnus.de/fitting-planes-to-point-clouds [procegen.konstantinmagnus.de]
https://procegen.konstantinmagnus.de/ [procegen.konstantinmagnus.de]
User Avatar
Member
275 posts
Joined: Sept. 2012
Offline
I have probably missed something with svddecomp , everytime i struggle with one direction which looks off to me..
So if i take your version, i get the reduction red plane, doesn't look that correct not?

I could improve the result with some "prefiltering", which give me the blue plane , way better already...
Have you also noticed or is it me only?

Attachments:
PCA.JPG (72.2 KB)

Vincent Thomas   (VFX and Art since 1998)
Senior Env and Lighting  artist & Houdini generalist & Creative Concepts
http://fr.linkedin.com/in/vincentthomas [fr.linkedin.com]
User Avatar
Member
708 posts
Joined: Feb. 2017
Offline
ah thank you Konstantin and animatrix, I missed the part that the detail attribute needs to be named centroid!
edit: ah bummer I thought it would respect the nonuniform scale of the target, too....

Cheers
CYTE
Edited by CYTE - Oct. 27, 2023 07:26:31
  • Quick Links