<p>If you have a ray from an origin point <span class="math-container">$\mathbf{x}_0$</span>  with unit direction <span class="math-container">$|\mathbf{v}|=1$</span>,  <span class="math-container">$\mathbf{x}(s)=[x(s),y(s),z(s)]=\mathbf{x}_0+\mathbf{v}s$</span> and look at the density times distance <span class="math-container">$\rho(s)=\rho_0 e^{-R(\mathbf{x})/h_R}e^{-z(\mathbf{x})/h_z}s^2$</span> the derivative is
<span class="math-container">$\rho'(s) =\rho_0\left\{ [-e^{-R(\mathbf{x})/h_R}R'(\mathbf{x})/h_R]e^{-z(\mathbf{x})/h_z}s^2 + [-e^{-z(\mathbf{x})/h_z}z'(\mathbf{x})/h_z]e^{-R(\mathbf{x})/h_R}s^2 +[2s]e^{-R(\mathbf{x})/h_R}e^{-z(\mathbf{x})/h_z} \right\}$</span>
<span class="math-container">$=\rho(s)\left\{[-R'(\mathbf{x})/h_R]+[-z'(\mathbf{x})/h_z]+[2s]/s^2\right\}$</span>.</p>
<p>Now, <span class="math-container">$R'(s) = (x(s)v_x+y(s)v_y)/R(s)$</span> and <span class="math-container">$z'(s)=v_z$</span> so the criterion for a maximum or minium is <span class="math-container">$0 = -(x(s)v_x+y(s)v_y)/h_RR(s)-v_z/h_z + 2/s$</span> or <span class="math-container">$$\frac{2}{s} = \frac{[x_0v_x+y_0v_y] +[v_x^2 + v_y^2]s}{h_R\sqrt{(x_0+v_xs)^2+(y_0+v_ys)^2}}+\frac{v_z}{h_z}$$</span></p>
<p>I can't see how to simplify it further.
I think the right approach here is just to do a numeric solution using <a href="https://en.wikipedia.org/wiki/Golden-section_search" rel="nofollow noreferrer">golden section search</a> rather than do a lot of algebra that anyway ends with a root finding algorithm. Doing that also allows you to use any stellar density model.</p>

CC BY-SA 4.0
2020-08-04T15:00:10.427Z
2020-08-04T15:00:10.427Z
Anders Sandberg
<p>The density of stars drops off exponentially from the center of the galaxy and can be approximated as follows using a cylindrical coordinate system:</p>
<p><span class="math-container">$$ \rho(R, z) = \rho_0 \exp \frac{-R}{h_R} \ \exp  \frac{-|z|}{h_z} $$</span></p>
<p><a href="https://i.sstatic.net/pGDJn.png" rel="nofollow noreferrer">screenshot</a></p>
<p>The radial scale length and height of the thin disk are ~ 3000 pc and ~ 200 pc respectively. At the moment rho_0 will just be taken as 1. We observe at a given l and b of 90 and 15 respectively using the galactic coordinate system (just look at l and b for now, the rest are annotations I added that I will describe shortly). The galactic coordinate system uses spherical coordinates:</p>
<p><a href="https://i.sstatic.net/Y0kMt.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Y0kMt.png" alt="enter image description here" /></a></p>
<p>We want to know where the density of stars peak along at given LOS (from Earth) per 1 sq degree at a given l and b. There are 41253 sq degrees in the entire sky, so 1/41253 will be the fraction we want to multiply the density equation by. However, we must also consider how the volume element changes by distance along the given LOS, so we need to also multiply rho and 1/41253 by this change in volume. This volume element can be represented by <span class="math-container">$4 \pi r^2 dr$</span> (the surface area of the sphere and the small change in the distance along the LOS). We are almost done but need a way to transform between coordinate systems by relating galactic coordinates to distance r and R (as seen in the diagram above). Mathematically, they are related as follows (Eq. 3 in <a href="http://articles.adsabs.harvard.edu/pdf/1990AJ....100.1191M" rel="nofollow noreferrer">Where Does the Disk Stop and the Halo Begin? Kinematics in a Rotation Field</a> Morrison, Flynn and Freeman 1990 Ast. J. 100 (4) 1191-1222):</p>
<p><span class="math-container">$$ r^2 = R_☉^2 + R^2 - 2 R R_☉ \cos b \cos l $$</span></p>
<p><a href="https://i.sstatic.net/5z20J.png" rel="nofollow noreferrer">screenshot</a></p>
<p>So, for a given r (distance from star or LOS to sun), l and b, we can find R (the distance from the G.C. to the star or LOS). This is in cylindrical coordinates, so we need to use cos(b)R and sin(b)R to find R and z in the <em><strong>density equation above</strong></em> (note these are different r's). The volume element needs to be the LOS from Earth, which corresponds is the R in the diagram and equation for the paper (for the given l,b, and r). Putting this all together, I have the following code. Please let me know if this attempt seems reasonable, or if not, where I went wrong.</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt

C=8500 #Distance from center of galaxy to sun (R_sun_

#Galactic Coordinates
b=np.deg2rad(15) #above plane
l=np.deg2rad(90) 

#Scale heights for the thin disk
h_R=3000
h_z=200

nsqdeg_in_sky=41253 #square deg in whole sky


#R: Distance from star to sun
R=np.arange(0,15000,1)

#distance from star to G.C.
#r: distance from star to G.C. kpc
r=np.sqrt(C**2+R**2-2*R*C*np.cos(b)*np.cos(l))
print(r)

#Spherical Galactic Coordinates to cylindrical coordinates
#z component of R
R_z=np.sin(b)*r
#r component of R
R_r=np.cos(b)*r


#density equation describing thin disk
rho_thin=np.e**(-R_r/h_R)*np.e**(-np.abs(R_z)/h_z)

#desnity equation combining volume element and portion of sky
N_thin = (1./nsqdeg_in_sky)*(4*np.pi)*R*R*rho_thin

plt.title(&quot;Number of stars per 1 square degree&quot;)
plt.plot(R,N_thin,color='blue',label='thin')
plt.legend(loc='best')
plt.xlabel(r'<span class="math-container">$distance$</span> [pc]')
plt.ylabel(r'<span class="math-container">$N_\ast$</span> [pc<span class="math-container">$^{-1}$</span>]')
</code></pre>
<p>edit to add plot for given l and b above:
<a href="https://i.sstatic.net/uZtQB.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/uZtQB.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2020-08-02T22:44:35.253Z
I converted the screenshots of equations to [MathJax](https://math.meta.stackexchange.com/q/5020/284619) and mad a few other format changes Please feel free to edit further.
uhoh
CC BY-SA 4.0
2020-08-03T07:10:53.770Z
This plot cannot be what you seek if the star has a high elevation over the disk, since the starting density near the sun is near maximal for this$R$, declining with $z$ over the disk. Given the monotonic decline of density with $R$ and $z$ the maximum along a ray will essentially be the closest point to the centre.
Anders Sandberg
CC BY-SA 4.0
2020-08-03T08:39:01.150Z
@Anders Sandberg You're seeing more stars in your FOV as you look out because of the volume element. That's an important part to consider. It's not just a function of density.
Astroturf
CC BY-SA 4.0
2020-08-03T09:10:07.450Z
We are only interested in where contribution from the thin disk stars peak.
Astroturf
<star><observational-astronomy><galaxy><milky-way><disk>
How to approximate the distance at which the thin disk peaks along a given LOS from Earth for a given galactic coordinate per 1 sq deg?
Astroturf
# How to approximate the distance at which the thin disk peaks along a given LOS from Earth for a given galactic coordinate per 1 sq deg?

(Asked by: username_0 on 2020-08-02)

The density of stars drops off exponentially from the center of the galaxy and can be approximated as follows using a cylindrical coordinate system:
$$ \rho(R, z) = \rho_0 \exp \frac{-R}{h_R} \ \exp  \frac{-|z|}{h_z} $$
screenshot
The radial scale length and height of the thin disk are ~ 3000 pc and ~ 200 pc respectively. At the moment rho_0 will just be taken as 1. We observe at a given l and b of 90 and 15 respectively using the galactic coordinate system (just look at l and b for now, the rest are annotations I added that I will describe shortly). The galactic coordinate system uses spherical coordinates:

We want to know where the density of stars peak along at given LOS (from Earth) per 1 sq degree at a given l and b. There are 41253 sq degrees in the entire sky, so 1/41253 will be the fraction we want to multiply the density equation by. However, we must also consider how the volume element changes by distance along the given LOS, so we need to also multiply rho and 1/41253 by this change in volume. This volume element can be represented by $4 \pi r^2 dr$ (the surface area of the sphere and the small change in the distance along the LOS). We are almost done but need a way to transform between coordinate systems by relating galactic coordinates to distance r and R (as seen in the diagram above). Mathematically, they are related as follows (Eq. 3 in Where Does the Disk Stop and the Halo Begin? Kinematics in a Rotation Field Morrison, Flynn and Freeman 1990 Ast. J. 100 (4) 1191-1222):
$$ r^2 = R_☉^2 + R^2 - 2 R R_☉ \cos b \cos l $$
screenshot
So, for a given r (distance from star or LOS to sun), l and b, we can find R (the distance from the G.C. to the star or LOS). This is in cylindrical coordinates, so we need to use cos(b)R and sin(b)R to find R and z in the density equation above (note these are different r's). The volume element needs to be the LOS from Earth, which corresponds is the R in the diagram and equation for the paper (for the given l,b, and r). Putting this all together, I have the following code. Please let me know if this attempt seems reasonable, or if not, where I went wrong.
import numpy as np
import matplotlib.pyplot as plt

C=8500 #Distance from center of galaxy to sun (R_sun_

#Galactic Coordinates
b=np.deg2rad(15) #above plane
l=np.deg2rad(90) 

#Scale heights for the thin disk
h_R=3000
h_z=200

nsqdeg_in_sky=41253 #square deg in whole sky


#R: Distance from star to sun
R=np.arange(0,15000,1)

#distance from star to G.C.
#r: distance from star to G.C. kpc
r=np.sqrt(C**2+R**2-2*R*C*np.cos(b)*np.cos(l))
print(r)

#Spherical Galactic Coordinates to cylindrical coordinates
#z component of R
R_z=np.sin(b)*r
#r component of R
R_r=np.cos(b)*r


#density equation describing thin disk
rho_thin=np.e**(-R_r/h_R)*np.e**(-np.abs(R_z)/h_z)

#desnity equation combining volume element and portion of sky
N_thin = (1./nsqdeg_in_sky)*(4*np.pi)*R*R*rho_thin

plt.title("Number of stars per 1 square degree")
plt.plot(R,N_thin,color='blue',label='thin')
plt.legend(loc='best')
plt.xlabel(r'$distance$ [pc]')
plt.ylabel(r'$N_\ast$ [pc$^{-1}$]')

edit to add plot for given l and b above:

**Tags:** star, observational-astronomy, galaxy, milky-way, disk

> **Comments:**
> **username_1**: I converted the screenshots of equations to [MathJax](https://math.meta.stackexchange.com/q/5020/284619) and mad a few other format changes Please feel free to edit further.  
> **username_2**: This plot cannot be what you seek if the star has a high elevation over the disk, since the starting density near the sun is near maximal for this$R$, declining with $z$ over the disk. Given the monotonic decline of density with $R$ and $z$ the maximum along a ray will essentially be the closest point to the centre.  
> **username_0**: @username_2 You're seeing more stars in your FOV as you look out because of the volume element. That's an important part to consider. It's not just a function of density.  
> **username_0**: We are only interested in where contribution from the thin disk stars peak.  

---

## 1 answers

### Answer by username_2 on 2020-08-04. Score: -1

If you have a ray from an origin point $\mathbf{x}\_0$ with unit direction $|\mathbf{v}|=1$, $\mathbf{x}(s)=[x(s),y(s),z(s)]=\mathbf{x}\_0+\mathbf{v}s$ and look at the density times distance $\rho(s)=\rho\_0 e^{-R(\mathbf{x})/h\_R}e^{-z(\mathbf{x})/h\_z}s^2$ the derivative is
$\rho'(s) =\rho\_0\left\{ [-e^{-R(\mathbf{x})/h\_R}R'(\mathbf{x})/h\_R]e^{-z(\mathbf{x})/h\_z}s^2 + [-e^{-z(\mathbf{x})/h\_z}z'(\mathbf{x})/h\_z]e^{-R(\mathbf{x})/h\_R}s^2 +[2s]e^{-R(\mathbf{x})/h\_R}e^{-z(\mathbf{x})/h\_z} \right\}$
$=\rho(s)\left\{[-R'(\mathbf{x})/h\_R]+[-z'(\mathbf{x})/h\_z]+[2s]/s^2\right\}$.

Now, $R'(s) = (x(s)v\_x+y(s)v\_y)/R(s)$ and $z'(s)=v\_z$ so the criterion for a maximum or minium is $0 = -(x(s)v\_x+y(s)v\_y)/h\_RR(s)-v\_z/h\_z + 2/s$ or $$\frac{2}{s} = \frac{[x\_0v\_x+y\_0v\_y] +[v\_x^2 + v\_y^2]s}{h\_R\sqrt{(x\_0+v\_xs)^2+(y\_0+v\_ys)^2}}+\frac{v\_z}{h\_z}$$

I can't see how to simplify it further.
I think the right approach here is just to do a numeric solution using [golden section search](https://en.wikipedia.org/wiki/Golden-section_search) rather than do a lot of algebra that anyway ends with a root finding algorithm. Doing that also allows you to use any stellar density model.


---

