21 for(
MInt i = 0; i < 3; i++) {
38 gratio = (1.0 + sqrt(5.0)) * 0.5;
48 MFloat theta1, theta2, theta3, theta4, f1, f4, f3, f5, f6;
65 theta3 = theta1 +
o1g * (theta2 - theta1);
66 theta4 = theta2 -
o1g * (theta2 - theta1);
73 if((f1 <= f3 && f3 <= f4) || (f3 <= f1 && f1 <= f4))
79 theta4 = theta2 -
o1g * (theta2 - theta1);
81 }
else if((f1 <= f4 && f4 <= f3) || (f4 <= f1 && f1 <= f3))
86 theta3 = theta1 +
o1g * (theta2 - theta1);
93 theta3 = theta1 +
o1g * (theta2 - theta1);
94 theta4 = theta2 -
o1g * (theta2 - theta1);
101 theta3 = theta1 +
o1g * (theta2 - theta1);
102 theta4 = theta2 -
o1g * (theta2 - theta1);
108 theta3 = theta1 +
o1g * (theta2 - theta1);
109 theta4 = theta2 -
o1g * (theta2 - theta1);
128 z[0] = x[1] *
y[2] - x[2] *
y[1];
129 z[1] = x[2] *
y[0] - x[0] *
y[2];
130 z[2] = x[0] *
y[1] - x[1] *
y[0];
140 if(
approx(length, 0.0, MFloatEps)) {
145 nvec[0] = vec[0] / length;
146 nvec[1] = vec[1] / length;
147 nvec[2] = vec[2] / length;
158 return Vec1[0] * Vec2[0] + Vec1[1] * Vec2[1] + Vec1[2] * Vec2[2];
166 MFloat alpha1, beta1, gamma1, v1, u1, alpha2, beta2, gamma2, v2, u2;
167 MFloat l1x, l1y, m1x, m1y, n1x, n1y, l2x, l2y, m2x, m2y, n2x, n2y;
168 MFloat a2d1, a2d2, b2d1, b2d2, angle1, angle2;
171 for(j = 0; j < 3; j++)
172 p[j] = cos(theta) *
p0[j] + sin(theta) *
dxp0[j];
180 alpha1 = l1x * l1x / (
a1 *
a1) + m1x * m1x / (
b1 *
b1) + n1x * n1x / (
c1 *
c1);
181 beta1 = l1y * l1x / (
a1 *
a1) + m1y * m1x / (
b1 *
b1) + n1x * n1y / (
c1 *
c1);
182 gamma1 = l1y * l1y / (
a1 *
a1) + m1y * m1y / (
b1 *
b1) + n1y * n1y / (
c1 *
c1);
183 v1 = sqrt(4.0 * beta1 * beta1 + (alpha1 - gamma1) * (alpha1 - gamma1));
184 angle1 = 0.5 * atan2(-2.0 * beta1, -(alpha1 - gamma1));
185 u1 = gamma1 + v1 * sin(angle1) * sin(angle1);
186 b2d1 = 1.0 / sqrt(u1);
187 a2d1 = 1.0 / sqrt(u1 - v1);
194 alpha2 = l2x * l2x / (
a2 *
a2) + m2x * m2x / (
b2 *
b2) + n2x * n2x / (
c2 *
c2);
195 beta2 = l2y * l2x / (
a2 *
a2) + m2y * m2x / (
b2 *
b2) + n2x * n2y / (
c2 *
c2);
196 gamma2 = l2y * l2y / (
a2 *
a2) + m2y * m2y / (
b2 *
b2) + n2y * n2y / (
c2 *
c2);
197 v2 = sqrt(4.0 * beta2 * beta2 + (alpha2 - gamma2) * (alpha2 - gamma2));
198 angle2 = 0.5 * atan2(-2.0 * beta2, -(alpha2 - gamma2));
199 u2 = gamma2 + v2 * sin(angle2) * sin(angle2);
200 b2d2 = 1.0 / sqrt(u2);
201 a2d2 = 1.0 / sqrt(u2 - v2);
204 return distance2d(a2d1, b2d1, a2d2, b2d2, angle1, angle2);
213 MFloat eps1, eps2, k1dotd, k2dotd, k1dotk2, nu, Ap[2][2];
214 MFloat lambdaplus, lambdaminus, bp2, ap2, cosphi, tanphi2, delta, dp, qu2;
215 MFloat A, B, C, D, E, alpha, beta, gamma, P, Q, A2, B2;
216 complex<MFloat> U,
y, qu, calpha;
218 eps1 = sqrt(1.0 - (b1_input * b1_input) / (a1_input * a1_input));
219 eps2 = sqrt(1.0 - (b2_input * b2_input) / (a2_input * a2_input));
220 k1dotd = cos(angle1);
221 k2dotd = cos(angle2);
222 k1dotk2 = cos(angle2 - angle1);
223 nu = a1_input / b1_input - 1.0;
225 b1_input * b1_input / (b2_input * b2_input)
226 * (1.0 + 0.5 * (1.0 + k1dotk2) * (nu * (2.0 + nu) - eps2 * eps2 * (1.0 + nu * k1dotk2) * (1.0 + nu * k1dotk2)));
228 b1_input * b1_input / (b2_input * b2_input)
229 * (1.0 + 0.5 * (1.0 - k1dotk2) * (nu * (2.0 + nu) - eps2 * eps2 * (1.0 - nu * k1dotk2) * (1.0 - nu * k1dotk2)));
230 Ap[0][1] = b1_input * b1_input / (b2_input * b2_input) * 0.5 * sqrt(1.0 - k1dotk2 * k1dotk2)
231 * (nu * (2.0 + nu) + eps2 * eps2 * (1.0 - nu * nu * k1dotk2 * k1dotk2));
233 0.5 * (Ap[0][0] + Ap[1][1]) + sqrt(0.25 * (Ap[0][0] - Ap[1][1]) * (Ap[0][0] - Ap[1][1]) + Ap[0][1] * Ap[0][1]);
235 0.5 * (Ap[0][0] + Ap[1][1]) - sqrt(0.25 * (Ap[0][0] - Ap[1][1]) * (Ap[0][0] - Ap[1][1]) + Ap[0][1] * Ap[0][1]);
236 bp2 = 1.0 / sqrt(lambdaplus);
237 ap2 = 1.0 / sqrt(lambdaminus);
239 if(
approx(k1dotk2, 1.0, MFloatEps)) {
240 if(Ap[0][0] > Ap[1][1])
241 cosphi = b1_input * k1dotd / (a1_input * sqrt(1.0 - eps1 * eps1 * k1dotd * k1dotd));
243 cosphi = sqrt(1.0 - k1dotd * k1dotd) / sqrt(1.0 - eps1 * eps1 * k1dotd * k1dotd);
246 / sqrt(2.0 * (Ap[0][1] * Ap[0][1] + (lambdaplus - Ap[0][0]) * (lambdaplus - Ap[0][0]))
247 * (1.0 - eps1 * eps1 * k1dotd * k1dotd))
248 * (Ap[0][1] / sqrt(1.0 + k1dotk2)
249 * (b1_input / a1_input * k1dotd + k2dotd + (b1_input / a1_input - 1.0) * k1dotd * k1dotk2)
250 + (lambdaplus - Ap[0][0]) / sqrt(1.0 - k1dotk2)
251 * (b1_input / a1_input * k1dotd - k2dotd - (b1_input / a1_input - 1.0) * k1dotd * k1dotk2));
254 delta = ap2 * ap2 / (bp2 * bp2) - 1.0;
255 if(
approx(delta, 0.0, MFloatEps) ||
approx(cosphi, 0.0, MFloatEps))
258 tanphi2 = 1.0 / (cosphi * cosphi) - 1.0;
259 A = -(1.0 + tanphi2) / (bp2 * bp2);
260 B = -2.0 * (1.0 + tanphi2 + delta) / bp2;
261 C = -tanphi2 - (1.0 + delta) * (1.0 + delta) + (1.0 + (1.0 + delta) * tanphi2) / (bp2 * bp2);
262 D = 2.0 * (1.0 + tanphi2) * (1.0 + delta) / bp2;
263 E = (1.0 + tanphi2 + delta) * (1.0 + delta);
266 alpha = -3.0 * B2 / (8.0 * A2) + C / A;
267 beta = B2 * B / (8.0 * A2 * A) - B * C / (2.0 * A2) + D / A;
268 gamma = -3.0 * B2 * B2 / (256.0 * A2 * A2) + C * B2 / (16.0 * A2 * A) - B * D / (4.0 * A2) + E / A;
269 calpha = complex<MFloat>(alpha, 0.0);
270 if(
approx(beta, 0.0, MFloatEps)) {
271 qu = complex<MFloat>(-B / (4.0 * A), 0.0)
272 + sqrt(0.5 * (-calpha + sqrt(complex<MFloat>(alpha * alpha - 4.0 * gamma, 0.0))));
274 P = -F1B12 * alpha * alpha - gamma;
275 Q = -alpha * alpha * alpha / 108.0 + F1B3 * alpha * gamma - 0.125 * beta * beta;
276 U =
c_cbrt(complex<MFloat>(-Q * 0.5, 0.0) + sqrt(complex<MFloat>(Q * Q * 0.25 + P * P * P / 27.0, 0.0)));
277 if(
approx(real(U), 0.0, MFloatEps) &&
approx(imag(U), 0.0, MFloatEps))
278 y = -5.0 * F1B6 * calpha -
c_cbrt(complex<MFloat>(Q, 0.0));
280 y = -5.0 * F1B6 * calpha + U - complex<MFloat>(P, 0.0) / (3.0 * U);
281 qu = complex<MFloat>(-B / (4.0 * A), 0.0)
283 * (sqrt(calpha + 2.0 *
y)
284 + sqrt(-(3.0 * calpha + 2.0 *
y + 2.0 * complex<MFloat>(beta, 0.0) / sqrt(calpha + 2.0 *
y))));
287 dp = sqrt((qu2 - 1.0) / delta * (1.0 + bp2 * (1.0 + delta)) * (1.0 + bp2 * (1.0 + delta)) / qu2
288 + (1.0 - (qu2 - 1.0) / delta) * (1.0 + bp2) * (1.0 + bp2) / qu2);
292 return dp * b1_input / sqrt(1.0 - eps1 * eps1 * k1dotd * k1dotd);
303 r = sqrt(
a *
a +
b *
b);
308 return complex<MFloat>(rn * cos(phi), rn * sin(phi));
std::complex< MFloat > c_cbrt(std::complex< MFloat >)
void norm(MFloat *vec, MFloat *nvec)
void crossP(MFloat *x, MFloat *y, MFloat *z)
MFloat dotP(MFloat *Vec1, MFloat *Vec2)
MFloat distance2d(MFloat, MFloat, MFloat, MFloat, MFloat, MFloat)
EllipsoidDistance(MFloat di[3], MFloat l1i[3], MFloat m1i[3], MFloat n1i[3], MFloat l2i[3], MFloat m2i[3], MFloat n2i[3], MFloat a1, MFloat b1, MFloat c1, MFloat a2, MFloat b2, MFloat c2)
MBool approx(const T &, const U &, const T)