1 | /**
|
2 | * @copyright 2013 Sonia Keys
|
3 | * @copyright 2016 commenthol
|
4 | * @license MIT
|
5 | * @module circle
|
6 | */
|
7 | /**
|
8 | * Circle: Chapter 20, Smallest Circle containing three Celestial Bodies.
|
9 | */
|
10 |
|
11 | /**
|
12 | * Smallest finds the smallest circle containing three points.
|
13 | *
|
14 | * Arguments should represent coordinates in right ascension and declination
|
15 | * or longitude and latitude. Result Δ is the diameter of the circle, typeI
|
16 | * is true if solution is of type I.
|
17 | *
|
18 | * @param {base.Coords} c1 - ra, dec point 1
|
19 | * @param {base.Coords} c2 - ra, dec point 2
|
20 | * @param {base.Coords} c3 - ra, dec point 3
|
21 | * @returns {Array} [Δ, typeI]
|
22 | * {Number} Δ - diameter of the circle
|
23 | * {Number} typeI - true - Two points on circle, one interior.
|
24 | * false - All three points on circle.
|
25 | */
|
26 | export function smallest(c1, c2, c3) {
|
27 | // Using haversine formula
|
28 | var cd1 = Math.cos(c1.dec);
|
29 | var cd2 = Math.cos(c2.dec);
|
30 | var cd3 = Math.cos(c3.dec);
|
31 | var a = 2 * Math.asin(Math.sqrt(hav(c2.dec - c1.dec) + cd1 * cd2 * hav(c2.ra - c1.ra)));
|
32 | var b = 2 * Math.asin(Math.sqrt(hav(c3.dec - c2.dec) + cd2 * cd3 * hav(c3.ra - c2.ra)));
|
33 | var c = 2 * Math.asin(Math.sqrt(hav(c1.dec - c3.dec) + cd3 * cd1 * hav(c1.ra - c3.ra)));
|
34 | if (b > a) {
|
35 | var _noswap = noswap(b, a);
|
36 |
|
37 | a = _noswap[0];
|
38 | b = _noswap[1];
|
39 | }
|
40 | if (c > a) {
|
41 | var _noswap2 = noswap(c, a);
|
42 |
|
43 | a = _noswap2[0];
|
44 | c = _noswap2[1];
|
45 | }
|
46 | if (a * a >= b * b + c * c) {
|
47 | return [a, true];
|
48 | }
|
49 | // (20.1) p. 128
|
50 | return [2 * a * b * c / Math.sqrt((a + b + c) * (a + b - c) * (b + c - a) * (a + c - b)), false];
|
51 | }
|
52 |
|
53 | var noswap = function noswap(a, b) {
|
54 | return [a, b];
|
55 | };
|
56 |
|
57 | /**
|
58 | * haversine function (17.5) p. 115
|
59 | */
|
60 | var hav = function hav(a) {
|
61 | return 0.5 * (1 - Math.cos(a));
|
62 | };
|
63 |
|
64 | export default {
|
65 | smallest: smallest
|
66 | }; |
\ | No newline at end of file |