Perimeter of a implicit curve
조회 수: 4 (최근 30일)
이전 댓글 표시
I tried to make a program that returns the perimeter of a plane curve defined implicitly. The difficulty is that this type of curves can have more connected regions.
As an example we can take
f=@(x,y) sin(x).*sin(y)-0.5;
fp=fimplicit(f,[-8,8,-8,8]);
I observed that the points used by the fimplicit command are in such an order that makes the connected regions separately, and I detect the indices where we pass from one connected region to another. My idea was that if the segment connected two consecutive points from Points is greater than a small enough number (but not too small) tol than this is the step where a connected region is finished and we go to the next one. I'm not sure that this is indeed the way fimplicit command works. I see this picture that I make using the plot command:
plot(real(Points),imag(Points)) %see below what is the vector Points
Here is my code:
tol=0.01;
fp=fimplicit(f,[-8,8,-8,8],'meshdensity', 1000,'visible', 'off');
Points=fp.XData+1i.*fp.YData; %these are the x and y coordinates of the points used by fimplicit to represent the curve f(x,y)=0.
delete(fp);
Points=Points(isfinite(Pointsnew)==1);
d=diff(Points);
P=sum(hypot(real(d),imag(d)).*(hypot(real(d),imag(d))<tol)); %this is the perimeter
It returns very good values (3 or 4 decimals are exact). But it depends on how I choose the tolerance tol. If I take it too low the perimeter will be less than it is indeed. Moreover if I hace a part of a connected region on a corner then I want to take into account the part of the perimeter of the rectangle that bounds that region. With my program that is impossible.
Is there a way to write that program without the use of tol and to take into account the corners if needed?
댓글 수: 2
Star Strider
2021년 4월 18일
First, ‘Pointsnew’ is nowhere to be found.
Second, the visible fimplicit plot has no connected lines.
Third, what perimeter do you want to calculate? Is it the perimeter of the entire region (in which case the boundary function would be appropriate to define it), or the perimeters of each or all of the closed contours (essentially trivial)?
답변 (1개)
Matt J
2021년 4월 18일
plotRange=[-1,+1, -1,+1]*8;
plotCorners=[-1 1;1 1;1 -1; -1 -1]*8;
f=@(x,y) (sin(x).*sin(y)-0.5);
fp=fimplicit(f,2*plotRange,'MeshDensity',3000);
XY=[fp.XData;fp.YData].'; close
shpRegions=polyshape(XY);
shpBounds=polyshape(plotCorners);
shpRegions=intersect(shpBounds,shpRegions);
Perimeter=perimeter(shpRegions)
plot(shpRegions,'FaceColor','r')
댓글 수: 7
Matt J
2021년 4월 18일
Well, you don't seem to have included samples of the boundary rectangle in the list of points in any way.
참고 항목
카테고리
Help Center 및 File Exchange에서 Preprocessing Data에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!