78 if (fabs(slant-p_a[0]) < p_tolerance) {
93 p_initialMinGroundRangeGuess = (slant - p_a[0]) / p_a[1];
94 double minGroundRangeGuess = slant - (p_a[0] + p_initialMinGroundRangeGuess *
95 (p_a[1] + p_initialMinGroundRangeGuess * (p_a[2] + p_initialMinGroundRangeGuess * p_a[3])));
97 p_initialMaxGroundRangeGuess = p_initialMinGroundRangeGuess + minGroundRangeGuess /
98 (p_a[1] + p_initialMinGroundRangeGuess * (2.0 * p_a[2] + p_initialMinGroundRangeGuess *
100 double maxGroundRangeGuess = slant - (p_a[0] + p_initialMaxGroundRangeGuess *
101 (p_a[1] + p_initialMaxGroundRangeGuess * (p_a[2] +
102 p_initialMaxGroundRangeGuess * p_a[3])));
104 p_initialMinGroundRangeGuess = p_initialMaxGroundRangeGuess - 10.0;
105 minGroundRangeGuess = slant - (p_a[0] + p_initialMinGroundRangeGuess *
106 (p_a[1] + p_initialMinGroundRangeGuess * (p_a[2] + p_initialMinGroundRangeGuess * p_a[3])));
110 if ((minGroundRangeGuess < 0.0 && maxGroundRangeGuess < 0.0) ||
111 (minGroundRangeGuess > 0.0 && maxGroundRangeGuess > 0.0)) {
113 int maxBracketIters = 10;
115 float xMin = p_initialMinGroundRangeGuess;
116 float xMax = p_initialMaxGroundRangeGuess;
118 float funcMin = minGroundRangeGuess;
119 float funcMax = maxGroundRangeGuess;
121 for (
int j=0; j<maxBracketIters; j++) {
124 float dist = abs(abs(xMin) - abs(xMax));
128 if (abs(funcMin) <= abs(funcMax)) {
130 xMin = xMax - 2*dist;
134 xMax = xMin + 2*dist;
137 funcMin = slant -(p_a[0]+ xMin *(p_a[1] + xMin * (p_a[2] + xMin * p_a[3])));
138 funcMax = slant - (p_a[0] + xMax *(p_a[1] + xMax * (p_a[2] + xMax * p_a[3])));
141 if ((funcMin <= 0.0 && funcMax >= 0.0) || (funcMin >= 0.0 && funcMax <= 0.0)){
142 p_initialMinGroundRangeGuess = xMin;
143 p_initialMaxGroundRangeGuess = xMax;
144 minGroundRangeGuess = funcMin;
145 maxGroundRangeGuess = funcMax;
154 if ((minGroundRangeGuess == maxGroundRangeGuess) ||
155 (minGroundRangeGuess < 0.0 && maxGroundRangeGuess < 0.0) ||
156 (minGroundRangeGuess > 0.0 && maxGroundRangeGuess > 0.0)) {
167 double ax = p_initialMinGroundRangeGuess;
168 double bx = p_initialMaxGroundRangeGuess;
169 double fax = minGroundRangeGuess;
170 double fbx = maxGroundRangeGuess;
177 double p, q, r, s, t;
181 if (fbx * fcx > 0.0) {
187 if (fabs(fcx) < fabs(fbx)) {
195 tol1 = 2.0 * eps * fabs(bx) + 0.5 * p_tolerance;
196 xm = 0.5 * (cx - bx);
197 if (fabs(xm) <= tol1 || fbx == 0.0) {
202 if (fabs(e) >= tol1 && fabs(fax) > fabs(fbx)) {
211 p = s * (2.0 * xm * q * (q - r) - (bx - ax) * (r - 1.0));
212 q = (q - 1.0) * (r - 1.0) * (s - 1.0);
216 t = 3.0 * xm * q - fabs(tol1 * q);
217 if (t > fabs(e * q)) t = fabs(e * q);
233 if (fabs(d) > tol1) {
245 fbx = slant - (p_a[0] + bx * (p_a[1] + bx * (p_a[2] + bx * p_a[3])));
247 while (iter <= p_maxIterations);
279 double currentEt = p_camera->
time().Et();
281 std::vector<double>::iterator pos = lower_bound(p_time.begin(), p_time.end(), currentEt);
283 int index = p_time.size() - 1;
284 if (currentEt <= p_time[0]) {
290 else if (currentEt >= p_time.at(index)) {
291 p_a[0] = p_a0[index];
292 p_a[1] = p_a1[index];
293 p_a[2] = p_a2[index];
294 p_a[3] = p_a3[index];
296 index = pos - p_time.begin();
297 double weight = (currentEt - p_time.at(index-1)) /
298 (p_time.at(index) - p_time.at(index-1));
299 p_a[0] = p_a0[index-1] * (1.0 - weight) + p_a0[index] * weight;
300 p_a[1] = p_a1[index-1] * (1.0 - weight) + p_a1[index] * weight;
301 p_a[2] = p_a2[index-1] * (1.0 - weight) + p_a2[index] * weight;
302 p_a[3] = p_a3[index-1] * (1.0 - weight) + p_a3[index] * weight;