Python Forum
Help with Maths (inverse squares)
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with Maths (inverse squares)
#1
Hello, hope this is the right forum for this question.

I'm generating star systems for a game and I could use some suggestions on the math.

I'm placing a star, then planets and using the distance (in pixels) to calculate surface temperature for the planets as follows:

self.surface_temp = round((1/self.dist**2)*star.temp, 3)
my outputs are like this:
RED DWARFS
PlanetTemp= 0.158 StarTemp= 4000 Dist= 159
PlanetTemp= 0.292 StarTemp= 4000 Dist= 117
PlanetTemp= 0.071 StarTemp= 4000 Dist= 238
Temp is in Kelvin and as you can see, these results are WAY too cold. (Pluto is about 44K)

Never been good at math, not sure if formula is right. If the formula is correct then I need to add a modifier of some sort, but I don't know if just using a fraction of the distance or multiplying the end result will throw of of the overall ratio.

Right now I'm using a screen that is 600X600 and distance is measured from the star at the center.

Any input would be nice. It's not going to break my game or anything, but if I use better math it will be nerdier.
Reply
#2
The formula doesn't seem correct. Here is another one (I don't know if it is correct either) where T**4 is proportional to 1/d**2 and there is a factor involving the luminosity of the star, the albedo of the planet and a universal constant, the Stefan-Boltzmann constant. There is a numerical example with the earth, so it should give you something more serious to work with.
Reply
#3
I woke up and did my best here:
self.surface_temp**4 = star.luminocity*(1-0.29)/((16*3.14)*(149,000,000,000**2)*(5.6703*(10**-8))     
print("PlanetTemp=",self.surface_temp,"StarTemp=", star.temp, "Dist=",self.dist)
Now for some reason I get a syntax error on the print statement, which i didn't touch.

I'm pretty sure I'm falling down the same rabbit hole as did the original programmers of Star Control 2(that I'm copying). I don't want this to take = programming_hours*(10**WTF). I have a game to write lol. I can use a stand-in formula until I get a working version of the game, then enhance.

It's really only so that my algorithm doesn't put "Ice Worlds" in a close orbit or "Scorching Rock Worlds" out past where Pluto might be. I'm still going to have to use a bunch of "If" statements to figure out the list of possible worlds that can exist in a particular location. Starcon2 doesn't need super accurate simulations, maybe I don't either. As long as the formula produces an inverse square relationship, I can put the displayed surface temperature into the class for each type of planet... I hope. Pray
Reply
#4
1 don't think 149,000,000,000 works the way you expect. Better use 149e9 or in recent pythons 149_000_000_000

Also self.surface_temp**4 = value is a syntax error. You can't assign to an arithmetic expression. Use
self.surface_temp = (value)**(1/4)
instead.
Reply
#5
Got it to run, but...

surface_temp = (((3.846*(10**26))*(1-0.29)))/((16*3.14)*(149e9**2)*(5.6703*(10**-8)))**(1/4)
Outputs
PlanetTemp= 1.7219105127308416
256 degrees Kelvin would be the result if I had it right. If I increase the luminosity then I get a smaller result too.

Thanks for the help, but I'm going to set this aside for now. I'd be embarrassed to tell you how much time I've spent on this. Wall I can change it later.
Reply
#6
The formula works for me
from math import pi

L = 3.846e26
a = 0.29
d = 149e9
sigma = 5.67073e-8

T = (L * (1 - a)/ (16 * pi * d**2 * sigma))**(1 / 4)
print("Temperature = {:.2f} K, or {:.2f} °C".format(T, T - 273.15))
Output:
Temperature = 256.30 K, or -16.85 °C
You can also avoid d**2 which can be very large by writing
T =  (L ** 0.25) * ((1 - a)/( pi * sigma)) ** 0.25 / (2 * d ** 0.5)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Least-squares fit multiple data sets multiverse22 1 2,226 Jun-06-2020, 01:38 AM
Last Post: Larz60+
  Differencing Time series and Inverse after Training donnertrud 0 4,075 May-27-2020, 06:11 AM
Last Post: donnertrud
  Inverse of singular matrix Divanova94 4 6,774 May-11-2019, 02:40 AM
Last Post: scidam
  Beta Inverse Function ankur2207 5 8,014 Jul-23-2018, 10:07 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020