Search code examples
numpyscipyinterpolationscientific-computing

What's the meaning of the partial derivatives of B-spline as given by scipy.interpolate.bisplev?


I have a mesh generated from cloudpoint, which could be described as z = f(x,y), so I'm using scipy.interpolate.bisplrep and bisplev, with good results.

bisplev can be used with parameters dx=n and/or dy=n so that the results are derivatives of order n at the evaluated points. I plan to use this to calculate mean and gaussian curvatures (called surfature in Matlab), and that should involve getting the second-order partial derivatives of the survace

The results using one of the partial derivatives at a time, say dx are great, clearly representing the gradient as a "shading" effect, as seen in this image from a human back (code first):

    self.spline = inter.bisplrep(self.pointlist[:,1],
                                 self.pointlist[:,0],
                                 self.pointlist[:,2], s=smoothing_factor)
    self.mesh_shadow = inter.bisplev(yy.flat, xx.flat, self.spline, dy=1)

enter image description here

So far, so good. The problem is: I can't understand (and can't find any explanation) what's the meaning of the result when I ask for both partial derivatives at the same time, since there isn't any obvious numeric or visual meaning. For example, if I use dx AND dy:

self.mesh_shadow = inter.bisplev(yy.flat, xx.flat, self.spline, dx=1, dy=1)

I get this: enter image description here

So, I wonder:

  1. What's the mathematical/geometrical meaning of the simultaneous result of first-order partial derivatives of a surface as given by bislplev(..., dx=1, dy=1), if any?
  2. Would there be a way to get the maximum slope (in any direction) from bislplev(..., dx=1, dy=1)?
  3. Are both partial derivatives supposed to be called together, in the first place? I see I can use, say, (..., dx=1, dy=2) and the function seems to produce "valid" results, but would that make any sense?

Every time, the returned value is a (Y,X)-shaped array of single float values (Z or one of its derivative-related values).

Any help?

Thanks for reading


Solution

    1. The partial derivative you get with dx=n, dy=m is the mathematical object (or rather, its numerical approximation)

      (d/dx)^n (d/dy)^m f(x,y)

    2. You cannot compute the Gaussian curvature just from dx=2,dy=0 and dx=0,dy=2 --- you in general also need also the cross-derivative dx=1,dy=1.

    3. Partial derivatives (d/dx)^n (d/dy)^m f(x,y) are mathematically well-defined. With splines, if you go to too high orders, you should start getting zeros or discontinuities.