I need to compute a curvature of a simple 2D discrete function like this one:
can anybody help how to do that? thanks
No products are associated with this question.
You function seems to be a 1D function.
Are you looking for the 2nd derivative? While diff calculates the one-sided differential quotient, gradient uses the two-sided inside the interval:
If you mean the curvature as reciprocal radius of the local fitting circle:
dx = gradient(x); ddx = gradient(dx); dy = gradient(y); ddy = gradient(dy);
num = dx .* ddy - ddx .* dy; denom = dx .* dx + dy .* dy; denom = sqrt(denom); denom = denom * denom * denom; curvatur = num ./ denom; curvature(denom < 0) = NaN;
Please test this, because I'm not sure if I remember the formulas correctly.
Let (x1,y1), (x2,y2), and (x3,y3) be three successive points on your curve. The curvature of a circle drawn through them is simply four times the area of the triangle formed by the three points divided by the product of its three sides. Using the coordinates of the points this is given by:
K = 2*abs((x2-x1).*(y3-y1)-(x3-x1).*(y2-y1)) ./ ... sqrt(((x2-x1).^2+(y2-y1).^2)*((x3-x1).^2+(y3-y1).^2)*((x3-x2).^2+(y3-y2).^2));
You can consider this as an approximation to the curve's curvature at the middle point of the three points.