Is there a way to evaluate the length/area of a connected cubic spline?
조회 수: 6 (최근 30일)
이전 댓글 표시
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/211337/image.png)
댓글 수: 0
채택된 답변
John D'Errico
2019년 4월 1일
편집: John D'Errico
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.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Spline Construction에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!