Function circumcenter finds the radius R and the center of the circumscribed circle of a triangle in 3D space.
Function curvature calls circumcenter for every triplet P_i-1, P_i, P_i+1 of neighboring points along the curve. The curvature is defined as κ_i = 1/R_i. The curvature vector is k_i=ε_i/R, where ε_i is the unit vector in the direction from P_i to the center of the circle.
Note that this local calculation is sensitive to noise in the data.
The syntax is:
[L,R,K] = curvature(X)
X: array of column vectors for the curve coordinates. X may have two or three columns.
L: Arc length
R: Curvature radius
K: Curvature vector
Are Mjaavatten (2020). Curvature of a 2D or 3D curve (https://www.mathworks.com/matlabcentral/fileexchange/69452-curvature-of-a-2d-or-3d-curve), MATLAB Central File Exchange. Retrieved .
Matthew Wong: Three points are required to calculate the curvature and direction. Thus the arrays R and Kappa are not defined at the end points. I have chosen to use the value NaN at those points. I could have made the arrays smaller or used zeros, but NaN makes it easier to make nice plots.
I used parts of this function to solve the problem that initially inspired this function's creation. What does it mean if an 'e' value returns NaN? I believe that the sign of 'e' determines curve direction (either 1 or -1) but I'm not sure what the NaN means.
Fixed typos in accompanying note.
Yet another mixup: Correct heading this time
Uploaded wrong file in v. 1.2.1
Corrected minor bug in circumcenter function. It now runs faster for a single output (R) than for more. Results remain unchanged.
The code is simplified and about 30% faster. The derivation of the mathematical model is included as a separate document. The output is identical to version 1.1.
Forgot to update image
The direction of the curvature vector in version 1.0 was very wrong. Corrected in version 1.1