## The distance between two planets

A lot of the fun in coding models is when you can start using them for what they can tell you about the underlying problem.

### Where we are

So far we've built a simplified solar system consisting of two planets moving around a central point (the Sun) in perfect circular orbits.

Travelling from Earth to Mars is obviously the first thing that we're going to think about.

### The distance between two points

Recall that the model maps a planet's location onto a two dimensional (x,y) grid as it moves around a circle (an orbit). The distance between two planets in different orbits can be determined by finding the length between two points (planets) on the grid.

What is the formula for this distance between two points? Such things can be looked up easily. I prefer DuckDuckGo so I'm not tracked asking this question by a search engine that knows how many math courses I've taken.

You can check out the code yourself, but here is a list of distances between Earth and Mars on different days, printed to the console. It's serviceable, but you have to look closely to start to find interesting details. If you look closely at the full console in Silico, you'll notice that the distance increases and decreases in an orderly way. Each day the distance between the planets grows, or shrinks, and at some point switches between growing and shrinking. Hmm...

## Communicating with better output

Output from a model should be about communicating interesting things in the easiest way possible. Let's see if we can create output that shows this orderly growing/shrinking with something more accessible than a list of numbers.

### A visual representation

Although there are powerful tools that could be used to produce compelling charts, animations and visualizations, we're not yet at the point of turning our simple, terribly wrong, but intellecutally useful model into a multibillion dollar spaceflight boondoggle.

Boondoggles
Powerpoint is the key.

For now, something hacky will suffice, and by the way this is always more fun than rooting around in some graphing API.

Rather than printing a sequence of numbered distances on each orbital day, it will be easier to interpret the change if we draw a representation of this over time. A bar chart will do nicely, I think.

### A bar chart to Mars

The simplest way to do this is to create a bar in the console by stacking the "|" character, although you could find another character you like.

I've chosen to show the average distance between the Earth and Mars every 30 days as a single bar. Why 30 days? 30 Earth days is about an Earth month, and since I'm only interested in showing that the distance between the two can change significantly over time, it should be sufficient.

Each "|" is some amount of kilometers, scaled so that the bars don't shoot off the right side of the screen. You can check out the code for more details. ## Wrong and useful

This is simple output from a simple model but it's a useful aid for starting to think about interesting dimensions of the problem.

The distance between the two planets varies a lot. Some bars are a fraction of the size of others.

The big takeaway here is that if two planets in a similar plane are moving at different speeds (have different angular velocities) the distance between them will increase and decrease over time. The distance between Earth and Mars at Time 1 and Time 4.

If you make some simple assumptions about a spaceship that could travel between them, you might start thinking that when you travel is important.

Thus, the concept of a launch window: A period during which it's more advantageous to travel between planets, as a function of their orbits.

## More questions

The implication for travel between two planets is that if what is expended in transit (fuel, food, air etc.) depends on distance, flying a shorter distance is probably better than flying a longer one.

If the two orbits have properties similar to our model, when a transit occurs could matter quite a bit. If the ship is to complete some mission and then come home, perhaps the problem is even more complex...

Here we can start to think about what else we could explore with this model, such as building a simple mission feasability feature using some very basic assumptions about the capability of a spaceship.

That being said, I suspect we'll quickly get past the boundary of usefulness, given how simple the model is.