Using the Right Ascension and Declination values from the HYG Database from The Astronomy Nexus:

Right ascension is measured in hours and declination is measured in degrees.

1 - Convert right ascension and declination into degrees

float getAngle(float value, char units)
    if (units == 'h')
        // 15 degrees = 1 hour
        // 360/24 = 15

        return value * 15;
        return value;

When right ascension is inputted, the input will get multiplied by 15, because RA is measured in hours.

When declination is entered, the input value is returned, this is because Dec is already measured in degrees.

2 - Work out the vectors

Trigonometry diagram

Two isosceles triangles can be derived, one for the horizontal plane and another for the vertical plane. The angles are alpha and delta, right ascension and declination respectively. Using these angles and knowing that some of the distances are equal to the distance between the centre of the celestial sphere to the star, the following code should work.

Vector3 getVectors(float RA, float Dec)
    float x = distanceStars;
    float z = (2 * distanceStars * (Mathf.Sin((getAngle(RA, 'h'))/ 2)));
    float y = (2 * distanceStars * (Mathf.Sin((getAngle(Dec, 'd'))/ 2)));

    return new Vector3(x, y, z);

Unfortunately, my code doesn't seem to work as this is the output that I am getting:

Graphical output

As you can see, the stars (white dots) are not spreading out evenly around the Earth (which is the black sphere in the middle).

It would be great if someone could help me with this.

  • $\begingroup$ You're on the right track. Skip getAngle() in favor of math.stackexchange.com/questions/15323/… $\endgroup$ – user31179 Dec 20 '19 at 21:13
  • 1
    $\begingroup$ are you converting to radians anywhere? $\endgroup$ – user21 Dec 20 '19 at 21:18
  • $\begingroup$ What Barry said. Also, your formulae don't look like the usual polar to cartesian formulae. And you probably should be using double, not float. $\endgroup$ – PM 2Ring Dec 20 '19 at 21:31
  • 1
    $\begingroup$ I followed the link that @ebv commented, and now my program works perfectly $\endgroup$ – SidS Dec 20 '19 at 21:34
  • $\begingroup$ @barrycarter nope, not using radians $\endgroup$ – SidS Dec 20 '19 at 22:14

The stars should fit $r = \sqrt{x^2 + y^2 + z^2}$ but seem to be plotted in the $x = r$ plane instead.

Conventionally the x axis is at (α=0h, δ=0°), the y axis is at (α=6h, δ=0°), and the z axis is at δ=+90°.

Using right triangles instead of isosceles triangles,

right triangles

Then $h = r \cos \delta$, and $$\begin{align} x &= r \cos \delta \cos \alpha \\ y &= r \cos \delta \sin \alpha \\ z &= r \sin \delta \end{align}$$

Most math libraries use radians for angles. Passing angles in other units to trig functions may result in a celestial sphere covered somewhat evenly but incorrectly.

  • 1
    $\begingroup$ Used corrected the maths, moved from degrees to radians and now the stars are spread out even better an much more evenly, thanks! $\endgroup$ – SidS Dec 21 '19 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.