## Is there a way to evaluate the length/area of a connected cubic spline?

Anuruddha Jayasuriya

### Anuruddha Jayasuriya (view profile)

さんによって質問されました 2019 年 4 月 1 日

### Anuruddha Jayasuriya (view profile)

さんによって コメントされました 2019 年 4 月 1 日
John D'Errico

### John D'Errico (view profile)

さんの 回答が採用されました
Hi,
I am working on 2D convex hull shapes. For a bunch of given x-,y- coordinates, I have been generating convex hulls with different shapes.
Now, I need to draw a spline using the those coordinates of the convex hull which interpolates the coordinates in between the given vertices of the shape. For this purpose, I am using the "cscvn" syntax to draw the spline. What I want is to evaluate the length of this spline and the area inside the spline. Following image is an example of a convex hull using 6-vertices and a representative smooth spline interpolated between those 6 coordinates given.
I would be thankful if someone can enlight few thoughts on this, and is highly appreciated.
Thank you. #### 0 件のコメント

サインイン to comment.

## 1 件の回答 2019 年 4 月 1 日

### John D'Errico (view profile)

2019 年 4 月 1 日
採用された回答

Seems pretty easy to me. Well, easy enough. Ok, well doable.
Compute the area inside an ellipse, centered at [2,3], all done by integrating a cscvn curve. Yes, I hope it will be pi, or close to that.
t = linspace(0,2*pi,10);
rx = 1/2;
ry = 2;
x = 2 + rx*cos(t);
y = 3 + ry*sin(t);
The area of that ellipse is simple enough, because I carefully chose rx and ry. It would pi*rx*ry = pi.
Now, we apply Green's theorem. We can find the necessary line integral, in parametric form from (4) on the page:
Lets apply it to this spline.
fn = cscvn([x;y]);
fnprime = fnder(fn);
Kofs = @(s) [1 -1]*(fnval(fn,s) .* flipud(fnval(fnprime,s)));
A = 1/2*integral(Kofs,fn.breaks(1),fn.breaks(end))
A =
3.1373
Got lucky. Of course, we know the area of that ellipse is indeed pi, so that was a reasonable result given a 10 point approximation around the curve. The result is a signed area, based on traversing the curve in the order of the points given. (Right hand rule should indicate the sign.)
The length of the curve itself is even easier.
Lfun = @(s) sqrt(sum(fnval(fnprime,s).^2,1));
L = integral(Lfun,fn.breaks(1),fn.breaks(end))
L =
8.5299
The true arc length for that curve will be somewhat difficult, at least to do analytically without an elliptic integral. vpaintegral will handle it, of course.
vpaintegral(sqrt(rx^2*cos(theta)^2 + ry^2*sin(theta)^2),theta,[0,2*pi])
ans =
8.57842
I should probably be able to check that from an elliptic integral. hmm, ellipke should do it, based on a quick search for a complete elliptic integral in MATLAB. Looks like the second kind should give what I need.
Based on the Kummer series approimation we find on that page, thus (65) & (66)
h = (ry - rx)/(ry + rx)
h =
0.6
pi*(rx + ry)*(1 + h^2/4 + h^4/64 + h^6/256)
ans =
8.5782
Looks good enough to me.

#### 1 件のコメント

Anuruddha Jayasuriya

### Anuruddha Jayasuriya (view profile)

2019 年 4 月 1 日
Hi John,
Your method gives very close interpretations to the area and the length of the closed convexed shape. Thank you so much for your though process here, and I understood it quite well.
Cheers!
Anuruddha

サインイン to comment.