In addition to indexing stars and deep sky objects by position, as described in Spatial Indexing Part 1 and Part 2, I added an additional index for magnitude to allow objects to be rendered by brightness.

I wanted to provide a way of automatically adjusting the faintest object visible as the field-of-view is changed, so that a sensible number of objects are drawn, particularly for rendering an appropriate number of labels. In order to consider which algorithm to use, I thought it would be useful to analyse the datasets for stars and deep-sky objects. Figure 1 shows the distribution of magnitude values in the Hipparcos catalog, the majority of which (87%) are in the range from 6-10.

Figure 1. Hipparcos magnitude histogram

In order to automatically select the magnitude for a given field-of-view, I chose first to calculate its fraction of the maximum field-of-view (1), then square this to give the fraction of area of the maximum field-of-view (2).

fov_fraction = current_fov(1)
max_fov

area_fraction = fov_fraction^{2}(2)

I assume that the change in brightness is directly proportional to the change in area (3).

brightness_fraction = area_fraction(3)

Apparent magnitude is a logarithmic scale, with magnitude 6 stars defined as being one hundred times brighter than magnitude 1 stars. Hence each order of magnitude is ^{5}√100 (approximately 2.512, known as Pogson's Ratio) times brighter (4). I then convert this difference in brightness to a difference in magnitude (5).

brightness_fraction = 2.512^{magnitude_delta}(4)

magnitude_delta = log(brightness_fraction)(5)
log(2.512)

Finally I subtract the magnitude difference from the magntiude used at the maximum field-of-view (6). The maximum magnitude for labels can be set slightly below this figure (e.g. by some order of magnitude) so that items appear before their labels.

max_magnitude = 5.0 - magnitude_delta(6)

The maximum magnitude calculated in this manner is shown in Figure 2. Note that the graph tends to the magnitude at maximum field-of-view (magntide 5.00 at 100° in this case). For example, at a field-of-view of 10°, the area fraction of the maximum field of view is 0.01, hence the magnitude difference is -5.00, giving a calculated value of 5.00 + 5.00 = 10.00.

Figure 2. Automatic magnitude by field-of-view