3

Updated:

I have a listplot of data and I would like to collect all the data points within a specific boundary of a circle graphic that overlaps the listplot in Mathematica.

Is something like this possible?

The ellipse I have made is of the form

{c, s, \[Theta]} = 1 /. ComponentMeasurements[f, {"Centroid", "SemiAxes", "Orientation"}] Show[Rasterize[p], Graphics[{Red, Rotate[Circle[c, s], \[Theta]]}]] 

Can you help me fit your bottom-most solution into a form where I can input my ellipse with the Centroid, SemiAxes, and Orientation properties?

1 Answer 1

6
data = RandomReal[{0, 1}, {100, 2}] r = 1/5; center = {1/6, 1/4}; sd = Select[data, EuclideanDistance[#, center] < r &] Show[ListPlot@data, Graphics@Circle[center, r], Graphics[{Red, PointSize[Large], Point@sd}], AspectRatio -> 1] 

Mathematica graphics

Edit

For an ellipse

data = RandomReal[{0, 1}, {100, 2}] r = 1/5; f1 = {1/6, 1/4}; f2 = {1/3, 1/5}; sd = Select[data, EuclideanDistance[#, f1] + EuclideanDistance[#, f2] < r &] Show[ListPlot@data, RegionPlot[EuclideanDistance[{x, y},f1] + EuclideanDistance[{x, y},f2] <r, {x, 0, 1}, {y, 0, 1}], Graphics[{Red, PointSize[Large], Point@sd}], AspectRatio -> 1] 

Mathematica graphics

Edit 2

Better code

data = RandomReal[{0, 1}, {100, 2}] r = 1/5; f1 = {1/6, 1/4}; f2 = {1/3, 1/5}; inside[{x_, y_}, {f1_, f2_}] := Sum[EuclideanDistance[{x, y}, i], {i, {f1, f2}}]; sd = Select[data, inside[#, {f1, f2}] < r &]; Show[ListPlot@data, RegionPlot[inside[{x, y}, {f1, f2}] < r, {x, 0, 1}, {y, 0, 1}], Graphics[{Red, PointSize[Large], Point@sd}], AspectRatio -> 1] 

Edit 3

Here you have the whole thing translated to your ComponentMeasurements output

(*{c,s,t}=1/.ComponentMeasurements[f,{"Centroid","SemiAxes",\ "Orientation"}] *) c = {.3, .4} s = {.4, .2} t = Pi/8 {s1, s2} = s center = {cx, cy} = c f = Sqrt[s1 s1 - s2 s2] f1 = {f1x, f1y} = {cx + f Cos[t], cy - f Sin[t]} f2 = {f2x, f2y} = {cx - f Cos[t], cy + f Sin[t]} r = 2 Sqrt[f f + s2 s2] data = RandomReal[{0, 1}, {100, 2}]; sd = Select[data, EuclideanDistance[#, f1] + EuclideanDistance[#, f2] < r &]; Show[ ListPlot@data, RegionPlot[ EuclideanDistance[{x, y}, f1] + EuclideanDistance[{x, y}, f2] < r, {x, 0, 1}, {y, 0, 1}], Graphics[{Red, PointSize[Large], Point@sd}], AspectRatio -> 1] 

Mathematica graphics

Sign up to request clarification or add additional context in comments.

4 Comments

Wow! Thank you so much belisarius. My Circle is actually an ellipse, but I think I can manage to translate your answer! This is perfect. Thank you!
@tquarton Please don't contact me by mail for further details, as that can't help others. If you need more help, post a comment here or update your question (the second option is better). Tnx!
Alright, I updated my question. My fault for not being very specific in the beginning. Thank you for all the help belisarius.
your solution worked perfectly, but I ran into another problem. I posted a related question here if you are interested in taking a look at it. I made it a separate question because its more related to image processing.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.