1
$\begingroup$

I have these polygon points which are like these:

a = {Polygon[{{1504.1, 456.266}, {1539.8, 402.781}, {1588.17, 
    378.487}, {1528.17, 456.266}}], 

b=  Polygon[{{273.801, 456.266}, {273.801, 306.852}, {545.027, 
    306.852}, {587.642, 456.266}}], 

c=  Polygon[{{1495.53, 456.266}, {1500.18, 386.794}, {1539.8, 
    402.781}, {1504.1, 456.266}}], 

d= Polygon[{{1528.17, 456.266}, {1588.17, 378.487}, {1636.98, 
    345.708}, {1648.84, 456.266}}], 

e= Polygon[{{1569.07, 306.852}, {1494.36, 368.012}, {1031.56, 
    341.018}, {1028.45, 306.852}}], 

f= Polygon[{{1032.95, 456.266}, {1031.56, 341.018}, {1494.36, 
    368.012}, {1500.18, 386.794}, {1495.53, 456.266}}], 

g= Polygon[{{1648.84, 456.266}, {1636.98, 345.708}, {1641.75, 
    306.852}, {2025.09, 306.852}, {2025.09, 456.266}}], 

h= Polygon[{{587.642, 456.266}, {545.027, 306.852}, {1028.45, 
    306.852}, {1031.56, 341.018}, {1032.95, 456.266}}], 

i= Polygon[{{1641.75, 306.852}, {1636.98, 345.708}, {1588.17, 
    378.487}, {1539.8, 402.781}, {1500.18, 386.794}, {1494.36, 
    368.012}, {1569.07, 306.852}}]}

Now, from here, I want to extract the common points of i from a to h. So, suppose, the first value of i {1641.75, 306.852} is common in g. So, I want to extract g and save it. Then the second value {1636.98, 345.708} is common in d. So, then I want to extract d and save it. In this way, I want to find all the polygons that have one point which is common with i.

Please let me know how to do it.

$\endgroup$
2
$\begingroup$

Let's reformulate data a bit, you do not need all those variables and Polygons:

plgs = {

   {{1504.1, 456.266}, {1539.8, 402.781}, {1588.17, 378.487}, {1528.17, 456.266}},

   {{273.801, 456.266}, {273.801, 306.852}, {545.027, 306.852}, {587.642, 456.266}},

   {{1495.53, 456.266}, {1500.18, 386.794}, {1539.8, 402.781}, {1504.1, 456.266}},

   {{1528.17, 456.266}, {1588.17, 378.487}, {1636.98, 345.708}, {1648.84, 456.266}},

   {{1569.07, 306.852}, {1494.36, 368.012}, {1031.56, 341.018}, {1028.45, 306.852}},

   {{1032.95, 456.266}, {1031.56, 341.018}, {1494.36, 368.012}, {1500.18, 386.794}, {1495.53, 
     456.266}},

   {{1648.84, 456.266}, {1636.98, 345.708}, {1641.75, 306.852}, {2025.09, 306.852}, {2025.09, 
     456.266}},

   {{587.642, 456.266}, {545.027, 306.852}, {1028.45, 306.852}, {1031.56, 341.018}, {1032.95, 
     456.266}},

   {{1641.75, 306.852}, {1636.98, 345.708}, {1588.17, 378.487}, {1539.8, 402.781}, {1500.18, 
     386.794}, {1494.36, 368.012}, {1569.07, 306.852}}};

Let's get the picture, where orange is i-th polygon:

Graphics[{{FaceForm[], EdgeForm[Black], Polygon@plgs[[;; -2]]}, 
{FaceForm[Orange], EdgeForm[Black], Polygon@plgs[[-1]]}}]

enter image description here

Length of i-th:

iLength = Length[plgs[[-1]]]

7

Now compare the lengths:

neigh = Select[plgs[[;; -2]], 
Length[Union[Join[#, plgs[[-1]]]]] =!= Length[#] + iLength &];

and you got the neighbores:

Graphics[{{FaceForm[], EdgeForm[Black], Polygon@neigh}, 
{FaceForm[Orange], EdgeForm[Black], Polygon@plgs[[-1]]}}]

enter image description here

This works only if polygons have exactly the same points. If they do not, you can Round your data so points do become equivalent. Or use Other function in Select based, for example, on some EuclideanDistance less than a threshold criteria.

$\endgroup$
5
  • $\begingroup$ Hi, Thanks. But, the problem is I can't reform the data. The data I get has a polygon in front of it. How can I remove the polygon name from there? $\endgroup$ – Odrisso Jan 31 '16 at 22:48
  • $\begingroup$ @Odrisso Cases[data, Polygon[x_] -> x, Infinity] $\endgroup$ – Vitaliy Kaurov Jan 31 '16 at 22:54
  • $\begingroup$ Thanks a lot. Perfectly works. :) $\endgroup$ – Odrisso Jan 31 '16 at 23:05
  • $\begingroup$ Can you please explain this line a bit further: I don;t understand the line: neigh = Select[plgs[[;; -2]], Length[Union[Join[#, plgs[[-1]]]]] =!= Length[#] + iLength &] $\endgroup$ – Odrisso Jan 31 '16 at 23:25
  • $\begingroup$ @Odrisso please read docs carefully on every function there - especially Union. If 2 lists have the same point Union will remove duplicate and the total length of 2 lists will decreases. You could also use DeleteDuplicates instead of Union. $\endgroup$ – Vitaliy Kaurov Feb 1 '16 at 9:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.