def get_slope(self, surf="top", xpos=0.0): if surf == "top": curve = list(self.top) else: curve = list(self.bottom) slopes = spline.derivative1(curve) index = spline.binsearch(curve, xpos) slope = slopes[index] return slope
def project_contour(self, surf="top", xstart=0, xend=None, xdist=None, ysize=0): #print "xstart=" + str(xstart) + " xend=" + str(xend) + " xdist=" + str(xdist) curve = [] #print "surf == " + surf if surf == "top": curve = list(self.top) else: curve = list(self.bottom) #print str(curve) n = len(curve) slopes = spline.derivative1(curve) shape = [] # make the exact sweep base line dist = 0.0 xpos = xstart #print 'xpos:', xpos, 'curve:', curve ypos = self.simple_interp(curve, xstart) if ypos: shape.append((xpos, ypos)) index = spline.binsearch(curve, xpos) if curve[index][0] <= xpos: index += 1 next_dist = 0 done = False #while index < n and dist + next_dist <= xdist: while index < n and not done: nextpt = curve[index] next_dist = self.dist_2d((xpos, ypos), nextpt) if (xdist and dist + next_dist <= xdist) or \ (xend and nextpt[0] <= xend): dist += next_dist xpos = nextpt[0] ypos = nextpt[1] if ypos: shape.append((xpos, ypos)) index += 1 else: done = True # add the final point of the curve (if needed) if index < n and xdist and dist < xdist: rem = xdist - dist #print "rem = " + str(rem) pct = rem / next_dist #print "pct of next step = " + str(pct) dx = nextpt[0] - xpos xpos += dx * pct ypos = self.simple_interp(curve, xpos) if ypos: shape.append((xpos, ypos)) elif index < n and xend and xpos < xend: xpos = xend ypos = self.simple_interp(curve, xpos) if ypos: shape.append((xpos, ypos)) # project the sweep line at the specified thickness result = [] #print 'shape:', shape for p in shape: index = spline.binsearch(curve, p[0]) slope = slopes[index] #print 'p:', p proj = self.project_point(p, ysize, surf, slope) result.append(proj) return result
def project_contour(self, surf="top", \ xstart=0, xend=None, xdist=None, \ ysize=0): #print "xstart=" + str(xstart) + " xend=" + str(xend) + " xdist=" + str(xdist) curve = [] #print "surf == " + surf if surf == "top": curve = list(self.top) else: curve = list(self.bottom) #print str(curve) n = len(curve) slopes = spline.derivative1(curve) shape = [] # make the exact sweep base line dist = 0.0 xpos = xstart ypos = self.simple_interp(curve, xstart) shape.append( (xpos, ypos) ) index = spline.binsearch(curve, xpos) if curve[index][0] <= xpos: index += 1 next_dist = 0 done = False #while index < n and dist + next_dist <= xdist: while index < n and not done: nextpt = curve[index] next_dist = self.dist_2d( (xpos, ypos), nextpt ) if (xdist and dist + next_dist <= xdist) or \ (xend and nextpt[0] <= xend): dist += next_dist xpos = nextpt[0] ypos = nextpt[1] shape.append( (xpos, ypos) ) index += 1 else: done = True # add the final point of the curve (if needed) if index < n and xdist and dist < xdist: rem = xdist - dist #print "rem = " + str(rem) pct = rem / next_dist #print "pct of next step = " + str(pct) dx = nextpt[0] - xpos xpos += dx * pct ypos = self.simple_interp(curve, xpos) shape.append( (xpos, ypos) ) elif index < n and xend and xpos < xend: xpos = xend ypos = self.simple_interp(curve, xpos) shape.append( (xpos, ypos) ) # project the sweep line at the specified thickness result = [] for p in shape: index = spline.binsearch(curve, p[0]) slope = slopes[index] proj = self.project_point(p, ysize, surf, slope) result.append(proj) return result