How do I convert celestial coordinates into galactic (and then cartesian) coordinates?

64 Views Asked by At

I'm attempting to make a map of the galaxy using desmos for sci-fi projects. Desmos can only really display points or shapes on the xy plane. But there's one issue that I haven't been able to figure out a solution for and searching hasn't helped matters, or I'm looking in the wrong places.

The galactic plane and the equator of the celestial sphere obviously aren't aligned, one is inclined 63° relative to the other if I recall the value correctly. What do I do to implement a variable so I can adjust the inclination of the plane? Preferably in a way so I can alternate between celestial and galactic with ease.

This is what I'm working with: $$ x = r × \cos(d) \sin(a) + x_0 \\ y = r × \cos(d) \cos(a) + y_0 \\ z = r × \sin(d) $$ Where $r$ is the radius or distance from the point of origin, $a$ is the right ascension, and $d$ is the declination. This is essentially equivalent to latitude, longitude, and altitude if I'm not mistaken. $x_0$ and $y_0$ are so I can offset the origin if I want, since celestial coordinates are centered on the observer (Earth) but galactic would make more sense to me to be centered on the galactic barycenter.

Thank you in advance