Is there a Python module for handling parametric (u-v) surfaces? I’m looking for something that’s the 3D analogue to scipy.interpolate’s spline functions, where I can create parametric splines through a set of 2D points thusly:
xypts = [[0., 1., 5., 2.], [4., 3., 6., 7.]]
tck, u = scipy.interpolate.splprep(xypts, s=0, k=3)
and then get a point at any t-value on the spline like this:
t = 0.5
intxypt = scipy.interpolate.splev(t, tck)
So, what I’d like is something that works like this:
# xyzpts is a 3 x m x n matrix, with m and n >= 4 for a cubic surface
tck, s, t = srfprep(xyzpts, s=0, k=3)
u, v = 0.5, 0.5
intxyzpt = srfev(u, v, tck)
I wrote my own code to do just this some time ago, but frankly it kinda sucks (slow and fragile, especially at the surface edges) and I’m looking for something more standard and optimized.
This is probably obvious, but if you are able to guess the u-v coordinates corresponding to each data point (simplest case
u=x,v=yif the surface is a graph), parametric interpolation(u,v) -> (x,y,z)is essentially 2-D interpolation of 3 separate datasets (the x, y, and z coordinates), so you can use any usual 2-D interpolation method.splprepin fact works this way, by assuming the points are ordered and assigning theucoordinates according tou[i] = u[i-1] + dist(p[i], p[j])using the euclidean distance. This generalizes to 2-D if you know which points are “next to each other”. For example, if thex,y,zdata come as 2-D arrays, you can doEDIT: Ok, I’m not fully sure how robust the above computed
u,vin practice are, as it seems there’s room for distortion. However, the LocallyLinearEmbedding below may work better in this respect.If you are not able to guess the
u,vvalues, for instance you have just a bunch of points and no neighborhood information, the problem becomes more difficult. The appropriate keywords here seem to be “surface reconstruction” and “manifold learning”.I didn’t try, but it seems to me that you easily can get suitable
u,vcoordinates usingLocallyLinearEmbeddingfrom scikits-learn, see this example. They have a bunch of different algorithms, and this seems solid enough. The resultingu = Y[:,0]; v = Y[:,1]you can then use in unstructured 2-D interpolation methods, as shown above.Maybe googling more will reveal more packages.