# Help with Converting Right Ascension and Declination into 3D Vectors

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;
}
else
{
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

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:

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.

• You're on the right track. Skip getAngle() in favor of math.stackexchange.com/questions/15323/…
– user31179
Dec 20, 2019 at 21:13
• are you converting to radians anywhere?
– user21
Dec 20, 2019 at 21:18
• 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. Dec 20, 2019 at 21:31
• I followed the link that @ebv commented, and now my program works perfectly
– SidS
Dec 20, 2019 at 21:34
• @barrycarter nope, not using radians
– SidS
Dec 20, 2019 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,

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.

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