Principia icon indicating copy to clipboard operation
Principia copied to clipboard

planet collision point displayed in wrong place

Open vladtcvs opened this issue 3 years ago • 4 comments

ksp 1.11, principia gödel and all previous

when path intersects planet, principia draws a symbol of collision on the path. But it draws it not in the place, where path intersects planet, but in periapsis (which is under surface)

vladtcvs avatar Mar 11 '21 17:03 vladtcvs

We should really compute the collisions in the C++. How hard can it be to intersect a sphere and a segment?

pleroy avatar Mar 29 '21 23:03 pleroy

the easiest way to find collision point - use bisect.

vladtcvs avatar Mar 30 '21 05:03 vladtcvs

Also, planets are not exact spheres. They have mountains and valleys. So using bisect looks like the only solution

vladtcvs avatar Mar 30 '21 05:03 vladtcvs

Planets are spheres in Principia, just say no to ridiculously expensive height maps. If your flight plan entails flying through the Grand Canyon, think again because you'll be sorry as soon as you enter the atmosphere.

Notes to self:

  1. Trajectories are cubic, so the intersection involves solving a cubic equation. That's hard to do in a way that's properly conditioned. There are papers by Kahan and Blinn on that topic.
  2. We do use Bisect to find ascending/descending nodes. That's stupid. We should either use Brent or solve the cubic.

pleroy avatar Mar 30 '21 07:03 pleroy

In the end, we decided to compute the impact properly, taking the terrain into account (and not assuming that planets are spheres).

For the record, it's not practical to find the the first collision using bisection. Bisection will easily find one collision, but not necessarily the first. In addition, in order to use bisection in the first place you need a point underground, and there is no guarantee that the periapsis is underground even if there is a collision: the periapsis could be in a crater and the collision on the wall of that crater. We used such an approach in Jordan and Julia, but it resulted in collisions being drawn at semi-random places or missed entirely.

In the end we found that building interpolants to the height above the terrain using Чебышёв polynomials, with suitable subdivisions, is the best approach. We then compute all zeros of these polynomials as eigenvalues of the companion matrix using the Schur decomposition, thereby ensuring that we find all the zeros regardless of the shape of the terrain. See the above pull requests and [Boy06] and [Boy13] in the bibliography.

pleroy avatar Feb 01 '24 23:02 pleroy