<p>Using the notation in your diagram.</p>
<p><span class="math-container">$$x = \cos (a) \cos (A)$$</span>
<span class="math-container">$$ y = \cos (a) \sin (A)$$</span>
<span class="math-container">$$z = \sin (a)$$</span></p>
<p>In most computer codes, all the angles should be in radians, where <span class="math-container">$\theta_{\rm rad} = \theta_{\rm deg} \times \pi/180$</span>.</p>
<p>Note that if comparing with other sources, you do have to pay attention to how the angles are defined. For instance, the altitude is <span class="math-container">$90^{\circ} -$</span> the usual polar angle in spherical polar coordinates.</p>

CC BY-SA 4.0
2023-03-17T19:55:36.403Z
I think it is $x = \sin (a) \cos (A)$ and $y = \sin (a) \sin (A)$. At least, this is how this formula appears in my Calculus book (and also in Wikipedia).
VansFannel
CC BY-SA 4.0
2023-03-17T23:33:51.820Z
@VansFannel I don't think so.
ProfRob
CC BY-SA 4.0
2023-03-19T15:12:40.573Z
Well, you can believe whatever you want. Just look it up on Wikipedia and check what I say.
VansFannel
CC BY-SA 4.0
2023-03-19T15:29:05.740Z
@VansFannel put the link here and I might. You might be confused with polar coordinates, where the expression would be $x = \sin\theta \cos\phi$ etc
ProfRob
CC BY-SA 4.0
2023-03-26T09:06:07.797Z
https://openstax.org/books/c%C3%A1lculo-volumen-3/pages/2-7-coordenadas-cilindricas-y-esfericas and https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates @ProfRob
VansFannel
CC BY-SA 4.0
2023-03-26T09:34:30.043Z
@VansFannel both of those sources are in perfect agreement with my answer. You DO have to pay attention to how the angles are defined.
ProfRob
CC BY-SA 4.0
2023-03-26T17:31:00.143Z
Both sets of equations can be correct depending on how the angles are expressed.  But the way profrob presented them is the way they're most often used in astronomy today.
Greg Miller
CC BY-SA 4.0
2023-03-26T18:04:45.737Z
@GregMiller only one of them is correct for the angles **as defined by the OP in their own question!**
ProfRob
CC BY-SA 4.0
2023-05-25T05:24:35.007Z
I can’t promise it will solve your issue, but I had a similar problem once, and to my surprise, I solved it by using, for example, y and z instead of x and y, or x and z, or any other such combination.
Pierre Paquette
CC BY-SA 4.0
2023-02-18T09:35:39.640Z
2023-03-26T09:38:09.323Z
2023-03-26T09:38:09.323Z
ProfRob
<p>I'm developing a planetarium software using the Hipparcos Catalogue. I have also implemented all the formulas of the book: &quot;<a href="https://www.cambridge.org/gb/academic/subjects/physics/amateur-and-popular-astronomy/practical-astronomy-your-calculator-or-spreadsheet-4th-edition?format=PB&amp;isbn=9781108436076" rel="nofollow noreferrer">Practical astronomy with your Calculator and Spreadsheet</a>&quot;.</p>
<p>With these formulas, I'm trying to draw the star inside a 3D space using its <em>Horizontal Coordinates</em>. To do it, I'm using these calculations to get its <em>X, Y</em> and <em>Z</em> coordinates:</p>
<p><span class="math-container">$$X = \cos(Azimuth)$$</span>
<span class="math-container">$$Y = \cos(Altitude)$$</span>
<span class="math-container">$$Z = \sin(Altitude)$$</span></p>
<p>I'm trying to get the coordinate of point X in this image:
<a href="https://i.sstatic.net/nDPqi.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/nDPqi.png" alt="enter image description here" /></a></p>
<p><span class="math-container">$a$</span> is altitude.<br/>
<span class="math-container">$A$</span> is azimuth.</p>
<p><span class="math-container">$Azimuth$</span> and <span class="math-container">$Altitude$</span> are in decimal degrees.</p>
<p>Maybe, I have to use it in radians, or maybe it is the sine instead of cosine. Anyway, this is what I get:</p>
<p><a href="https://i.sstatic.net/GQFWo.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GQFWo.jpg" alt="enter image description here" /></a></p>
<p>The stars aren't drawn as a sphere.</p>
<p>How can I fix this problem?</p>

