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
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:
Here is my code:
fp=fimplicit(f,[-8,8,-8,8],'meshdensity', 1000,'visible', 'off');
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?