I have a bunch of point in 3d (x
, y
and z
) and want to find the best plane fitting these points. I used the rbf method of scipy but it is giving me points and I want the equation of the plane. I have also read this solution and this one but still I cannot find the equation of the plane. The important note is that my poitns are usually making curves shapes surfaces and a linear least square plane is not what I want. I do appreciate any help in advance.
Asked
Active
Viewed 1,083 times
1

Ali_d
- 1,089
- 9
- 24
-
1Do you mean a plane? It sound like you want to fit a surface to a set of points, otherwise just use the equation for a plane [here](https://en.wikipedia.org/wiki/Plane_(geometry)) in scipy [curvefit](https://docs.scipy.org/doc/scipy/reference/generated/scipy.optimize.curve_fit.html). For a general surface, I think you need to flip your problem - decide on a sufficiently general function and try to fit it, either some piecewise set of functions (bilinear or trianglar patches, RBF) or maybe consider an arbitary sum of sines and cosines if your surface is periodic. – Ed Smith May 10 '21 at 10:07
-
Dear @Ed Smith, Thanks for your informative comment. I am exactly looking for a method like bspline for my points. How can I find it? thanks in advance for your help. – Ali_d May 10 '21 at 10:31
-
1Maybe either scipy [interp2d](https://docs.scipy.org/doc/scipy/reference/generated/scipy.interpolate.interp2d.html#scipy.interpolate.interp2d) or this [answer](https://stackoverflow.com/questions/34053174/python-scipy-for-2d-extrapolated-spline-function) then extract coefficients? Generally you can fit any functional form using a least squares approach (collect all coefficients for your function into a matrix A and solve the Moore-Penrose Inverse using numpy linear algebra). Not sure how well this will work with piecewise functions, Scipy uses FITPACK which is based on splines it seemes – Ed Smith May 10 '21 at 14:40
-
@Ed Smith, thanks for the info. I checked scipy interp2d and this is giving me interpolated points rather than the surface. My points are coming from a geological model and are representative of surfaces. So, predicting the function of the best surface is tricky. That's why I am stuck. – Ali_d May 10 '21 at 15:03
-
Bivariatespline has a get_coeff function where your points can be fitted in various ways and you can at least get the form of the surface, integrate, get roots, etc. Why do you need the surface fn? Plotting or something else? Otherwise a general surface fit which has a closed functional form is not a trivial problem. I spent a long time trying to do something similar and ended fitting a sum of sine fns [here](http://arxiv.org/pdf/2007.10779) which i then converted to a set of piecewise bilinear patches for efficiency reasons (fast ray tracing). – Ed Smith May 10 '21 at 16:40
-
Dear @Ed Smith, sorry for my late response. I need surfaces to create mesh between my surfaces and then do FE modeling in meshes. Surfaces are wrapping volumes and the shape of volumes can not be predicted easily. – Ali_d May 10 '21 at 18:52
-
1[This method](https://stackoverflow.com/a/64835893/2148416) gives you the parameters (a,b,c,d) of the plane equation ax+by+cz+d=0. – aerobiomat May 12 '21 at 15:23
-
1Hi @Ali_d, just seen this again, did you ever solve it? If you want the surface for FEA and have a bunch or points, why not just triangulate based on the points using Delaunay https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.Delaunay.html and solving on the resulting triangular grid? – Ed Smith Aug 13 '21 at 08:57