CC BY-SA 4.0
2023-02-18T08:32:56.123Z
I can't tell from your question what you are trying to do. Almost all computer languages expect the arguments of trigonometry functions to be in radians though.
ProfRob
CC BY-SA 4.0
2023-02-18T08:42:51.290Z
Your equations don't make sense. And you didn't tell us what convention you're using for X, Y, Z. Have you seen https://en.wikipedia.org/wiki/Spherical_coordinate_system ?
PM 2Ring
CC BY-SA 4.0
2023-02-18T09:05:03.043Z
I have updated my question.
VansFannel
<mathematics><software>
Get (X, Y, Z) coordinates from Horizontal Coordinates
VansFannel
# Get (X, Y, Z) coordinates from Horizontal Coordinates

(Asked by: username_0 on 2023-02-18)

I'm developing a planetarium software using the Hipparcos Catalogue. I have also implemented all the formulas of the book: "[Practical astronomy with your Calculator and Spreadsheet](https://www.cambridge.org/gb/academic/subjects/physics/amateur-and-popular-astronomy/practical-astronomy-your-calculator-or-spreadsheet-4th-edition?format=PB&isbn=9781108436076)".

With these formulas, I'm trying to draw the star inside a 3D space using its *Horizontal Coordinates*. To do it, I'm using these calculations to get its *X, Y* and *Z* coordinates:

$$X = \cos(Azimuth)$$
$$Y = \cos(Altitude)$$
$$Z = \sin(Altitude)$$

I'm trying to get the coordinate of point X in this image:
[![enter image description here](https://i.sstatic.net/nDPqi.png)](https://i.sstatic.net/nDPqi.png)

$a$ is altitude.  
$A$ is azimuth.

$Azimuth$ and $Altitude$ are in decimal degrees.

Maybe, I have to use it in radians, or maybe it is the sine instead of cosine. Anyway, this is what I get:

[![enter image description here](https://i.sstatic.net/GQFWo.jpg)](https://i.sstatic.net/GQFWo.jpg)

The stars aren't drawn as a sphere.

How can I fix this problem?

**Tags:** mathematics, software
> **Comments:**
> **username_1**: I can't tell from your question what you are trying to do. Almost all computer languages expect the arguments of trigonometry functions to be in radians though.  
> **username_2**: Your equations don't make sense. And you didn't tell us what convention you're using for X, Y, Z. Have you seen https://en.wikipedia.org/wiki/Spherical_coordinate_system ?  
> **username_0**: I have updated my question.  

---

## 1 answers

### Answer by username_1 on 2023-02-18. Score: 3 | Accepted answer

Using the notation in your diagram.

$$x = \cos (a) \cos (A)$$
$$ y = \cos (a) \sin (A)$$
$$z = \sin (a)$$

In most computer codes, all the angles should be in radians, where $\theta\_{\rm rad} = \theta\_{\rm deg} \times \pi/180$.

Note that if comparing with other sources, you do have to pay attention to how the angles are defined. For instance, the altitude is $90^{\circ} -$ the usual polar angle in spherical polar coordinates.

> **Comments:**
> **username_0**: I think it is $x = \sin (a) \cos (A)$ and $y = \sin (a) \sin (A)$. At least, this is how this formula appears in my Calculus book (and also in Wikipedia).  
> **username_1**: @VansFannel I don't think so.  
> **username_0**: Well, you can believe whatever you want. Just look it up on Wikipedia and check what I say.  
> **username_1**: @VansFannel put the link here and I might. You might be confused with polar coordinates, where the expression would be $x = \sin\theta \cos\phi$ etc  
> **username_0**: https://openstax.org/books/c%C3%A1lculo-volumen-3/pages/2-7-coordenadas-cilindricas-y-esfericas and https://en.wikipedia.org/wiki/Spherical_coordinate_system#Cartesian_coordinates @ProfRob  
> **username_1**: @VansFannel both of those sources are in perfect agreement with my answer. You DO have to pay attention to how the angles are defined.  
> **username_3**: Both sets of equations can be correct depending on how the angles are expressed.  But the way profrob presented them is the way they're most often used in astronomy today.  
> **username_1**: @GregMiller only one of them is correct for the angles **as defined by the OP in their own question!**  
> **username_4**: I can’t promise it will solve your issue, but I had a similar problem once, and to my surprise, I solved it by using, for example, y and z instead of x and y, or x and z, or any other such combination.  

---

