def calc_epm_zones(pts): if len(pts) != 8: print >> sys.stderr, 'argument must be list of length 8; length is %s. argument pts:\n%s' % (len(pts),pts) raise ValueError else: outerpts = [] m1,b1 = vidtools.line_fx_from_pts(pts[0],pts[1]) m2,b2 = vidtools.line_fx_from_pts(pts[7],pts[6]) x = (b2-b1)/(m1-m2) y = m2*x+b2 outerpts.append((x,y)) m2,b2 = vidtools.line_fx_from_pts(pts[2],pts[3]) x = (b2-b1)/(m1-m2) y = m2*x+b2 outerpts.append((x,y)) m1,b1 = vidtools.line_fx_from_pts(pts[4],pts[5]) x = (b2-b1)/(m1-m2) y = m2*x+b2 outerpts.append((x,y)) m2,b2 = vidtools.line_fx_from_pts(pts[7],pts[6]) x = (b2-b1)/(m1-m2) y = m2*x+b2 outerpts.append((x,y)) centerpts = [] m1,b1 = vidtools.line_fx_from_pts(pts[0],pts[5]) m2,b2 = vidtools.line_fx_from_pts(pts[7],pts[2]) x = (b2-b1)/(m1-m2) y = m2*x+b2 centerpts.append((x,y)) m1,b1 = vidtools.line_fx_from_pts(pts[1],pts[4]) x = (b2-b1)/(m1-m2) y = m2*x+b2 centerpts.append((x,y)) centerpts m2,b2 = vidtools.line_fx_from_pts(pts[6],pts[3]) x = (b2-b1)/(m1-m2) y = m2*x+b2 centerpts.append((x,y)) m1,b1 = vidtools.line_fx_from_pts(pts[0],pts[5]) x = (b2-b1)/(m1-m2) y = m2*x+b2 centerpts.append((x,y)) zones = {} zones['F1'] = [outerpts[0],pts[0],centerpts[0],pts[7]] zones['F2'] = [pts[1],outerpts[1],pts[2],centerpts[1]] zones['F3'] = [centerpts[2],pts[3],outerpts[2],pts[4]] zones['F4'] = [pts[6],centerpts[3],pts[5],outerpts[3]] zones['OT'] = [pts[0],pts[1],centerpts[1],centerpts[0]] zones['OB'] = [centerpts[3],centerpts[2],pts[4],pts[5]] zones['CR'] = [centerpts[1],pts[2],pts[3],centerpts[2]] zones['CL'] = [pts[7],centerpts[0],centerpts[3],pts[6]] zones['M'] = centerpts return zones
def nearest_point_on_line(lpt1,lpt2,qpt): h = vidtools.hypotenuse(lpt1,lpt2) xdiff = lpt2[0] - lpt1[0] m,b = vidtools.line_fx_from_pts(lpt1,lpt2) xstep = xdiff/h lpoly = [(x,(m*x+b)) for x in numpy.arange(lpt1[0],lpt2[0],xstep)] return vidtools.perigee(lpoly,[qpt])
def calc_chord_stats(tun,cm_factor=1): h = vidtools.hypotenuse(tun[0],tun[-1]) xdiff = tun[-1][0] - tun[0][0] m,b = vidtools.line_fx_from_pts(tun[0],tun[-1]) xstep = xdiff/h lpoly = [(x,(m*x+b)) for x in numpy.arange(tun[0][0],tun[-1][0],xstep)] on_chord_pt,on_curve_pt = max([(vidtools.hypotenuse(*vidtools.perigee(lpoly,[p])),vidtools.perigee(lpoly,[p])) for p in tun])[1] chord_len = vidtools.hypotenuse(tun[0],tun[-1])/cm_factor chord_pt = vidtools.hypotenuse(tun[0],on_chord_pt)/cm_factor chord_dp = vidtools.hypotenuse(on_chord_pt,on_curve_pt)/cm_factor return chord_len, chord_pt, chord_dp