Fix R < r torus intersection bug (#2589)

Co-authored-by: Paul Romano <paul.k.romano@gmail.com>
This commit is contained in:
Egor Afanasenko 2023-07-15 00:20:30 +03:00 committed by GitHub
parent c5f551103f
commit 3f9cd0d7cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -972,7 +972,14 @@ double torus_distance(double x1, double x2, double x3, double u1, double u2,
if (roots[i].imag() == 0) {
double root = roots[i].real();
if (root > cutoff && root < distance) {
distance = root;
// Avoid roots corresponding to internal surfaces
double s1 = x1 + u1 * root;
double s2 = x2 + u2 * root;
double s3 = x3 + u3 * root;
double check = D * s3 * s3 + s1 * s1 + s2 * s2 + A * A - C * C;
if (check >= 0) {
distance = root;
}
}
}
}