Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import matplotlib.pyplot as plt
- from matplotlib.path import Path
- import matplotlib.patches as patches
- import pyclipper
- import itertools
- def gentri(len,originx,originy):
- h= int((len*0.866025)) #height
- top_tri= (originx, originy)
- lef_tri=((originx-(len/2)),(originy-h))
- right_tri= ((originx+(len/2)),(originy-h))
- base_tri= (top_tri,right_tri,lef_tri,top_tri)
- return base_tri
- def rowtri():
- row= range(0,5)
- result=[]
- baselen=10
- h = int((baselen * 0.866025)) # height
- originx=240
- originy= 170
- for a in row:
- result.append (gentri(baselen,originx,originy))
- originx += baselen
- originx += 10
- print(result)
- for a in row:
- result.append (gentri(baselen,originx,originy))
- originy += baselen
- print (result)
- return result
- subj= rowtri()
- clip =((180, 200), (260, 200), (260, 150),(180, 200))
- pc = pyclipper.Pyclipper()
- pc.AddPath(clip, pyclipper.PT_CLIP, True)
- pc.AddPaths(subj, pyclipper.PT_SUBJECT, False)
- solution = pc.Execute2(pyclipper.CT_INTERSECTION,pyclipper.PFT_NONZERO)
- solution= pyclipper.PolyTreeToPaths(solution)
- #%% Cleaning the data
- print (solution)
- print(list(itertools.chain.from_iterable(solution)))
- #%% Cleaning the data
- def grafico(subj):
- vertex= list(map(tuple,subj))
- codes=list(range(0,len(vertex)))
- i=0
- path = Path(vertex)
- xlim =min(vertex)[0]-10,max(vertex)[0]+10
- ylim = (min(vertex)[1]-10,max(vertex)[1]+10)
- return path, xlim, ylim
- path, xlim, ylim = grafico(clip)
- #path2, xlim, ylim = grafico(subj)
- fig = plt.figure()
- ax = fig.add_subplot(111)
- patch = patches.PathPatch(path, facecolor='None', edgecolor='blue')
- #patch2 = patches.PathPatch(path2, facecolor='None',edgecolor='red' )
- print(solution)
- for a in subj:
- pathsol, xlim, ylim = grafico(a)
- ax.add_patch( patches.PathPatch(pathsol, facecolor='None',edgecolor='green' ))
- ax.add_patch(patch)
- #ax.add_patch(patch2)
- ax.set_xlim(150,280)
- ax.set_ylim(140,220)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement