File Exchange

Patch Curvature

version 1.2.0.0 (314 KB) by Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

Principal, Gaussian and Mean Curvature of triangulated mesh

Updated 15 Jan 2014

This function calculates the principal curvature directions and values
of a triangulated mesh.

The function first rotates the data so the normal of the current
vertex becomes [-1 0 0], so we can describe the data by XY instead of
XYZ.
Secondly it fits a least-squares quadratic patch to the local
neighborhood of a vertex "f(x,y) = ax^2 + by^2 + cxy + dx + ey + f".
Then the eigenvectors and eigenvalues of the hessian are used to
calculate the principal, mean and gaussian curvature.

[Cmean,Cgaussian,Dir1,Dir2,Lambda1,Lambda2]=patchcurvature(FV,usethird)

inputs,
FV : A triangulated mesh (see Patch)
usethird : Use third order neighbour vertices for the curvature
fit, making it smoother but less local. true/ false (default)

outputs,
Cmean : Mean Curvature
Cgaussian : Gaussian Curvature
Dir1 : XYZ Direction of first Principal component
Dir2 : XYZ Direction of second Principal component
Lambda1 : value of first Principal component
Lambda2 : value of second Principal component

Cite As

Dirk-Jan Kroon (2020). Patch Curvature (https://www.mathworks.com/matlabcentral/fileexchange/32573-patch-curvature), MATLAB Central File Exchange. Retrieved .

Pieter Livens

Pieter Livens (view profile)

For those using this code and noticing small errors in the principle values, the 'eig2' function compares the principle values based on the absolute value, which is incorrect.
If you simply remove both 'abs' functions in the if loop on line 156, the direction of the principle curvatures will be correct. Everything else works perfectly, many thanks for sharing this code.

Dongjin Han

Dongjin Han (view profile)

Great work! Thank you

Martin Kefer

Martin Kefer (view profile)

Seems to only work on closed patches, if there are open spots, missing faces, Cmean is complex

Nairouz Mohamed

AB

AB (view profile)

When I try to run the file on my data, I get the error:
Warning: Matrix is singular, close to singular or badly scaled. Results may be inaccurate. RCOND = NaN.
> In VectorRotationMatrix (line 7)

Gianni Schena

Gianni Schena (view profile)

By shifting around a sphere we obtain different curvatures. thus the curvature seems to depend on the position of the centre (?)
...
[xx,yy,zz] = meshgrid(1:side,1:side,1:side);
c=[h_side h_side h_side]; % centre
rr = sqrt( (xx-c(1)).^2 + (yy-c(2)).^2 + (zz-c(3)).^2 );
[...]=patchcurvature(FV,usethird);

XiaoGang

Stefano Cauzzi

Stefano Cauzzi (view profile)

Great tool, however I keep on getting the following warning:
Warning: Rank deficient
Did anyone experience the same problem? Did you find a solution?

Helia

Helia (view profile)

why shifting the cylinder changes the curvature values? Is there an error in calculation?
I used the cylinder provided with this code but shifted the vertices keeping the same scaling. I obtained a different curvature values. Sounds strange to me.

Marta

Great!

Leo

Leo (view profile)

Dear author, Thank you for this work.

k = rand(1,3)
in the VectorRotationMatrix.
It will be very kind of you, if you can give me some hint.
Thanks again.

Binhang

Binhang (view profile)

This version seems much better!

Dirk-Jan Kroon

Dirk-Jan Kroon (view profile)

* Binhang
Thank you, there was a bug which I solved by removing abs from the eigenvalues. This version will probably be online in one or two days.

Binhang

Binhang (view profile)

Dear author, I have a question for the result.

Have you ever test your code for the torus? Did you notice that all the values for gauss and mean curvature are positive?

Well, I think this is incorrect.

baziham

baziham (view profile)

SABYASACHI DASGUPTA

SABYASACHI DASGUPTA (view profile)

Dear Mr.Kroon ,
Is it possible that you include how to calculate squared mean curvature over the mesh .
Regards,
Sabya

Jonathan Sullivan

Jonathan Sullivan (view profile)

Great submission. Very help. Nice examples provided too!