Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace StellarScaper
  8. {
  9. public struct Vector2
  10. {
  11. public double x;
  12. public double y;
  13.  
  14. public Vector2(double x, double y)
  15. {
  16. this.x = x;
  17. this.y = y;
  18. }
  19. }
  20.  
  21. public struct Vector3
  22. {
  23. public double x;
  24. public double y;
  25. public double z;
  26.  
  27. public Vector3(double x, double y, double z)
  28. {
  29. this.x = x;
  30. this.y = y;
  31. this.z = z;
  32. }
  33. }
  34.  
  35. public struct Vector4
  36. {
  37. public double x;
  38. public double y;
  39. public double z;
  40. public double a;
  41.  
  42. public Vector4(double x, double y, double z, double a)
  43. {
  44. this.x = x;
  45. this.y = y;
  46. this.z = z;
  47. this.a = a;
  48. }
  49. }
  50.  
  51. public static class Utilities
  52. {
  53.  
  54. private static double sunMagnitude = 4.83;
  55. private static double PI = 3.14159265358979;
  56. private static double GasConstant = 8.3145;
  57. private static double PlanckConstant = 6.582119514 * Math.Pow(10, -16);
  58. private static double LightSpeed = 299792458;
  59. private static double AvogadroConstant = 6.022140857 * Math.Pow(10, 23);
  60. private static double BoltzmannConstant = GasConstant / AvogadroConstant;
  61. public static double StefanBoltzmannConstant = 5.670367 * Math.Pow(10, -8);
  62. public static double GravitationalConstant = 6.67408 * Math.Pow(10, -11);
  63.  
  64. public static class Double
  65. {
  66. private static Random randomizer;
  67.  
  68. public static double Lerp(double a, double b, double percent)
  69. {
  70. return (a + percent * (b - a));
  71. }
  72.  
  73. public static Vector2 Lerp(Vector2 a, Vector2 b, double percent)
  74. {
  75. return new Vector2((a.x + percent * (b.x - a.x)), (a.y + percent * (b.y - a.y)));
  76. }
  77.  
  78. public static Vector3 Lerp(Vector3 a, Vector3 b, double percent)
  79. {
  80. return new Vector3((a.x + percent * (b.x - a.x)), (a.y + percent * (b.y - a.y)), (a.z + percent * (b.z - a.z)));
  81. }
  82.  
  83. public static Vector4 Lerp(Vector4 a, Vector4 b, double percent)
  84. {
  85. return new Vector4((a.x + percent * (b.x - a.x)), (a.y + percent * (b.y - a.y)), (a.z + percent * (b.z - a.z)), (a.a + percent * (b.a - a.a)));
  86. }
  87.  
  88. public static double Random()
  89. {
  90. if (randomizer == null)
  91. {
  92. randomizer = new Random();
  93. }
  94. return 0 + randomizer.NextDouble() * (100 - 0);
  95. }
  96.  
  97. public static double Random(double maximum, double minimum)
  98. {
  99. if (randomizer == null)
  100. {
  101. randomizer = new Random();
  102. }
  103. return minimum + randomizer.NextDouble() * (maximum - minimum);
  104. }
  105.  
  106. public static Vector2 Random(Vector2 a, Vector2 b)
  107. {
  108. return new Vector2(Random(a.x, b.x), Random(a.y, b.y));
  109. }
  110.  
  111. public static Vector3 Random(Vector3 a, Vector3 b)
  112. {
  113. return new Vector3(Random(a.x, b.x), Random(a.y, b.y), Random(a.z, b.z));
  114. }
  115.  
  116. public static Vector4 Random(Vector4 a, Vector4 b)
  117. {
  118. return new Vector4(Random(a.x, b.x), Random(a.y, b.y), Random(a.z, b.z), Random(a.a, b.a));
  119. }
  120. }
  121.  
  122.  
  123. public static class Calculate
  124. {
  125. public static double SolarMassToKg(double solarMass)
  126. {
  127. return solarMass * (1.989 * Math.Pow(10, 30));
  128. }
  129.  
  130. public static double KgToSolarMass(double Kg)
  131. {
  132. return Kg / (1.989 * Math.Pow(10, 30));
  133. }
  134.  
  135. public static double SolarRadiusToKm(double solarRadius)
  136. {
  137. return solarRadius * (695800);
  138. }
  139.  
  140. public static double KmToSolarRadius(double Km)
  141. {
  142. return Km / (695800);
  143. }
  144.  
  145. public static double MeterToKm(double meter)
  146. {
  147. return meter / 1000;
  148. }
  149.  
  150. public static double KmToMeter(double Km)
  151. {
  152. return Km * 1000;
  153. }
  154.  
  155. public static double GetWattsFromSolarLuminosity(double watts)
  156. {
  157. return watts * (3.827 * Math.Pow(10, 26));
  158. }
  159.  
  160. public static double GetSolarLuminosityFromWatts(double solarLuminosity)
  161. {
  162. return solarLuminosity / (3.827 * Math.Pow(10, 26));
  163. }
  164.  
  165. public static double GetVolumeFromRadius(double radius)
  166. {
  167. return (4d / 3d) * PI * Math.Pow(radius, 2);
  168. }
  169.  
  170. public static double GetRadiusFromVolume(double volume)
  171. {
  172. return Math.Pow(volume / ((4 / 3) * PI), 1d / 2d);
  173. }
  174.  
  175. public static double GetDensityFromMassAndVolume(double mass, double volume)
  176. {
  177. return mass / volume;
  178. }
  179.  
  180. public static double GetMassFromDensityAndVolume(double density, double volume)
  181. {
  182. return density * volume;
  183. }
  184.  
  185. public static double GetVolumeFromMassAndDensity(double mass, double density)
  186. {
  187. return mass / density;
  188. }
  189.  
  190. public class Star
  191. {
  192. public static double SolarLuminosityToMagnitude(double luminosity)
  193. {
  194. return sunMagnitude - (Math.Pow(100d, 1d / 5d) * Math.Log10(luminosity));
  195. }
  196.  
  197. public static double MagnitudeToSolarLuminosity(double magnitude)
  198. {
  199. return Math.Pow(Math.Pow(100d, 1d / 5d), sunMagnitude - magnitude);
  200. }
  201.  
  202. public static double GetSolarMassFromLuminosity(double solarLuminosity)
  203. {
  204. if (solarLuminosity <= (.23 * Math.Pow(.43, 2.3)))
  205. {
  206. return Math.Pow(solarLuminosity / .23d, 1d / 2.3d);
  207. }
  208. else if (solarLuminosity < Math.Pow(2d, 4d))
  209. {
  210. return Math.Pow(solarLuminosity, 1d / 4d);
  211. }
  212. else if (solarLuminosity < 1.5 * Math.Pow(20d, 3.5d))
  213. {
  214. return Math.Pow(solarLuminosity / 1.5d, 1d / 3.5d);
  215. }
  216. else
  217. {
  218. return solarLuminosity / 3200;
  219. }
  220. }
  221.  
  222. public static double GetLuminosityFromSolarMass(double solarMass)
  223. {
  224. if (solarMass <= .43)
  225. {
  226. return (.23 * Math.Pow(solarMass, 2.3));
  227. }
  228. else if (solarMass <= 2)
  229. {
  230. return (Math.Pow(solarMass, 4));
  231. }
  232. else if (solarMass <= 20)
  233. {
  234. return (1.5 * (Math.Pow(solarMass, 3.5)));
  235. }
  236. else
  237. {
  238. return 3200 * solarMass;
  239. }
  240. }
  241.  
  242. public static double GetMeterRadiusFromTempAndWatts(double temperature, double watts) //temperature is in kelvin
  243. {
  244. return Math.Pow(watts / (4d * PI * StefanBoltzmannConstant * Math.Pow(temperature, 4d)), 1d / 2d);
  245. }
  246.  
  247. public static double GetWattsFromTempAndMeterRadius(double temperature, double meters)
  248. {
  249. return 4 * PI * Math.Pow(meters, 2) * StefanBoltzmannConstant * Math.Pow(temperature, 4);
  250. }
  251.  
  252. public static double GetTempFromWattsAndMeterRadius(double watts, double meters)
  253. {
  254. return Math.Pow(watts / (4 * PI * StefanBoltzmannConstant * Math.Pow(meters, 2)), 1d / 4d);
  255. }
  256.  
  257. public static double GetGravityFromRadiusAndMass(double radius, double mass) //radius is in meters, mass is in kilograms, gravity is in meters/second
  258. {
  259. return GravitationalConstant * mass / Math.Pow(radius, 2);
  260. }
  261.  
  262. public static double GetMassFromGravityAndRadius(double gravity, double radius)
  263. {
  264. return (gravity * Math.Pow(radius, 2)) / GravitationalConstant;
  265. }
  266.  
  267. public static double GetRadiusFromGravityAndMass(double gravity, double mass)
  268. {
  269. return Math.Pow((mass * GravitationalConstant) / gravity, 1d / 2d);
  270. }
  271.  
  272. public static class Color
  273. {
  274. public static double GetTempFromBVColor(double bv)
  275. {
  276. return 4600 * ((1 / ((0.92 * bv) + 1.7)) + (1 / ((0.92 * bv) + 0.62)));
  277. }
  278.  
  279. public static Vector2 GetXYyFromTemp(double temperature)
  280. {
  281. Vector2 vec = new Vector2();
  282. if (temperature >= 1667 && temperature <= 4000)
  283. {
  284. vec.x = ((-0.2661239 * Math.Pow(10, 9)) / Math.Pow(temperature, 3)) + ((-0.2343580 * Math.Pow(10, 6)) / Math.Pow(temperature, 2)) + ((0.8776956 * Math.Pow(10, 3)) / temperature) + 0.179910;
  285. }
  286. else if (temperature > 4000 && temperature <= 25000)
  287. {
  288. vec.x = ((-3.0258469 * Math.Pow(10, 9)) / Math.Pow(temperature, 3)) + ((2.1070379 * Math.Pow(10, 6)) / Math.Pow(temperature, 2)) + ((0.2226347 * Math.Pow(10, 3)) / temperature) + 0.240390;
  289. }
  290.  
  291. if (temperature >= 1667 && temperature <= 2222)
  292. {
  293. vec.y = -1.1063814 * Math.Pow(vec.x, 3) - 1.34811020 * Math.Pow(vec.x, 2) + 2.18555832 * vec.x - 0.20219683;
  294. }
  295. else if (temperature > 2222 && temperature <= 4000)
  296. {
  297. vec.y = -0.9549476 * Math.Pow(vec.x, 3) - 1.37418593 * Math.Pow(vec.x, 2) + 2.09137015 * vec.x - 0.16748867;
  298. }
  299. else if (temperature > 4000 && temperature <= 25000)
  300. {
  301. vec.y = 3.0817580 * Math.Pow(vec.x, 3) - 5.87338670 * Math.Pow(vec.x, 2) + 3.75112997 * vec.x - 0.37001483;
  302. }
  303. return vec;
  304. }
  305.  
  306. public static Vector3 GetXYZFromXYy(Vector2 XYy)
  307. {
  308. Vector3 vec = new Vector3();
  309. vec.y = (XYy.y == 0) ? 0 : 1;
  310. vec.x = (XYy.y == 0) ? 0 : (XYy.x * vec.y) / XYy.y;
  311. vec.z = (XYy.y == 0) ? 0 : ((1 - XYy.x - XYy.y) * vec.y) / XYy.y;
  312. return vec;
  313. }
  314.  
  315. public static Vector3 GetRGBFromXYZ(Vector3 XYZ)
  316. {
  317. Vector3 rgb = new Vector3();
  318. rgb.x = 3.2406 * XYZ.x - 1.5372 * XYZ.y - 0.4986 * XYZ.z;
  319. rgb.y = -0.9689 * XYZ.x + 1.8758 * XYZ.y + 0.0415 * XYZ.z;
  320. rgb.z = 0.0557 * XYZ.x - 0.2040 * XYZ.y + 1.0570 * XYZ.z;
  321.  
  322. Vector3 RGB = new Vector3();
  323. RGB.x = (rgb.x <= 0.0031308) ? 12.92 * rgb.x : 1.055 * Math.Pow(rgb.x, 1 / 0.5) - 0.055;
  324. RGB.y = (rgb.y <= 0.0031308) ? 12.92 * rgb.y : 1.055 * Math.Pow(rgb.y, 1 / 0.5) - 0.055;
  325. RGB.z = (rgb.y <= 0.0031308) ? 12.92 * rgb.y : 1.055 * Math.Pow(rgb.y, 1 / 0.5) - 0.055;
  326. return RGB;
  327. }
  328.  
  329. public static Vector3 GetColorFromTemp(double temperature)
  330. {
  331. return GetRGBFromXYZ(GetXYZFromXYy(GetXYyFromTemp(temperature)));
  332. }
  333. }
  334. }
  335. }
  336. }
  337.  
  338. public static class StarGeneration
  339. {
  340.  
  341. public static Vector2[] GetCords(string harvard, string yerkes, int IntNumeral) //on HR diagram
  342. {
  343. Vector2[] returnArray = new Vector2[2];
  344. switch (harvard.ToLower())
  345. {
  346. case "o":
  347. switch (yerkes.ToLower())
  348. {
  349. case "v":
  350. break;
  351. case "iv":
  352. break;
  353. case "iii":
  354. break;
  355. case "ii":
  356. break;
  357. case "ib":
  358. break;
  359. case "iab":
  360. break;
  361. case "ia":
  362. break;
  363. case "ia+":
  364. break;
  365. }
  366. break;
  367. case "b":
  368. switch (yerkes.ToLower())
  369. {
  370. case "v":
  371. break;
  372. case "iv":
  373. break;
  374. case "iii":
  375. break;
  376. case "ii":
  377. break;
  378. case "ib":
  379. break;
  380. case "iab":
  381. break;
  382. case "ia":
  383. break;
  384. case "ia+":
  385. break;
  386. }
  387. break;
  388. case "a":
  389. switch (yerkes.ToLower())
  390. {
  391. case "v":
  392. break;
  393. case "iv":
  394. break;
  395. case "iii":
  396. break;
  397. case "ii":
  398. break;
  399. case "ib":
  400. break;
  401. case "iab":
  402. break;
  403. case "ia":
  404. break;
  405. case "ia+":
  406. break;
  407. }
  408. break;
  409. case "f":
  410. switch (yerkes.ToLower())
  411. {
  412. case "v":
  413. break;
  414. case "iv":
  415. break;
  416. case "iii":
  417. break;
  418. case "ii":
  419. break;
  420. case "ib":
  421. break;
  422. case "iab":
  423. break;
  424. case "ia":
  425. break;
  426. case "ia+":
  427. break;
  428. }
  429. break;
  430. case "g":
  431. switch (yerkes.ToLower())
  432. {
  433. case "v":
  434. break;
  435. case "iv":
  436. break;
  437. case "iii":
  438. break;
  439. case "ii":
  440. break;
  441. case "ib":
  442. break;
  443. case "iab":
  444. break;
  445. case "ia":
  446. break;
  447. case "ia+":
  448. break;
  449. case "sd":
  450. break;
  451. }
  452. break;
  453. case "k":
  454. switch (yerkes.ToLower())
  455. {
  456. case "v":
  457. break;
  458. case "iv":
  459. break;
  460. case "iii":
  461. break;
  462. case "ii":
  463. break;
  464. case "ib":
  465. break;
  466. case "iab":
  467. break;
  468. case "ia":
  469. break;
  470. case "ia+":
  471. break;
  472. case "sd":
  473. break;
  474. }
  475. break;
  476. case "m":
  477. switch (yerkes.ToLower())
  478. {
  479. case "v":
  480. break;
  481. case "iv":
  482. break;
  483. case "iii":
  484. break;
  485. case "ii":
  486. break;
  487. case "ib":
  488. break;
  489. case "iab":
  490. break;
  491. case "ia":
  492. break;
  493. case "ia+":
  494. break;
  495. case "sd":
  496. break;
  497. }
  498. break;
  499. case "c":
  500. switch (yerkes.ToLower())
  501. {
  502. case "v":
  503. break;
  504. case "iv":
  505. break;
  506. case "iii":
  507. break;
  508. case "ii":
  509. break;
  510. case "ib":
  511. break;
  512. case "iab":
  513. break;
  514. case "ia":
  515. break;
  516. case "ia+":
  517. break;
  518. case "sd":
  519. break;
  520. }
  521. break;
  522. case "s":
  523. switch (yerkes.ToLower())
  524. {
  525. case "v":
  526. break;
  527. case "iv":
  528. break;
  529. case "iii":
  530. break;
  531. case "ii":
  532. break;
  533. case "ib":
  534. break;
  535. case "iab":
  536. break;
  537. case "ia":
  538. break;
  539. case "ia+":
  540. break;
  541. case "sd":
  542. break;
  543. }
  544. break;
  545. case "l":
  546. break;
  547. case "t":
  548. break;
  549. case "y":
  550. break;
  551. case "wn":
  552. case "wn/c":
  553. case "wc":
  554. case "wo":
  555. break;
  556. case "DA":
  557. case "DAZ":
  558. case "DAO":
  559. case "DAB":
  560. case "DBZ":
  561. case "DB":
  562. case "DO":
  563. case "DQ":
  564. case "DZ":
  565. case "DC":
  566. break;
  567. }
  568. return returnArray;
  569. }
  570. }
  571. }