def getNextPosAndResult(self, pos, e): left = pos + e* (-self.stepSize) right = pos + e * (self.stepSize) left2 = pos + e* (-self.stepSize/4) right2 = pos + e * (self.stepSize/4) mini = goldenSectionSearch(self.variables, self.getFunctionResult, left, right, self.epsilon) miniVal = self.getFunctionResult(dict(zip(self.variables, mini))) return mini, miniVal
def tilt_d_s_given_center(pointset, c): '''Tilt, foci spacing, and string length given center. ''' tlo,thi = 0,math.pi def area(t): d,s = d_s_given_center_tilt(pointset, c, t) return 0.25*math.pi*s*math.sqrt(s**2-d**2) b = tlo+resphi*(thi-tlo) T = goldenSectionSearch(area, zip((tlo,b,thi),3*[None]), 0.05*thi) return T, + d_s_given_center_tilt(c,T)
def tilt_d_s_given_center(pointset, c): '''Tilt, foci spacing, and string length given center. ''' tlo, thi = 0, math.pi def area(t): d, s = d_s_given_center_tilt(pointset, c, t) return 0.25 * math.pi * s * math.sqrt(s**2 - d**2) b = tlo + resphi * (thi - tlo) T = goldenSectionSearch(area, zip((tlo, b, thi), 3 * [None]), 0.05 * thi) return T, +d_s_given_center_tilt(c, T)
def d_s_given_center_tilt(pointset, c, t): '''Foci spacing and string length given center and tilt.''' dlo,dhi = (0, 2*max([math.sqrt(np.dot(*(2*[c-p]))) for p in pointset])) def s_given_d(d): delta = 0.5*d*np.array([math.cos(t),math.sin(t)]) foci = [c+delta,c-delta] return s_given_foci(pointset, foci) def area(d): s = s_given_d(d) a = 0.25*math.pi*s*math.sqrt(s**2-d**2) return a b = dlo+resphi*(dhi-dlo) D = goldenSectionSearch(area, zip((dlo,b,dhi),3*[None]), 0.0001*dhi) return D , s_given_d(D)
def d_s_given_center_tilt(pointset, c, t): '''Foci spacing and string length given center and tilt.''' dlo, dhi = (0, 2 * max([math.sqrt(np.dot(*(2 * [c - p]))) for p in pointset])) def s_given_d(d): delta = 0.5 * d * np.array([math.cos(t), math.sin(t)]) foci = [c + delta, c - delta] return s_given_foci(pointset, foci) def area(d): s = s_given_d(d) a = 0.25 * math.pi * s * math.sqrt(s**2 - d**2) return a b = dlo + resphi * (dhi - dlo) D = goldenSectionSearch(area, zip((dlo, b, dhi), 3 * [None]), 0.0001 * dhi) return D, s_given_d(D)