Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- //This class contains utilities for heavenly body calculations
- public class HeavenlyUtil {
- private const double stefanBoltzmanConstant = 0.000000560373d;
- private const double PI = 3.14159265359d;
- private const double GM = 0.00000000006740831d;
- private const double sunTemp = 5778;
- private const double sunMag = 4.83;
- public static Star buildStar(Star star)
- {
- //assuming magnitude and temperature are already defined.
- star.solarLuminosity = getSolarLuminosity(star.absoluteMagnitude);
- star.solarRadius = getSolarRadius(star.absoluteMagnitude, star.surfaceTemperature);
- star.solarMass = getSolarMass(star.solarLuminosity);
- star.surfaceGravity = getSurfaceGravity(star.solarRadius, star.solarMass);
- star.escapeVelocity = getEscapeVelocity(star.solarRadius, star.solarMass);
- star.circumfrence = getCircumfrence(star.solarRadius);
- star.volume = getSolarVolume(star.solarRadius);
- star.averageDensity = getDensity(star.solarMass, star.volume);
- star.criticalRotationalVelocity = getCriticalVelocityOfRotation(star.solarMass, star.solarRadius);
- star.rotationalVelocity = generateRotation(star.criticalRotationalVelocity);
- bool giant = false;
- if (star.yerkesClass != "" && star.yerkesClass != "V" && star.yerkesClass != "sd")
- {
- giant = true;
- }
- star.lifespan = getLifespan(giant, star.solarMass);
- star.age = generateAge(star.lifespan);
- return star;
- }
- public static void printStarInfo(Star star)
- {
- Debug.Log(star.fullClassification + " TEMP: " + star.surfaceTemperature + " AM: " + star.absoluteMagnitude + " L: " + star.solarLuminosity + " Radius: " + star.solarRadius + " Mass: " + star.solarMass + " surfaceGrav: " + star.surfaceGravity + " escapeVelocity: " + star.escapeVelocity + " rot: " + star.rotationalVelocity + " critrot: " + star.criticalRotationalVelocity + " density: " + star.averageDensity + " vol: " + star.volume + " lifespan: " + star.lifespan + " age: " + star.age);
- }
- public static void csvStarInfo(Star star)
- {
- DebugDataWriter.AppendString(star.fullClassification + "," + star.surfaceTemperature + "," + star.absoluteMagnitude + "," + star.solarLuminosity + "," + star.solarRadius + "," + star.solarMass + "," + star.surfaceGravity + "," + star.escapeVelocity + "," + star.rotationalVelocity + "," + star.criticalRotationalVelocity + "," + star.averageDensity + "," + star.volume + "," + star.lifespan + "," + star.age + ",");
- }
- public static void csvStarTitle()
- {
- DebugDataWriter.AppendString("classification,surfaceTemperature,absoluteMagnitude,solarLuminosity,solarRadius,solarMass,surfaceGravity,escapeVelocity,rotation,criticalRotation,averageDensity,volume,lifespan,age,");
- }
- public static double getSolarLuminosity(double absoluteMagnitude)
- {
- return System.Math.Pow(2.51188643, (sunMag - absoluteMagnitude));
- }
- public static double getSolarRadius(double magnitude, double temperature)
- {
- return System.Math.Pow(sunTemp / temperature, 2) * (System.Math.Pow(2.512, 0.5 * (sunMag - magnitude)));
- }
- public static double getSolarMass(double luminosity)
- {
- return (System.Math.Pow(luminosity/1,1/3.5)*1);
- }
- public static double getSurfaceGravity(double solarRadius, double solarMass)
- {
- return solarMass / System.Math.Pow(solarRadius, 2);
- }
- public static double convertSolarMassToKG(double solarMass)
- {
- return solarMass * 1988920001144600000000000000000d;
- }
- public static double convertSolarRadiusToMeter(double solarRadius)
- {
- return solarRadius * 696000000d;
- }
- public static double getEscapeVelocity(double solarRadius, double solarMass)
- {
- return System.Math.Sqrt((2 * GM * convertSolarMassToKG(solarMass)) / convertSolarRadiusToMeter(solarRadius));
- }
- public static double getCircumfrence(double solarRadius)
- {
- return 2 * PI * convertSolarRadiusToMeter(solarRadius);
- }
- public static double getSolarVolume(double solarRadius)
- {
- return (4 / 3) * PI * System.Math.Pow(solarRadius, 3);
- }
- public static double getDensity(double mass, double volume)
- {
- return mass / volume;
- }
- public static double getCriticalVelocityOfRotation(double solarMass, double solarRadius)
- {
- return System.Math.Sqrt(GM * convertSolarMassToKG(solarMass) / (convertSolarRadiusToMeter(solarRadius) / 1000));
- }
- public static float generateRotation(double criticalVelocityOfRotation)
- {
- return Random.Range(0, (float)criticalVelocityOfRotation);
- }
- public static double getLifespan(bool giant, double solarMass)
- {
- double lifetime = System.Math.Pow(10, 10) * System.Math.Pow((1 / solarMass), 2.5);
- if (giant)
- {
- return lifetime * .1;
- }
- else
- {
- return lifetime * .9;
- }
- }
- public static float generateAge(double lifespan)
- {
- return Random.Range((float)lifespan * .1f, (float)lifespan);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement