How to fit a curved surface to 3d data
조회 수: 17(최근 30일)
표시 이전 댓글
Banu Muthukumar 2014년 11월 18일
답변: Sanjay Manohar 2021년 3월 29일
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:
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?
편집: Ahmet Cecen 2014년 11월 18일
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
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 2021년 3월 29일
For estimating a single Z-surface on an XY plane, I have had great success with the gridfit toolbox, downloadable from here. It may suit your purpose if you can get the data in a Z(X,Y) format.
Find more on Linear and Nonlinear Regression in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!