TransWikia.com

How to define space inside a closed curve as a Region

Mathematica Asked by Pirx on June 3, 2021

Let’s say I have some closed curve, which could be given by a parametric representation, or by a closed spline as in:

pts = {{-1, 0}, {-1, 1}, {0, 0}, {1, 1}, {1, 0}};

which looks like so:

Graphics[{Thick, BSplineCurve[pts, SplineClosed -> True]}]

enter image description here

My question is, is there an efficient way to convert the space inside the boundary to a Region (which could then be postprocessed by any of Mathematica’s functions that act on such objects)? I don’t see any built-in functionality that would achieve this. Do I have to define a Boolean function that tests whether a point lies within the area enclosed by the curve, and plug that into ImplicitRegion? If so, what would be a good approach to do this?

Of course, extending this idea to the 3D case (a parametric closed surface defining a 3D region) would be of interest as well.

3 Answers

In principle this should work:

pts = {{-1, 0}, {-1, 1}, {0, 0}, {1, 1}, {1, 0}};

g = Graphics[{FilledCurve@BSplineCurve[pts, SplineClosed -> True]}]

enter image description here

DiscretizeGraphics[g]

enter image description here

But as you can see, the result is wrong.

This may be the same bug as described here:

You may want to report it to Wolfram again in the hope that more reports equal a higher likelihood of fixing it ...

Answered by Szabolcs on June 3, 2021

It seems that the DiscretizeGraphics code doesn't know how to handle the SplineClosed->True option of the BSplineCurve object. As a workaround, you can use my FullBSplineCurve function to convert the SplineClosed->True option into an equivalent SplineKnots specification, and then perform the discretization:

DiscretizeGraphics @ FilledCurve @ FullBSplineCurve @ BSplineCurve[
    {{-1, 0}, {-1, 1}, {0, 0}, {1, 1}, {1, 0}},
    SplineClosed->True
]

enter image description here

Answered by Carl Woll on June 3, 2021

The problem mentionned by @Szabolcs in his answer is solved on Mathematica version 12.2 (the problem is present on Mathematica 12.1)

$Version

pts = {{-1, 0}, {-1, 1}, {0, 0}, {1, 1}, {1, 0}};
g = Graphics[{FilledCurve@BSplineCurve[pts, SplineClosed -> True]}]
DiscretizeGraphics[g]  

enter image description here

Answered by andre314 on June 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP