Representing Large Distances (Light years)

Started by
6 comments, last by alvaro 12 years, 11 months ago
Simple question really, I am wondering how programs like Celestia can represent such large distances (say 1000 light years is the distance across the Milky Way galaxy).
Advertisement
If your base unit of measurement is 1 meter, then a 64 bit number actually has just enough precision to store 1000 light-years ;)

I'm guessing though that they wouldn't use absolute positions - locations could be describe as a relative offset from a parent coordinate system.

e.g. the centre of a solar system could be quantised to the nearest million kilometers (and stored in a format where "1" represents 1M km), then planets could describe their position relative to the solar system, etc...
Scientific programs have support for big numbers which are arbitrary precision floating point numbers.. So the coordinates are probably stored in that which isn't limited by the machines integral types..
You can also use one value to represent large units, and a second one to represent small units. For example, use a long to store the light year position, and a double for the fraction part. Its the same way you keep track of years, days, hours, etc. though for a bit different reason.

If your base unit of measurement is 1 meter, then a 64 bit number actually has just enough precision to store 1000 light-years ;)


It is my understanding that the values become imprecise the larger the value gets though?

[quote name='Hodgman' timestamp='1297996526' post='4775674']
If your base unit of measurement is 1 meter, then a 64 bit number actually has just enough precision to store 1000 light-years ;)


It is my understanding that the values become imprecise the larger the value gets though?
[/quote]

That is true for floating point numbers, but I believe he was referring to using an integer. Those have exactly the same resolution for their entire range.
I'm doing this in my Galaxy Space Trade Simulator by using 3 different data types.

  1. Lightyears - Holds the value in lightyears for where the star is located. This is just a floating point number between 0.01 and 1020.01
  2. AU - This is the distance of the planet from the star. 1 AU = 149597870.7 km (distance from sun to earth). This is also a floating point value.
  3. Km - This is then used to describe objects/planets/ships etc that are closer than 1 AU. I use a floating point number for this too. Actually it only kicks in when under about 0.8 AU because the system I am using cannot reliably represent floating point numbers above 128 million. But the system works brilliantly for me and besides who wants to know that a star is 74,634,389,340,823,489,023,423 km away. The mind cant crasp that. It is much easier to see that something is 13 Lightyears away :)
In principle there is no good reason to have more resolution near the origin than anywhere else, so it makes sense to use fixed-point numbers. You can represent the whole galaxy in femtometers with 128-bit integers, which are easy to implement as two-digit numbers in base 2^64. To make things more human friendly you can use a 64+64 fixed-point representation, where the units are Kilometers.

You may find this table useful.

This topic is closed to new replies.

Advertisement