pagnatious
pagnatious

Reputation: 193

How to predict encounters between a ship and a body's sphere of influence in 2D

Long time listener, first time caller. I'm making a little hobby game in XNA, its about transport ships in space, analogous to container ships at sea. I need to be able to predict the encounter between a Ship and a planet/moons gravitational sphere of influence in a restricted 2D environment. The positions at time of the Ship and planet/moon, Body for short, are determined from keplerian orbital elements. The Ship and Body both orbit the same centre of attraction.

The approach I have devised so far is first to do some preliminary checks on the apoapsis and periapsis (farthest and closest points from centre of attraction) to see if an encounter is possible. Between checks such as this and if the Ship's orbit is open (hyperbolic, I approximate the parabola case to a hyperbola), it can rule out many scenarios where there could not be an encounter.

If these checks determine an encounter is possible, I determine the minimum and maximum distance from centre of attraction that the Ship is eligible for an encounter. I then get the intersection points of the ships orbit with the two circles defined by that minimum and maximum. This results in zero, two, or four, points on the Ship's orbit, defining zero, one, or two periods where it could encounter the sphere of the Body. At this point if there are zero intersections it is possible the whole of the Ship orbit is in the encounter zone, this is probably an uncommon extreme case but would need to be covered.

I can get the times that the Ship will pass those points on it's orbit, giving one or two windows of time to check for encounter, but from there my best solution is searching the time span by dividing it into steps, calculating the Body's position at those times, and then testing for encounter.

The trouble with that approach is knowing the size to make the steps to efficiently find the encounter. Getting the Body's position at time is somewhat expensive so I'd rather do it as little as possible, but steps too large could potentially miss the encounter.

Are there any properties of confocal conic shapes that could help reduce the search space? Or are there other ways to predict encounter/collision between what is effectively a point moving along a conic path and a circle moving along an ellipse sharing a focal point.

Upvotes: 17

Views: 1257

Answers (3)

se5a
se5a

Reputation: 97

Since this hasn't got an accepted answer yet and I don't see the below calculations I'll add these in the hopes that it will help someone. I've not figured out how to get a date time, I have however figured out how to get angles. This will get you the distance between the orbiting body and the soi (or ship) if you know the angle:

public static double RadiusAtAngle(double angle, double semiLatusRectum, double eccentricity)
{
    return semiLatusRectum / (1 + eccentricity * Math.Cos(angle)); 
}

More importantly, flipping that calc gets you the angle to the soi edge if you know the semiLatusRectum and the eccentricity (radius here will be the distance from the body to the soi edge):

public static double AngleAtRadus(double radius, double semiLatusRectum, double eccentricity)
{
    //r = p / (1 + e * cos(θ))
    //1 + e * cos(θ) = p/r
    //((p / r) -1) / e = cos(θ)
    return Math.Acos((semiLatusRectum / radius - 1) / eccentricity);
}

For reference, semiLatusRectum can be found from the semiMajorAxis and eccentricity:

public static double SemiLatusRectum(double SemiMajorAxis, double eccentricity)
{
    if (eccentricity == 0)//ie a circle 
        return SemiMajorAxis;
    return SemiMajorAxis * (1 - eccentricity * eccentricity);
}

Note that these calcs will also work for hyperbolic trajectories.

Upvotes: 0

j_random_hacker
j_random_hacker

Reputation: 51316

You could try constructing the function describing the (square of the) distance between the planet and the ship as a function of time, using the usual Pythagoras distance expression. You are looking for zeros of this function, so Newton's method or similar can be applied to find them.

This should work well provided that the planet's motion is much slower than the ship's -- then the function will be relatively smooth, and Newton's method will have no trouble converging. However if the planet's motion is much faster than the ship's, then this distance function will bounce up and down, like a "spring" superimposed on some parabola-like curve, and will possibly intersect the x axis several times. Newton's method can have trouble with such functions, where the derivative changes direction rapidly.

Hopefully some terms will cancel out when you construct the distance function, or the expression can be otherwise simplified or approximated, but if not it may be sufficient to look for zeros in the vertical and horizontal directions. (You could in fact choose distances along any axis -- e.g. the major axis of the planet's orbit.) Zeros in either of these functions are necessary but not sufficient conditions for collision, and may be simpler to calculate. If you have a list of x-direction zeros sorted by time and the same for y-direction zeros, you can find any true collisions by calculating their intersection with a list merge (a la mergesort).

Upvotes: 1

Jon Harbour
Jon Harbour

Reputation: 402

Use radial collision detection (circles), with one circle representing the planet's gravity influence (will be larger than the planet itself), another circle for each ship, and cause the center point of each circle to move toward each other in a straight line ever so slightly as the distance decreases.

Apply the amount of pull each circle has to the rate of movement of each ship. Movement can be done with just simple trig, cos() for x, sin() for y, no need for any more complex math. When the distance between any two objects is less than the sum of their radii, then a collision has occurred.

But when doing this form of collision on just the "gravity circles", so to speak, when they collide, you can increase the speed of the ship by a small amount every iteration to simulate the pull of gravity.

Upvotes: 1

Related Questions