Advertisement
Guest User

bh.py

a guest
Jul 18th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.06 KB | None | 0 0
  1. import matplotlib.pyplot as plt
  2. from matplotlib.path import Path
  3. import matplotlib.patches as patches
  4. import pyclipper
  5. import itertools
  6. def gentri(len,originx,originy):
  7. h= int((len*0.866025)) #height
  8. top_tri= (originx, originy)
  9. lef_tri=((originx-(len/2)),(originy-h))
  10. right_tri= ((originx+(len/2)),(originy-h))
  11. base_tri= (top_tri,right_tri,lef_tri,top_tri)
  12.  
  13. return base_tri
  14.  
  15. def rowtri():
  16. row= range(0,5)
  17. result=[]
  18. baselen=10
  19. h = int((baselen * 0.866025)) # height
  20. originx=240
  21. originy= 170
  22.  
  23. for a in row:
  24. result.append (gentri(baselen,originx,originy))
  25. originx += baselen
  26. originx += 10
  27. print(result)
  28. for a in row:
  29. result.append (gentri(baselen,originx,originy))
  30. originy += baselen
  31. print (result)
  32. return result
  33. subj= rowtri()
  34.  
  35.  
  36.  
  37. clip =((180, 200), (260, 200), (260, 150),(180, 200))
  38.  
  39.  
  40. pc = pyclipper.Pyclipper()
  41.  
  42. pc.AddPath(clip, pyclipper.PT_CLIP, True)
  43.  
  44. pc.AddPaths(subj, pyclipper.PT_SUBJECT, False)
  45.  
  46.  
  47. solution = pc.Execute2(pyclipper.CT_INTERSECTION,pyclipper.PFT_NONZERO)
  48.  
  49.  
  50. solution= pyclipper.PolyTreeToPaths(solution)
  51. #%% Cleaning the data
  52. print (solution)
  53. print(list(itertools.chain.from_iterable(solution)))
  54.  
  55.  
  56.  
  57.  
  58. #%% Cleaning the data
  59.  
  60. def grafico(subj):
  61.  
  62. vertex= list(map(tuple,subj))
  63.  
  64. codes=list(range(0,len(vertex)))
  65. i=0
  66.  
  67.  
  68.  
  69. path = Path(vertex)
  70. xlim =min(vertex)[0]-10,max(vertex)[0]+10
  71. ylim = (min(vertex)[1]-10,max(vertex)[1]+10)
  72.  
  73. return path, xlim, ylim
  74.  
  75.  
  76.  
  77.  
  78. path, xlim, ylim = grafico(clip)
  79. #path2, xlim, ylim = grafico(subj)
  80.  
  81.  
  82.  
  83. fig = plt.figure()
  84. ax = fig.add_subplot(111)
  85. patch = patches.PathPatch(path, facecolor='None', edgecolor='blue')
  86. #patch2 = patches.PathPatch(path2, facecolor='None',edgecolor='red' )
  87.  
  88. print(solution)
  89. for a in subj:
  90.  
  91. pathsol, xlim, ylim = grafico(a)
  92.  
  93. ax.add_patch( patches.PathPatch(pathsol, facecolor='None',edgecolor='green' ))
  94. ax.add_patch(patch)
  95. #ax.add_patch(patch2)
  96. ax.set_xlim(150,280)
  97. ax.set_ylim(140,220)
  98.  
  99. plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement