Description
I have a geometric configuration consisting of a set of geometric primitives e.g. points and lines. I want to define an area and retrieve all points and lines which are members of its region.
Example
Green is the area denoting the arbitrary region. I am after the points and lines within its boundaries.
These are the points and lines within the region above.
Here is my attempt to solve the problem.
Code
Module[
{module, lines, points, area},
(*Module Variable Declaration*)
module = {{0,0},{0,43},{11,43},{11,45},{15,45},{15,44},{26,44},{26,39},{38,39},{38,34},{50,34},{50,37},{80,37},{80,33},{89,33},{89,4},{75,4},{75,0}};
points = {{9,32},{6,25},{20,27},{25,23},{25,32},{33,29},{32,23},{37,24},{6,18},{10,9},{19,10},{22,9},{21,17},{23,14},{28,11},{27,18},{36,2},{34,15},{56,30},{68,30},{79,31},{60,25},{60,23},{62,22},{65,25},{72,24},{78,24},{83,21},{58,15},{57,13},{58,11},{59,7},{65,13},{67,19},{75,19},{78,13},{82,16},{68,8}};
lines = {{{16,42},{25,42}},{{16,39},{25,39}},{{17,37},{17,22}},{{7,30},{7,23}},{{23,32},{23,22}},{{4,34},{30,34}}, {{8,18},{8,8}},{{13,30},{13,8}},{{18,18},{18,8}},{{30,32},{30,11}},{{38,32},{38,6}},{{42,32},{42,6}},{{15,4},{39,4}},{{46,28},{55,35}},{{56,35},{78,35}},{{56,28},{79,28}},{{48,24},{48,12}},{{52,28},{52,10}},{{47,3},{60,3}},{{42,5.5},{62,5.5}},{{47,8.5},{67,8.5}}};
(*Arbitrary Region*)
area = {{0,0},{0,43},{11,43},{11,45},{15,45},{15,44},{26,44},{26,39},{38,39},{38,34},{38,0}};
(*Program*)
Graphics[{
{FaceForm @ White, EdgeForm @ {Thick, Gray},Polygon @ module},
{RGBColor["#339989"], Opacity @ .8, Polygon @ area},
Point @ points,
Line @ lines
}
]
(* Example of all 'points' and 'lines' within 'area'*)
(*RegionPlot @ (RegionIntersection[Polygon @ area, #] & /@ {Point @ points, Line @ lines})*)
]
I used RegionPlot
to visualzie the points and lines deduced after RegionIntersection
. However, I cannot retrieve the actual point and line definitions, and if I execute RegionInteresection
on its own, the method fails to workout the lines. It also seems to take <10~20 sec to execute :s
I would appreciate communities thoughts on the above, and accept an answer which would solve the above problem. The faster the solution the better. Note, I need a generic solution which could be applied to similar compositions.