# [SciPy-user] How to fit a surface from a list of measured 3D points ?

josef.pktd@gmai... josef.pktd@gmai...
Wed Apr 1 12:51:30 CDT 2009

```On Wed, Apr 1, 2009 at 1:40 PM, LB <berthe.loic@gmail.com> wrote:
>> Hmm, good point. Can you rotate the data points in the 3D space so
>> that the new z values do become a proper function in two dimensions?
> It may be possible, with some manual transformation of the data
> points, but I would prefer a more generic approach if possible.
>
>> If not, then you'll have to:
>> a) fit a surface to all of the data in 3D (something done a lot by
>> computer graphics and robotics people, who get point clouds as return
>> data from LIDAR scanners and similar, and then try to fit the points
>> to 3D surfaces for visualization / navigation)
>>
>> b) Find locally-smooth patches and fit surfaces to these individually
>> (the manifold-learning folks do this, e.g. "Hessian LLE"). Say you're
>> interested in curvature around a given data point (x, y, z)... you
>> could take the points within some neighborhood and then either fit
>> them to a simple 3d surface (like some kind of paraboloid), or figure
>> out (with e.g. PCA) the best projection of those data points to a
>> plane, and then fit a surface to f(x, y) -> z for the transformed data.
>>
>> or perhaps even c) just calculate what you need from the data points
>> directly. If you just need very local curvature data, you could
>> probably calculate that from a point and its nearest neighbors. (This
>> is really just a degenerate case of b...)
>>
>> Lots of tools for these tasks are in scipy, but nothing off-the-shelf
>> that I know if.
>
> The method c) seems the simplest at first sight but I see two issues
> for this local approach :
>  - the measured data are noisy. Using the nearest neighbor could give
> a noisy result two, especially when looking at a radius of curvature
>  - I don't see how to use this approach to plot the variation of
> radius of curvature along the surface, It can give me an array of
> radius of curvature, but as my data are not regularly spaced, it won't
> be easy to handle.
>
> Th method b) seems very fuzzy to me : I don't have any knowledge in
> manifold-learning and I would have the second issue of the method c)
> too.
>
> The method a) is what I had initially in mind, but I didn't see how to
> do this in scipy :-(
> I believed at first that I could make a sort of parametric bispline
> fit with the functions available in scipy.interpolate, but I didn't
> succeed in.
> Do you have any example or hint for doing this kind of treatment in
> scipy ?
>
> LB

If you have noisy data, then a kernel ridge regression or fitting a
gaussian process might be more appropriate than just interpolation.

I posted a simple example code for it a while ago, and pymvpa has a
more complete implementation. Around 900 points should still be ok,
since it builds the square distance matrix (900,900)

I don't know anything about your curvature measure, but it should be
worth a try.

Josef
```