# Drawing stars in a 3D space

I'm using the Galactic Coordinates to draw stars in a 3D space, but I don't know how to do it.

In the book "Practical Astronomy with your Calculator or Spreadsheet" I've found this:

Where:
S: the Sun.
G: the centre of the Galaxy.
X: a star which not lie in the galactic plane.
l: galactic longitude.
b: galactic latitude.

If I know S, G, l and b. How can I know the (x, y, z) coordinates of the star X?

Probably I need to know the distance between S and X.

• Yes, you will indeed need to know the distance between S and X. Multiple star catalogues are available on the Internet which can provide you with this information. Keep in mind, though, that astronomical distances can only be measured indirectly, and there is an error margin to the measurement, so you may get slightly different values in different catalogues. Commented Mar 27, 2023 at 2:43
• You can use the "parallax" field of a star catalog, and the RA/Dec to compute the XYZ coordinates relative to the Solar System Barycenter. Example is here: celestialprogramming.com/snippets/starxyz.html . Then shift the results so the galactic center is 0,0,0. Commented Mar 27, 2023 at 5:08
• @GregMiller Thanks for you comment. Now, I'm using Hipparcos Catalogue, but I've been checking the Gaia project to look for a field called "distance". Commented Mar 27, 2023 at 7:06

You can't without knowing the distance to the star, $$d$$.
Once you have that then, depending on exactly how the $$x, y, z$$ axes are defined: \begin{align} x &= d \cos(b)\cos(l) \\ y &= d \cos(b) \sin(l) \\ z &= d \sin(b)\ , \end{align} where I have used a usual convention that $$x$$ is measured towards the Galactic centre from Earth, $$y$$ is measured at right angles to this but in the Galactic plane and $$z$$ is perpendicular to the Galactic plane.
If you wish to have the origin at the Galactic centre then simply subtract the $$x$$ coordinate of the Galactic centre from $$x$$.