Skip to content

Commit

Permalink
Fix the math for inverted shapes (including cylinders)
Browse files Browse the repository at this point in the history
  • Loading branch information
TrentHouliston committed Jun 23, 2019
1 parent 4a64fe3 commit 67868d1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
12 changes: 6 additions & 6 deletions src/geometry/Circle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@ namespace geometry {
return std::numeric_limits<Scalar>::quiet_NaN();
}

// Valid below the horizon
// Below the horizon with positive height
if (h > 0 && phi_n < M_PI_2) { return std::atan((2 * r / k + h * std::tan(phi_n)) / h); }
// Valid above the horizon
// Above the horizon with negative height
else if (h < 0 && phi_n > M_PI_2) {
return M_PI - std::atan((2 * r / k - h * std::tan(M_PI - phi_n)) / -h);
return M_PI - phi(phi_n, -h);
}
// Other situations are invalid so return NaN
else {
Expand All @@ -77,11 +77,11 @@ namespace geometry {
// If we are beyond our max distance return nan
if (std::abs(h) * tan(phi > M_PI_2 ? M_PI - phi : phi) > d) { return std::numeric_limits<Scalar>::quiet_NaN(); }

// Valid below the horizon
// Below the horizon with positive height
if (h > 0 && phi < M_PI_2) { return 2 * std::asin(r / (h * std::tan(phi) + r)) / k; }
// Valid above the horizon
// Above the horizon with negative height
else if (h < 0 && phi > M_PI_2) {
return 2 * std::asin(r / (-h * std::tan(M_PI - phi) + r)) / k;
return theta(M_PI - phi, -h);
}
// Other situations are invalid so return NaN
else {
Expand Down
17 changes: 8 additions & 9 deletions src/geometry/Sphere.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,15 @@ namespace geometry {
return std::numeric_limits<Scalar>::quiet_NaN();
}

// Our effective radius for the number of intersections
Scalar er = (h / 2) * (1 - std::pow(1 - 2 * r / h, 1 / k));

// Valid below the horizon
// Below the horizon with positive height
if (h > 0 && phi_n < M_PI_2) {
// Our effective radius for the number of intersections
Scalar er = (h / 2) * (1 - std::pow(1 - 2 * r / h, 1 / k));
return 2 * std::atan(er / (std::cos(phi_n) * (h - er)) + std::tan(phi_n)) - phi_n;
}
// Valid above the horizon
// Above the horizon with negative height
else if (h < 0 && phi_n > M_PI_2) {
return 2 * std::atan(er / (std::cos(M_PI - phi_n) * (-h - er)) + std::tan(M_PI - phi_n)) - M_PI - phi_n;
return M_PI - phi(M_PI - phi_n, -h);
}
// Other situations are invalid so return NaN
else {
Expand All @@ -84,11 +83,11 @@ namespace geometry {
return std::numeric_limits<Scalar>::quiet_NaN();
}

// Valid below the horizon
// Below the horizon with positive height
if (h > 0 && phi < M_PI_2) { return 2 * std::asin(r / ((h - r) * std::tan(phi))) / k; }
// Valid above the horizon
// Above the horizon with negative height
else if (h < 0 && phi > M_PI_2) {
return 2 * std::asin(r / (-(h - r) * std::tan(M_PI - phi))) / k;
return theta(M_PI - phi, -h);
}
// Other situations are invalid so return NaN
else {
Expand Down

0 comments on commit 67868d1

Please sign in to comment.