UNPKG

2.09 kBJavaScriptView Raw
1/**
2 * @copyright 2013 Sonia Keys
3 * @copyright 2016 commenthol
4 * @license MIT
5 * @module stellar
6 */
7/**
8 * Stellar: Chapter 56, Stellar Magnitudes.
9 */
10
11/**
12 * Sum returns the combined apparent magnitude of two stars.
13 */
14export function sum(m1, m2) {
15 // (m1, m2 float64) float64
16 var x = 0.4 * (m2 - m1);
17 return m2 - 2.5 * Math.log10(Math.pow(10, x) + 1);
18}
19
20/**
21 * SumN returns the combined apparent magnitude of a number of stars.
22 */
23export function sumN(m) {
24 // (m ...float64) float64
25 var s = 0;
26 for (var _iterator = m, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
27 var _ref;
28
29 if (_isArray) {
30 if (_i >= _iterator.length) break;
31 _ref = _iterator[_i++];
32 } else {
33 _i = _iterator.next();
34 if (_i.done) break;
35 _ref = _i.value;
36 }
37
38 var mi = _ref;
39
40 s += Math.pow(10, -0.4 * mi);
41 }
42 return -2.5 * Math.log10(s);
43}
44
45/**
46 * Ratio returns the brightness ratio of two stars.
47 *
48 * Arguments m1, m2 are apparent magnitudes.
49 */
50export function ratio(m1, m2) {
51 // (m1, m2 float64) float64
52 var x = 0.4 * (m2 - m1);
53 return Math.pow(10, x);
54}
55
56/**
57 * Difference returns the difference in apparent magnitude of two stars
58 * given their brightness ratio.
59 */
60export function difference(ratio) {
61 // (ratio float64) float64
62 return 2.5 * Math.log10(ratio);
63}
64
65/**
66 * AbsoluteByParallax returns absolute magnitude given annual parallax.
67 *
68 * Argument m is apparent magnitude, π is annual parallax in arc seconds.
69 */
70export function absoluteByParallax(m, π) {
71 // (m, π float64) float64
72 return m + 5 + 5 * Math.log10(π);
73}
74
75/**
76 * AbsoluteByDistance returns absolute magnitude given distance.
77 *
78 * Argument m is apparent magnitude, d is distance in parsecs.
79 */
80export function absoluteByDistance(m, d) {
81 // (m, d float64) float64
82 return m + 5 - 5 * Math.log10(d);
83}
84
85export default {
86 sum: sum,
87 sumN: sumN,
88 ratio: ratio,
89 difference: difference,
90 absoluteByParallax: absoluteByParallax,
91 absoluteByDistance: absoluteByDistance
92};
\No newline at end of file