i have been working electronic structure mapping. used python write code in have polygon shape (not polygon) , have set of x , y coordinates. first had check whether points inside polygon or outside. pretty able do. problem want calculate distance between polygon , points outside polygon. can me that?
here code:
note: c14list.dat file importing set of points , format (<element name> <x-axis><y-axis>)
laves kind of polygon
import numpy np def maverick(x,y,cir): if (x,y) in cir: return "in convex hull" in range(len(cir)): p1 = none p2 = none if i==0: p1 = cir[0] p2 = cir[1] else: p1 = cir[i-1] p2 = cir[i] if p1[1] == p2[1] , p1[1] == y , x > min(p1[0], p2[0]) , x < max(p1[0], p2[0]): return "in convex hull" n = len(cir) inside = false p1x,p1y = cir[0] in range(n+1): p2x,p2y = cir[i % n] if y > min(p1y,p2y): if y <= max(p1y,p2y): if x <= max(p1x,p2x): if p1y != p2y: xints = (y-p1y)*(p2x-p1x)/(p2y-p1y)+p1x if p1x == p2x or x <= xints: inside = not inside p1x,p1y = p2x,p2y if inside: return "in convex hull" else: return "out of convex hull" laves = [(4.667,0.22701578), (5.667,0.33127494), (6.283,0.32687551), (11.333,0.26443006),(9.667,0.11122194),(9.333,0.1067382),(5.667,0.09125353),(5,0.1141427),(4.667,0.22701578)] f = open('c14list.dat','r') label_arr=[] x_arr=[] y_arr=[] in range(69): a=f.readline() a=str(a).split('\t') lent = len(a) label_arr.append(a[0]) x_arr.append(float(a[1])) y_arr.append(float(a[lent-1][0:10])) in range(69): label=label_arr[i] x=x_arr[i] y=y_arr[i] print label,'\t',x,'\t',y,'\t',maverick(x,y,laves)
Comments
Post a Comment