2

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.

rhomboidRhipper
  • 856
  • 4
  • 7

1 Answers1

6
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}
 ]

enter image description here

Note

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

Cases[ParametricPlot[(* stuff *)], Line[l_] :> Polygon[l], ∞][[1]]
ubpdqn
  • 60,617
  • 3
  • 59
  • 148