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.
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 (&alpha;=0h, &delta;=0&deg;),
the y axis is at (&alpha;=6h, &delta;=0&deg;),
and the z axis is at &delta;=+90&deg;.

Using right triangles instead of isosceles triangles,



Then $h = r \cos \delta$, and
$$\begin{align}
x &amp;= r \cos \delta \cos \alpha \\
y &amp;= r \cos \delta \sin \alpha \\
z &amp;= 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.