# How to find if x-y point falls within a closed BSplineCurve

Here's a simple Manipulate with a closed BSplineCurve, and a Locator.

Manipulate[Graphics[
{BSplineCurve[{{0.5, 0.05}, {1.05, 0.7}, {0.4, 1.5},
{-1.15,0.85}, {-0.75, 0.02}, {-0.93, -1}, {0.2, -1.3}, {1.05, -0.83}},
SplineClosed -> True]}],{pt, Locator}]


Is it possible to detect if the Locator is within the boundary of the curve? So that I can perform some action if it is?

I've found similar things here (52322) and here (17306), but these are all explicit x-y functions, so not so helpful.

Thanks.

• Why not use RegionMember[] on a ParametricRegion[], using BSplineFunction[] to represent your curve? – J. M. is away Jun 2 '15 at 23:27

## 1 Answer

Manipulate[
With[{f =
BSplineFunction[{{0.5, 0.05}, {1.05, 0.7}, {0.4, 1.5}, {-1.15,
0.85}, {-0.75, 0.02}, {-0.93, -1}, {0.2, -1.3}, {1.05, -0.83}},
SplineClosed -> True]},
reg = Polygon[Table[f[t], {t, 0, 1, 0.01}]];
rm = RegionMember[reg];
];
Column[{Graphics[{Point[p], EdgeForm[{Red, Thick}], Yellow, reg},
PlotRange -> Table[{-2, 2}, {2}]],
Row[{"Region Member: ", rm[p]}]}],
{{p, {0.5, 0.5}}, Locator}
] Note

As @Guesswhoitis. notes in comments region could also be obtained as:

Cases[ParametricPlot[(* stuff *)], Line[l_] :> Polygon[l], ∞][]

• This is mostly what I had in mind, except that I'd have used ParametricPlot[] to construct the shape. (Still, + 1!) – J. M. is away Jun 3 '15 at 2:17
• @J. M. when I originally looked I used ParametricPlot of BSplineFunction...but just thought Polygon would end being cleaner...thanks for upvote :) – ubpdqn Jun 3 '15 at 2:20
• Well, you could still use Cases[ParametricPlot[(* stuff *)], Line[l_] :> Polygon[l], ∞][], of course. :) – J. M. is away Jun 3 '15 at 2:40
• @J. M. yes...I will add to answer :) – ubpdqn Jun 3 '15 at 2:43
• Ah, RegionMember. Thanks. That makes it simple. – rhomboidRhipper Jun 3 '15 at 15:33