# How can Mathematica be used to detect an area surrounded by the most lines?

I have an array of lines that produce random shapes. These lines define edge boundaries from an array that I would like to use to reconstruct the main feature of the array. Can Mathematica find the points where most of these lines cross, and then define the largest area(s) inside these crossing points? I assume this will give me the main area(s) of the array to look at as in the example plot image. These lines are boundary lines and crossing too many reduces the accuracy of the area plot. There are 4 lines creating most boundaries. The first of those 4 is the line used in the plot below

lines={{{900., 703.449}, {590.556, 0.}}, {{900., 475.145}, {651.23, 0.}}, {{900., 286.849},
{660.333, 0.}}, {{900., 503.578}, {178.177,0.}}, {{0., 707.111}, {900., 689.133}}, {{231.482, 1093.}, {302.527, 0.}}, {{853.322, 1093.}, {568.821, 0.}}, {{513.461, 1093.},
{411.662, 0.}}, {{900., 521.686}, {514.729, 0.}}, {{280.141, 1093.}, {248.479, 0.}}, {{0., 183.582},
{900., 312.065}}, {{0., 648.073}, {900., 682.241}}, {{0.,110.149}, {900., 507.127}}, {{0., 402.186},
{900., 389.603}}, {{900., 605.326}, {324.743, 0.}}, {{706.587, 1093.}, {720.777, 0.}}, {{900., 86.9532},
{769.336, 0.}}, {{900., 539.768}, {610.491, 0.}}, {{900., 464.134}, {113.723, 0.}}, {{900.,428.16},
{47.3056, 0.}}, {{0., 1000.61}, {900., 988.023}}, {{316.911, 1093.}, {889.171, 0.}}, {{0., 337.878},
{900., 399.087}}, {{0., 492.562}, {900., 451.191}}, {{0.,344.122}, {900., 272.07}}, {{0., 151.791},
{900., 369.811}}, {{502.51, 1093.}, {352.038, 0.}}, {{0., 136.204}, {900.,460.163}}, {{177.623, 1093.}, {404.553, 0.}}, {{900., 234.416}, {665.35, 0.}}, {{900., 679.326}, {446.947, 0.}}, {{900., 1089.37}, {312.902, 0.}}, {{0., 652.435}, {900., 207.253}}, {{900.,115.841}, {712.418, 0.}}, {{900., 806.604}, {220.582, 0.}}, {{0., 783.297}, {900., 616.042}}, {{0., 1055.81}, {900., 938.313}}, {{300.376, 1093.}, {156.573, 0.}}, {{684.328, 1093.},
{770.733, 0.}}, {{0., 679.389}, {900., 733.378}}, {{900.,135.671}, {751.702, 0.}}, {{0., 1052.08},
{900., 822.61}}, {{900., 544.556}, {246.914, 0.}}, {{900., 879.237}, {32.7302, 1093.}}, {{0., 972.41},
{900., 956.231}}, {{0., 1026.6}, {900., 857.481}}, {{619.175, 1093.}, {818.911, 0.}}, {{0., 9.58286},
{900., 624.196}}, {{626.404, 1093.}, {555.359, 0.}}, {{772.244, 1093.}, {419.036, 0.}}, {{355.762, 1093.},
{105.964, 0.}}, {{900., 107.987}, {588.194, 1093.}}, {{806.666, 1093.}, {318.024, 0.}}, {{0., 86.1212},
{900., 760.554}}, {{279.164, 1093.}, {358.983, 0.}}, {{0., 27.23}, {900., 260.535}}, {{0., 169.335},
{900., 228.737}}, {{491.48, 1093.}, {96.8161, 0.}}, {{0., 404.323}, {900., 470.951}}, {{900., 681.523},
{342.039, 0.}}, {{732.078, 1093.}, {671.987, 0.}}, {{610.656, 1093.}, {406.405, 0.}}, {{0., 1069.95},
{900.,163.635}}, {{112.851, 1093.}, {397.351, 0.}}, {{0., 72.2908}, {900., 65.1008}}, {{644.998, 1093.},
{702.9, 0.}}, {{900., 720.816}, {203.947, 0.}}, {{549.162, 1093.}, {374.145, 0.}}, {{446.497, 1093.},
{434.49, 0.}}, {{0., 42.0853}, {900., 106.906}}, {{0., 743.122}, {900., 596.242}}, {{0.,630.275},
{900., 744.118}}, {{39.5396, 1093.}, {449.074, 0.}}};


• I feel this is a little underspecified... What is the criterion for determining the area in pink? You say: "find the points where these lines cross, and then define the largest area", but I can visually pick out areas that are larger than the one that you've highlighted and bounded by lines.
– rm -rf
Commented Nov 20, 2012 at 23:16
• So which are you looking for? The area defined by the largest NUMBER of lines or the largest area define by ANY amount of lines? Also, as rm-rf notes, your example isn't very accurate. Do you perhaps mean the largest such area which does not contain any other areas bounded by lines?
– VF1
Commented Nov 20, 2012 at 23:18
• Understood, please see my edits Commented Nov 20, 2012 at 23:39
• I think what everyone is asking is, why not this area instead of what you've drawn? Or something even bigger?
– user484
Commented Nov 21, 2012 at 1:09
• Okay, so what characteristic defines a boundary line and what is "too many" crossings? Also, since this shape is not a quadrilateral, there are obviously more than four bounding lines. To be honest I find the definition of this problem completely incomprehensible... Commented Nov 21, 2012 at 10:19

Did you see this answer by J. M.?

If you apply it on your set of lines, you can extract all the intersection points:

GraphicsMeshMeshInit[];

pts = FindIntersections[Line /@ lines]; (*intersection points*)

Graphics[{{AbsoluteThickness[1],
Line /@ lines}, {Directive[Red, AbsolutePointSize[4]],
Point[pts]}}]


You could then use SmoothDensityHistogram to visualize where the intersections are denser, but you have then to choose a criterion to pick the corners that would define your polygon.

SmoothDensityHistogram[pts]


• I told OP about that answer you linked to in chat, so it would seem he's at least aware... Commented Nov 21, 2012 at 12:11
• @VLC one could then use, say WatershedComponents to identify the boundary of the deepest valley? I guess we need a criterion to decide how many points within the region is ok... Commented Nov 21, 2012 at 13:13
• @VLC Thank you! Commented Nov 24, 2012 at 13:46