Surface Curvature Matlab equivalent in Python

后端 未结 6 1402
野的像风
野的像风 2021-01-05 18:21

I was trying to calculate the curvature of a surface given by array of points (x,y,z). Initially I was trying to fit a polynomial equation z=a + bx + cx^2 + dy + exy + fy^2)

6条回答
  •  生来不讨喜
    2021-01-05 19:03

    I hope I'm not too late here. I work with exactly the same problem (a product for the company I work to).

    The first thing you must consider is that the points must represent a rectangular mesh. X is a 2D array, Y is a 2D array, and Z is a 2D array. If you have an unstructured cloudpoint, with a single matrix shaped Nx3 (the first column being X, the second being Y and the third being Z) then you can't apply this matlab function.

    I have developed a Python equivalent of this Matlab script, where I only calculate Mean curvature (I guess you can get inspired by the script and adapt it to get all your desired curvatures) for the Z matrix, ignoring the X and Y by assuming the grid is square. I think you can "grasp" what and how I am doing, and adapt it for your needs:

    note: This assumes that your data points are 1 unit apart.

    def mean_curvature(Z):
        Zy, Zx  = numpy.gradient(Z)
        Zxy, Zxx = numpy.gradient(Zx)
        Zyy, _ = numpy.gradient(Zy)
    
        H = (Zx**2 + 1)*Zyy - 2*Zx*Zy*Zxy + (Zy**2 + 1)*Zxx
        H = -H/(2*(Zx**2 + Zy**2 + 1)**(1.5))
    
        return H
    

提交回复
热议问题