import sys from math import sqrt # y x z # 0 1 2 def main(): bulkheadFile = open(sys.argv[1]) chinelogs = [] for line in bulkheadFile: points = line.split() for p in range(1, (len(points)+1)/2): if len(chinelogs) < p: chinelogs.append([]) chinelogs[p-1].append((float(points[0]), float(points[p*2-1]), float(points[p*2]))) chines = [] for ch in range(len(chinelogs)-1): base = chinelogs[ch][0] left = chinelogs[ch] right = chinelogs[ch+1] l3p = left[0] r3p = right[0] l2p = [0, 0] r2p = [0, dist3(l3p, r3p)] #print ch, 0, insInches(l2p), insInches(r2p) chines.append([[l2p, r2p]]) for b in range(1, len(left)): l2q = l2p r2q = r2p l3q = l3p r3q = r3p l3p = left[b] r3p = right[b] #print l2q, dist3(l3q, l3p), r2q, dist3(r3q, l3p) l2p = intersect(l2q, dist3(l3q, l3p), r2q, dist3(r3q, l3p)) #print l2p #print "r2p" r2p = intersect(l2q, dist3(l3q, r3p), r2q, dist3(r3q, r3p)) #print r2p #print ch, b, insInches(l2p), insInches(r2p) chines[ch].append([l2p, r2p]) for chine in chines: minx = chine[0][0][0] miny = chine[0][0][0] for bulkhead in chine: for point in bulkhead: if point[0] < minx: minx = point[0] if point[1] < miny: miny = point[1] for bulkhead in chine: for point in bulkhead: point[0] -= minx point[1] -= miny for chine in chines: print print str(chines.index(chine)) + ':' for bulkhead in chine: print str(round(bulkhead[0][0], 1)), '|', str(round(bulkhead[0][1], 1)) + ',', round(bulkhead[1][1], 1) # text #print str(round(bulkhead[0][0], 1)) + ',', str(round(bulkhead[0][1], 1)) + ',', round(bulkhead[1][1], 1) # CSV ''' def inInches(num): if int(abs(round((num - int(num))*16))) in (0, 16): return str(round(num)) if int(abs(round((num - int(num))*16))) == 8: return str(int(num)) + ' 1/2' if int(abs(round((num - int(num))*16))) in (4, 12): return str(int(num)) + ' ' + str(int(abs(round((num - int(num))*4)))) + '/4' if int(abs(round((num - int(num))*16))) in (2, 6, 10, 14): return str(int(round(num))) + ' ' + str(int(abs(round((num - int(num))*8)))) + '/8' return str(int(num)) + ' ' + str(int(abs(round((num - int(num))*16)))) + '/16' def insInches(l): return [inInches(c) for c in l] ''' def dist3(p1, p2): """find the distance between two points in three dimensions""" return sqrt(pow(p2[2] - p1[2], 2) + pow(p2[0] - p1[0], 2) + pow(p2[1] - p1[1], 2)) def intersect(p1, r1, p2, r2): """ find the intersection of the two coplanar circles with the specified radii and centers """ x1, y1 = p1 x2, y2 = p2 d = sqrt(pow(x2-x1, 2) + pow(y2-y1, 2)) #print p1, r1, p2, r2, d xa = (x2 + x1) / 2 + (x2 - x1)*(r1**2 - r2**2) / (2 * d**2) + (y2 - y1) / (2 * d**2) * sqrt(((r1+r2)**2 - d**2)*(d**2 - (r2-r1)**2)) xb = (x2 + x1) / 2 + (x2 - x1)*(r1**2 - r2**2) / (2 * d**2) - (y2 - y1) / (2 * d**2) * sqrt(((r1+r2)**2 - d**2)*(d**2 - (r2-r1)**2)) ya = (y2 + y1) / 2 + (y2 - y1)*(r1**2 - r2**2) / (2 * d**2) - (x2 - x1) / (2 * d**2) * sqrt(((r1+r2)**2 - d**2)*(d**2 - (r2-r1)**2)) yb = (y2 + y1) / 2 + (y2 - y1)*(r1**2 - r2**2) / (2 * d**2) + (x2 - x1) / (2 * d**2) * sqrt(((r1+r2)**2 - d**2)*(d**2 - (r2-r1)**2)) if xa > 0: return [xa, ya] else: return [xb, yb] def cflat(base, point): x = point[1] - base[1] y = sqrt(pow(point[0] - base[0], 2) + pow(point[2] - base[2], 2)) return (x, y) print chinelogs if __name__ == '__main__': main()