Advertisement
Guest User

Untitled

a guest
Aug 30th, 2017
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.26 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. //This class contains utilities for heavenly body calculations
  6. public class HeavenlyUtil {
  7.  
  8. private const double stefanBoltzmanConstant = 0.000000560373d;
  9. private const double PI = 3.14159265359d;
  10. private const double GM = 0.00000000006740831d;
  11. private const double sunTemp = 5778;
  12. private const double sunMag = 4.83;
  13.  
  14.  
  15. public static Star buildStar(Star star)
  16. {
  17. //assuming magnitude and temperature are already defined.
  18. star.solarLuminosity = getSolarLuminosity(star.absoluteMagnitude);
  19. star.solarRadius = getSolarRadius(star.absoluteMagnitude, star.surfaceTemperature);
  20. star.solarMass = getSolarMass(star.solarLuminosity);
  21. star.surfaceGravity = getSurfaceGravity(star.solarRadius, star.solarMass);
  22. star.escapeVelocity = getEscapeVelocity(star.solarRadius, star.solarMass);
  23. star.circumfrence = getCircumfrence(star.solarRadius);
  24. star.volume = getSolarVolume(star.solarRadius);
  25. star.averageDensity = getDensity(star.solarMass, star.volume);
  26. star.criticalRotationalVelocity = getCriticalVelocityOfRotation(star.solarMass, star.solarRadius);
  27. star.rotationalVelocity = generateRotation(star.criticalRotationalVelocity);
  28. bool giant = false;
  29. if (star.yerkesClass != "" && star.yerkesClass != "V" && star.yerkesClass != "sd")
  30. {
  31. giant = true;
  32. }
  33. star.lifespan = getLifespan(giant, star.solarMass);
  34. star.age = generateAge(star.lifespan);
  35. return star;
  36. }
  37.  
  38. public static void printStarInfo(Star star)
  39. {
  40. 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);
  41. }
  42.  
  43. public static void csvStarInfo(Star star)
  44. {
  45. 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 + ",");
  46. }
  47.  
  48. public static void csvStarTitle()
  49. {
  50. DebugDataWriter.AppendString("classification,surfaceTemperature,absoluteMagnitude,solarLuminosity,solarRadius,solarMass,surfaceGravity,escapeVelocity,rotation,criticalRotation,averageDensity,volume,lifespan,age,");
  51. }
  52.  
  53. public static double getSolarLuminosity(double absoluteMagnitude)
  54. {
  55. return System.Math.Pow(2.51188643, (sunMag - absoluteMagnitude));
  56. }
  57.  
  58. public static double getSolarRadius(double magnitude, double temperature)
  59. {
  60. return System.Math.Pow(sunTemp / temperature, 2) * (System.Math.Pow(2.512, 0.5 * (sunMag - magnitude)));
  61.  
  62. }
  63.  
  64. public static double getSolarMass(double luminosity)
  65. {
  66. return (System.Math.Pow(luminosity/1,1/3.5)*1);
  67. }
  68.  
  69. public static double getSurfaceGravity(double solarRadius, double solarMass)
  70. {
  71. return solarMass / System.Math.Pow(solarRadius, 2);
  72. }
  73.  
  74. public static double convertSolarMassToKG(double solarMass)
  75. {
  76. return solarMass * 1988920001144600000000000000000d;
  77. }
  78.  
  79. public static double convertSolarRadiusToMeter(double solarRadius)
  80. {
  81. return solarRadius * 696000000d;
  82. }
  83.  
  84. public static double getEscapeVelocity(double solarRadius, double solarMass)
  85. {
  86. return System.Math.Sqrt((2 * GM * convertSolarMassToKG(solarMass)) / convertSolarRadiusToMeter(solarRadius));
  87. }
  88.  
  89. public static double getCircumfrence(double solarRadius)
  90. {
  91. return 2 * PI * convertSolarRadiusToMeter(solarRadius);
  92. }
  93.  
  94. public static double getSolarVolume(double solarRadius)
  95. {
  96. return (4 / 3) * PI * System.Math.Pow(solarRadius, 3);
  97. }
  98.  
  99. public static double getDensity(double mass, double volume)
  100. {
  101. return mass / volume;
  102. }
  103.  
  104. public static double getCriticalVelocityOfRotation(double solarMass, double solarRadius)
  105. {
  106. return System.Math.Sqrt(GM * convertSolarMassToKG(solarMass) / (convertSolarRadiusToMeter(solarRadius) / 1000));
  107. }
  108.  
  109. public static float generateRotation(double criticalVelocityOfRotation)
  110. {
  111. return Random.Range(0, (float)criticalVelocityOfRotation);
  112. }
  113.  
  114. public static double getLifespan(bool giant, double solarMass)
  115. {
  116. double lifetime = System.Math.Pow(10, 10) * System.Math.Pow((1 / solarMass), 2.5);
  117.  
  118. if (giant)
  119. {
  120. return lifetime * .1;
  121. }
  122. else
  123. {
  124. return lifetime * .9;
  125. }
  126. }
  127.  
  128. public static float generateAge(double lifespan)
  129. {
  130. return Random.Range((float)lifespan * .1f, (float)lifespan);
  131. }
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement