<p>Cool aim. I've been intermittently working on a similar program, feel free to use any pieces you like. </p>

<p>It's hosted at:
<a href="http://thestarsbetween.com/maker/builder?stellar=o&amp;rand=1233" rel="nofollow">http://thestarsbetween.com/maker/builder?stellar=o&amp;rand=1233</a></p>

<p>And the code is shared open source at:
<a href="https://github.com/jaycrossler/procyon" rel="nofollow">https://github.com/jaycrossler/procyon</a></p>

CC BY-SA 3.0
2014-07-14T16:23:11.160Z
Thank you very much, I'll have a look and see if there's anything I can use (will give credit too).
MMM
CC BY-SA 3.0
2014-07-14T18:05:29.870Z
Awesome, let me know if it's useful. I keep wanting to get back to add more to it, so your interest might spark me to add the other features I've been thinking of.
JayCrossler
CC BY-SA 3.0
2014-07-14T03:17:39.443Z
2014-07-14T03:17:39.443Z
JayCrossler
<p>This is a tricky question, not immediate. </p>

<p>If we talk about Main Sequence stars, yes, you can constrain your fictional star by two parameters. The crucial parameters in the diagram, as you said, are the mass and the radius. This is why the HR diagram well represents the stellar population with two axis. Of course, for your scope, we need to do some assumptions. For example, the metallicity, that for your purposes can be fixed as the Solar one. Or, that the initial mass is already in a condition to contract.</p>

<p>You can see it this way: the luminosity is connected with the radius (because it depends on the irradiating surface), while the temperature is connected with the mass (the more is the mass, the more is the pressure at the center of the star).</p>

<p>If you have $L \sim RT$ and $L \sim M$, then you also have $RT \sim M$. 
The degeneracy from one parameter can be overcame if you have your reference star (the Sun), which allows you to trace isoradii lines on the HR diagram. See here for example:
<img src="https://i.sstatic.net/0sS3I.gif" alt="enter image description here">
Or, that is equivalent, you can express your first equation (Stefan-Boltzmann), in Solar units as well (<a href="http://abyss.uoregon.edu/~js/ast122/lectures/lec11.html" rel="nofollow noreferrer">as shown here</a>).</p>

<p>Try it out just by your self: choose a mass, or observationally speaking, choose a luminosity. Then <a href="http://www.kcvs.ca/martin/astro/au/unit4/85/chp8_5.htm" rel="nofollow noreferrer">trace your line on the HR diagram</a>, and find your star. That star has a defined temperature (spectral class), Mass and Radius as well.</p>

<p>If you need the exact equations, feel free to ask please.</p>

<p>Nice aim, anyway. Have fun!</p>

CC BY-SA 3.0
2014-07-10T09:04:54.387Z
Thank you very much for your answer and providing links to interesting resources. In particular, the H-R Diagram Explorer found [here](http://www.kcvs.ca/martin/astro/au/unit4/85/chp8_5.htm) is pretty interesting as it nicely shows the relation between the luminosity, temperature and radius of the star. I will continue with my research based on your suggestions, and wait for a bit to see if other people have some other suggestions.
MMM
CC BY-SA 3.0
2014-07-14T19:41:09.867Z
I have found a [webpage](http://www.schoolphysics.co.uk/age16-19/Astrophysics/text/Mass_luminosity_relation/index.html) claiming that main sequence stars have an average density of 1600 kg/m³, is this an accurate approximation? This would mean I could derive the mass from the radius of the star.
MMM
CC BY-SA 3.0
2014-07-15T22:24:56.040Z
Ok so I've managed to work out an algorithm that generates stars very close to the HR diagram line by using a density between 1400kg/m³ and 1600kg/m³. What's great is that I simply need to choose a random mass of my star (at the moment it's between 0.5M☉ and 15M☉) and all the formulas work out the rest. Many thanks again for your help.
MMM
CC BY-SA 3.0
2014-07-16T01:57:19.183Z
@MMM, you are very welcome! Good luck :)
Py-ser
CC BY-SA 3.0
2014-07-10T03:48:42.967Z
2014-07-11T09:31:21.807Z
2014-07-11T09:31:21.807Z
Py-ser
<p>I am working on a (personal) programming project, part of which involves generating random stars and their parameters.</p>

<p>In order to create a procedurally generated star, I want to randomly select as few parameter values as possible, and then extrapolate the rest using formulas.</p>

<p>For instance by interpreting the <a href="https://en.wikipedia.org/wiki/Stefan%E2%80%93Boltzmann_law" rel="noreferrer">Stefan-Boltzmann law</a> I can derive the star's luminosity based on the surface temperature and the star's radius:</p>

<p>$$
L = 4 \pi R^2 \sigma T_{e}^4
$$</p>

<p>There are however other parameters that I would like to generate, such as the mass of the star. What seems to be able to help me is the <a href="https://en.wikipedia.org/wiki/Mass%E2%80%93luminosity_relation" rel="noreferrer">mass-luminosity relation</a>:</p>

<p>$$
\frac{L}{L_{\odot}} = \left(\frac{M}{M_{\odot}}\right)^a
$$</p>

<p>By knowing $a$ (based on my randomly selected mass) it seems that I can derive the star's luminosity. By glancing at the <a href="https://en.wikipedia.org/wiki/Hertzsprung%E2%80%93Russell_diagram" rel="noreferrer">Hertzsprung–Russell diagram</a> (e.g. <a href="https://en.wikipedia.org/wiki/Hertzsprung%E2%80%93Russell_diagram#mediaviewer/File%3aHertzsprung-Russel_StarData.png" rel="noreferrer">this one</a>) I can see that I can perhaps somehow calculate the radius of the star, but I'm not entirely sure how.</p>

<p>There is an existing star "generator" which can be found <a href="http://web.archive.org/web/20030218125318/www.geocities.com/Area51/Corridor/8611/mseqstar.htm" rel="noreferrer">here</a>, however this one interpolates existing data using logarithms.</p>

<p>My full question would be, is there a way to "generate" a "regular", main sequence star, starting from one or two parameters and extrapolating the rest using formulas? Is there a sensible relation between the mass of the star and its radius that can be used to generate a "realistic" star? Or would most parameters need to be interpolated from existing data?</p>

<star>
Accurate way to programmatically generate a main sequence star?
MMM
# Accurate way to programmatically generate a main sequence star?

(Asked by: username_0 on 2014-07-09)

I am working on a (personal) programming project, part of which involves generating random stars and their parameters.

In order to create a procedurally generated star, I want to randomly select as few parameter values as possible, and then extrapolate the rest using formulas.

For instance by interpreting the [Stefan-Boltzmann law](https://en.wikipedia.org/wiki/Stefan%E2%80%93Boltzmann_law) I can derive the star's luminosity based on the surface temperature and the star's radius:

$$
L = 4 \pi R^2 \sigma T\_{e}^4
$$

There are however other parameters that I would like to generate, such as the mass of the star. What seems to be able to help me is the [mass-luminosity relation](https://en.wikipedia.org/wiki/Mass%E2%80%93luminosity_relation):

$$
\frac{L}{L\_{\odot}} = \left(\frac{M}{M\_{\odot}}\right)^a
$$

By knowing $a$ (based on my randomly selected mass) it seems that I can derive the star's luminosity. By glancing at the [Hertzsprung–Russell diagram](https://en.wikipedia.org/wiki/Hertzsprung%E2%80%93Russell_diagram) (e.g. [this one](https://en.wikipedia.org/wiki/Hertzsprung%E2%80%93Russell_diagram#mediaviewer/File%3aHertzsprung-Russel_StarData.png)) I can see that I can perhaps somehow calculate the radius of the star, but I'm not entirely sure how.

There is an existing star "generator" which can be found [here](http://web.archive.org/web/20030218125318/www.geocities.com/Area51/Corridor/8611/mseqstar.htm), however this one interpolates existing data using logarithms.

My full question would be, is there a way to "generate" a "regular", main sequence star, starting from one or two parameters and extrapolating the rest using formulas? Is there a sensible relation between the mass of the star and its radius that can be used to generate a "realistic" star? Or would most parameters need to be interpolated from existing data?

**Tags:** star


---

## 2 answers

### Answer by username_2 on 2014-07-10. Score: 4 | Accepted answer

This is a tricky question, not immediate.

If we talk about Main Sequence stars, yes, you can constrain your fictional star by two parameters. The crucial parameters in the diagram, as you said, are the mass and the radius. This is why the HR diagram well represents the stellar population with two axis. Of course, for your scope, we need to do some assumptions. For example, the metallicity, that for your purposes can be fixed as the Solar one. Or, that the initial mass is already in a condition to contract.

You can see it this way: the luminosity is connected with the radius (because it depends on the irradiating surface), while the temperature is connected with the mass (the more is the mass, the more is the pressure at the center of the star).

If you have $L \sim RT$ and $L \sim M$, then you also have $RT \sim M$.
The degeneracy from one parameter can be overcame if you have your reference star (the Sun), which allows you to trace isoradii lines on the HR diagram. See here for example:
![enter image description here](https://i.sstatic.net/0sS3I.gif)
Or, that is equivalent, you can express your first equation (Stefan-Boltzmann), in Solar units as well ([as shown here](http://abyss.uoregon.edu/~js/ast122/lectures/lec11.html)).

Try it out just by your self: choose a mass, or observationally speaking, choose a luminosity. Then [trace your line on the HR diagram](http://www.kcvs.ca/martin/astro/au/unit4/85/chp8_5.htm), and find your star. That star has a defined temperature (spectral class), Mass and Radius as well.

If you need the exact equations, feel free to ask please.

Nice aim, anyway. Have fun!

> **Comments:**
> **username_0**: Thank you very much for your answer and providing links to interesting resources. In particular, the H-R Diagram Explorer found [here](http://www.kcvs.ca/martin/astro/au/unit4/85/chp8_5.htm) is pretty interesting as it nicely shows the relation between the luminosity, temperature and radius of the star. I will continue with my research based on your suggestions, and wait for a bit to see if other people have some other suggestions.  
> **username_0**: I have found a [webpage](http://www.schoolphysics.co.uk/age16-19/Astrophysics/text/Mass_luminosity_relation/index.html) claiming that main sequence stars have an average density of 1600 kg/m³, is this an accurate approximation? This would mean I could derive the mass from the radius of the star.  
> **username_0**: Ok so I've managed to work out an algorithm that generates stars very close to the HR diagram line by using a density between 1400kg/m³ and 1600kg/m³. What's great is that I simply need to choose a random mass of my star (at the moment it's between 0.5M☉ and 15M☉) and all the formulas work out the rest. Many thanks again for your help.  
> **username_2**: @username_0, you are very welcome! Good luck :)  

---

### Answer by username_1 on 2014-07-14. Score: 2

Cool aim. I've been intermittently working on a similar program, feel free to use any pieces you like.

It's hosted at:
<http://thestarsbetween.com/maker/builder?stellar=o&rand=1233>

And the code is shared open source at:
<https://github.com/username_1/procyon>

> **Comments:**
> **username_0**: Thank you very much, I'll have a look and see if there's anything I can use (will give credit too).  
> **username_1**: Awesome, let me know if it's useful. I keep wanting to get back to add more to it, so your interest might spark me to add the other features I've been thinking of.  

---

