# How to fit a curved surface to 3d data

10 views (last 30 days)

Show older comments

Hi,

I have a set of points in 3d that I want to fit a surface to. I would like to show you the image first off.

My procedure is to first find if the points fit into a plane. If they don't, I would like to fit some kind of curved surface.

I have 3 questions mainly:

1. How to check for a good plane fit?

I have done SVD on the data using standard procedure and I have the plane equation and the normals. General consensus on several forums seems to be that we can evaluate a good plane fit using diag(S) where S is one of the outputs of SVD. If the 1st and 2nd values of diag(S) and significantly larger than the 3rd, the plane is a good one. I want to know if there is any metric for defining this significantly larger concept. For the figure below, my diag(S) values are as follows:

69.5547201214327

28.9724880972647

12.7254335381371

I know that for the points shown, a plane is not the best way to go but I want to know what ratio is termed significant because I want Matlab to automatically discard such bad fits.

2.I also tried using the fit function for plane using 'poly11' and it worked well but I was not able to figure out how to obtain the residual information and number of outliers.

3. I want to know how to fit a curved surface. I tried using the function fit with a 'poly23', 'poly12' kind of fits but they dont work. Is there another/better way and assuming all my data is curved similar to the figure below, what kind of equation/ model best fit this?

##### 0 Comments

### Answers (2)

Ahmet Cecen
on 18 Nov 2014

Edited: Ahmet Cecen
on 18 Nov 2014

First off, many of your questions above about when to decide what curve to use, where to stop, where to mark data as outliers are all dependent on WHERE this data is coming from. For instance, a generalized rule such as the diag(S) might happen to apply to your case, but it sure isn't correct for many cases I have seen.If you give detailed information on the origins of the data, I might be able to offer more specific suggestions.

Being completely blind as to why you are doing this, I would suggest you start with fitting all available polynomial surfaces. and compare performance of each fit. Use an overfit measure like Cross Validation to decide when to stop increasing the degree of polynomial.

For example, lets say in your application area, 5% average error for the fit (notice this is not R^2) is acceptable. Since you are familiar with SVD might as well stick to principal components since that is generally better conditioned for regression. Try polynomial fits up to power 5th on the first and second principal components alone. If you get to 5% error or below like that, there you go you don't need the 3rd dimension. If you can't, try the same thing up to 5th power with all 3 components.

The above is just one particular scheme I made up to give you an idea, you can change a lot of decisions I made to fit your own problem.

I show something similar to this in the example for my regression code MultiPolyRegress, even if want to stick to the built in functions, the example might help.

##### 2 Comments

Ahmet Cecen
on 18 Nov 2014

Hmm, so the geo-location of your points is important. If you don't mind me asking, why is it important for you to fit a surface to each segment? As in, why are you fitting a curve to begin with? Are you just interested in the visual surface, or does the formula for the fit matter? Will you be receiving any new point in any segment that you would need to evaluate and get a reasonable answer to later?

Correct me if I am wrong but the way you pose the problem sounds like you are interested in visualization, not in estimation. Wouldn't it be better to chose what kind of surface you would like to see, or what would be realistic (is a 5th order polynomial surface realistic in an actual building?), then fit that even if there is some error?

Sanjay Manohar
on 29 Mar 2021

##### 0 Comments

### See Also

### Categories

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!