如何从Mathematica中的椭圆图形中的列表图中收集数据点?

时间:2012-08-02 18:15:24

标签: wolfram-mathematica

更新:

我有一个数据列表图,我想收集圆形图形的特定边界内的所有数据点,这些数据点与Mathematica中的列表图重叠。

这样的事情可能吗?

我制作的椭圆形式为

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

你能帮助我将你最底层的解决方案融入我可以用Centroid,SemiAxes和Orientation属性输入椭圆的形式吗?

1 个答案:

答案 0 :(得分:5)

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

修改

对于椭圆

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

修改2

更好的代码

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]

编辑3

在这里,您将整个内容翻译为ComponentMeasurements输出

(*{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