File Exchange

## Mean Curvature (Fast code)

version 1.0.0.0 (1.01 KB) by Pratik Kamdar

### Pratik Kamdar (view profile)

Calculate the Mean curvature of a given surface (x,y,z) using vectorized form.

Updated 22 Mar 2006

This function is a modified form of original code (see below). I vectorized the code to make the code time efficient.

The function calculates the mean curvature of the input structured matrix data. The input are the coordinate matrices of x,y & z (as generated by meshgrid or similar functions).

The outputs are a matrix containing the mean curvature at each point and a scalar giving the surface average mean curvature (SAMC).

Mistake found by Anthony Beaucamp. Thanks for letting me know! File has been updated.

Abdelrahman Shaath

### Abdelrahman Shaath (view profile)

% First Derivatives
% Second Derivatives
% Initialize Gaussian and mean curvature
K = zeros(size(Z));
H = zeros(size(Z));
% Calculate both Gaussian and mean curvature
for i=1:size(Z,1)
for j=1:size(Z,2)
% assign vector values that we are going to work on
r_u = [Xu(i,j) Yu(i,j) Zu(i,j)];
r_v = [Xv(i,j) Yv(i,j) Zv(i,j)];
r_uu = [Xuu(i,j) Yuu(i,j) Zuu(i,j)];
r_uv = [Xuv(i,j) Yuv(i,j) Zuv(i,j)];
r_vv = [Xvv(i,j) Yvv(i,j) Zvv(i,j)];
% First fundamental Coeffecients of the surface (E,F,G)
E = dot(r_u, r_u);
F = dot(r_u, r_v);
G = dot(r_v, r_v);
% Calculate the unite normal vector (the perpendicular vector for
% both of these vectors)
m = cross(r_u,r_v,2);
n = m./sqrt(dot(m,m,2));
% Second fundamental Coeffecients of the surface (L,M,N)
L = dot(r_uu,n);
M = dot(r_uv,n);
N = dot(r_vv,n);
% Gaussian Curvature
K(i,j) = (L.*N - M.^2)./(E.*G - F.^2);
% Mean Curvature
H(i,j) = (E.*N + G.*L - 2.*F.*M)./(2*(E.*G - F.^2));
end
end

Jose Cappelletto

### Jose Cappelletto (view profile)

Hi Claude,
When I run by providing the point cloud data it throws error:

Too many output arguments.

Can you provide a way how should i run for 3D point cloud as an example.

mehdi ravanbakhsh

Hi pratik,
Can you please let me know how I can use your code to calculate the curvature of a 2-D curve?
Thanks,Mehdi

Pratik Kamdar

@Claude Gouedard:

I acknowledged the original author in my post. I dont think I am responsible for any missing citations on the part of the original author.
(This review might appear twice).

Claude Gouedard

I apologize !
I didn't send my code to you ...

However ...
this code, yours, sounds a lot like mine. Perhaps there is only one way to program fine ....

Claude Gouedard

It seems I recognize my own code (!) I sent you because I told you that yours was not in the Matlab spirit ...
I don't see any citation ...no thanks ...

Pratik Kamdar

File updated to remove error found by Anthony Beaucamp. Thanks for letting me know! Dont know how I missed that! Btw, the original file also has the same error.

Anthony Beaucamp

That's a big improvement from the original code, but you made a mistake: It's not (2.*(E.*G)-F.^2) but 2.*((E.*G)-F.^2). Anyway, I am working on an extended version that calculates everything: Principal Curvatures, Directions, Mean and Gaussian. I will post it as soon as it's ready.

John D'Errico

Cleaned up the help and description. I also compared this code to its predecessor - on a 100x100 grid, I saw a 40x speedup.
(This review may appear twice.)

Pratik Kamdar

Thnx for the comments John. I will update the file description. Presently, I am having trouble logging into my account.

John D'Errico

That this function does not work on a triangulation does not make it worth deletion. It merely makes it of less value to at least one user than it might be otherwise.

I do have two issues though. First is the claim in the description that it works on a "point cloud". The phrase point cloud suggests an unstructured set of points. This code requires a structured array of data, as meshgrid might have generated. My second comment is a related one - There is very little information supplied in the help to this function, only one vague line. I'd have preferred a much better description of what the inputs must be. Ordinarily I'd have given this file a rating of 2 due to these flaws, but since its already gotten a rating of 1, I chose to round up.

M. Tetouan

Computing the mean curvature of an implicit surface is very simple and straightforward. The challenging problem is how to efficiently compute the curvatures of a 3D triangle mesh. The most common representation of a 3D surface in computer graphics is the triangle mesh which consists of a set of vertices (geometry) and a set of faces (connectivety).

 22 Mar 2006 1.0.0.0 Mistake in formula. Found by Anthony Beaucamp. Thanks for letting me know! 23 Feb 2006 update description 23 Feb 2006 To provide better description of the function 23 Feb 2006 To provide better description of the function 23 Feb 2006 To provide better description of the function 23 Feb 2006 To provide better description of the function 23 Feb 2006 To provide better description of the function
##### MATLAB Release Compatibility
Created with R14SP2
Compatible with any release
##### Platform Compatibility
Windows macOS Linux