-
Notifications
You must be signed in to change notification settings - Fork 8
/
planets.js
153 lines (118 loc) · 7.35 KB
/
planets.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
var FormData = require("form-data");
const math = require('mathjs');
const dotenv = require('dotenv');
var result = require('dotenv').config();
const weight = parseInt(process.env.WEIGHT);
const { writeFile } = require("fs/promises");
var fetch = require("node-fetch");
var formdata = new FormData();
var myDate = new Date();
var dateString = myDate.toISOString();
console.log("date", myDate, "dateString", dateString);
formdata.append("date", dateString);
var requestOptions = {
method: "POST",
body: formdata,
redirect: "follow",
};
async function fetchText() {
let response = await fetch("https://astro6.herokuapp.com/", requestOptions);
let myData = await response.json();
const dataJSON = JSON.stringify(myData, null, 4);
const dataArray = Object.entries(myData);
dataArray.forEach(([key, value]) => {
console.log(key); // 'one'
console.log(value); // 1
});
const arrayJSON = JSON.stringify(dataArray, null, 4);
await writeFile("./files/data-local.json", dataJSON);
await writeFile("./files/data-array.json", arrayJSON);
console.log(myData);
// Now that the data is logged, let's process it
//==============================================
let G = 6.67408 * 10e-11;
console.log('mass of earth:', myData.earth_mass,'*10e+24 kg');
console.log('mass of mars:', myData.mars_mass,'*10e+24 kg');
console.log('distance earth_mars:', myData.marsd,'km');
console.log('geocentric longitude of mars:', myData.marsg.lon,'km');
//Attraction force between planets is G * (mass1 * mass2)/dist^2
let forceMercuryEarth = G * (( myData.earth_mass*10e+24 * myData.mercury_mass*10e+24 ) / Math.pow((myData.mercuryd*1000), 2) );
let forceVenusEarth = G * (( myData.earth_mass*10e+24 * myData.venus_mass*10e+24 ) / Math.pow((myData.venusd*1000), 2) );
let forceMarsEarth = G * (( myData.earth_mass*10e+24 * myData.mars_mass*10e+24 ) / Math.pow((myData.marsd*1000), 2) );
let forceJupiterEarth = G * (( myData.earth_mass*10e+24 * myData.jupiter_mass*10e+24 ) / Math.pow((myData.jupiterd*1000), 2) );
let forceSaturnEarth = G * (( myData.earth_mass*10e+24 * myData.saturn_mass*10e+24 ) / Math.pow((myData.saturnd*1000), 2) );
let forceNeptuneEarth = G * (( myData.earth_mass*10e+24 * myData.neptune_mass*10e+24 ) / Math.pow((myData.neptuned*1000), 2) );
console.log('Attraction force between Mercury and Earth:', forceMercuryEarth.toExponential(),'Newtons');
console.log('Attraction force between Venus and Earth:', forceVenusEarth.toExponential(),'Newtons');
console.log('Attraction force between Mars and Earth:', forceMarsEarth.toExponential(),'Newtons');
console.log('Attraction force between Jupiter and Earth:', forceJupiterEarth.toExponential(),'Newtons');
console.log('Attraction force between Saturn and Earth:', forceSaturnEarth.toExponential(),'Newtons');
console.log('Attraction force between Neptune and Earth:', forceNeptuneEarth.toExponential(),'Newtons');
// let's compute the resulting attraction force vectors of all planets on earth
let x = (forceMercuryEarth * Math.cos(myData.mercuryg.lon)) +
(forceVenusEarth * Math.cos(myData.venusg.lon)) +
(forceMarsEarth * Math.cos(myData.marsg.lon)) +
(forceJupiterEarth * Math.cos(myData.jupiterg.lon)) +
(forceSaturnEarth * Math.cos(myData.saturng.lon)) +
(forceNeptuneEarth * Math.cos(myData.neptuneg.lon));
let y = (forceMercuryEarth * Math.sin(myData.mercuryg.lon)) +
(forceVenusEarth * Math.sin(myData.venusg.lon)) +
(forceMarsEarth * Math.sin(myData.marsg.lon)) +
(forceJupiterEarth * Math.sin(myData.jupiterg.lon)) +
(forceSaturnEarth * Math.sin(myData.saturng.lon)) +
(forceNeptuneEarth * Math.sin(myData.neptuneg.lon));
console.log('x exponential:', x.toExponential(), 'y exponential:', y.toExponential(),'y/x:', (y/x));
console.log('x:', x, 'y:', y);
let globalVectorLong = Math.atan(y/x) * 180 / Math.PI;
let globalVectorForce = Math.sqrt(x**2 + y**2).toExponential();
console.log('global vector force:', globalVectorForce, 'Newtons');
console.log('global vector longitude:', globalVectorLong, 'degrees');
//Attraction force between planet and patient (80kg) is G * (mass1 * mass2)/dist^2
let forceMercuryEarth_p = G * (( weight * myData.mercury_mass*10e+24 ) / Math.pow((myData.mercuryd*1000), 2) );
let forceVenusEarth_p = G * (( weight * myData.venus_mass*10e+24 ) / Math.pow((myData.venusd*1000), 2) );
let forceMarsEarth_p = G * (( weight * myData.mars_mass*10e+24 ) / Math.pow((myData.marsd*1000), 2) );
let forceJupiterEarth_p = G * (( weight * myData.jupiter_mass*10e+24 ) / Math.pow((myData.jupiterd*1000), 2) );
let forceSaturnEarth_p = G * (( weight * myData.saturn_mass*10e+24 ) / Math.pow((myData.saturnd*1000), 2) );
let forceNeptuneEarth_p = G * (( weight * myData.neptune_mass*10e+24 ) / Math.pow((myData.neptuned*1000), 2) );
console.log('Attraction force between Mercury and patient:', forceMercuryEarth_p.toExponential(),'Newtons');
console.log('Attraction force between Venus and patient:', forceVenusEarth_p.toExponential(),'Newtons');
console.log('Attraction force between Mars and patient:', forceMarsEarth_p.toExponential(),'Newtons');
console.log('Attraction force between Jupiter and patient:', forceJupiterEarth_p.toExponential(),'Newtons');
console.log('Attraction force between Saturn and patient:', forceSaturnEarth_p.toExponential(),'Newtons');
console.log('Attraction force between Neptune and patient:', forceNeptuneEarth_p.toExponential(),'Newtons');
let x_p = (forceMercuryEarth_p * Math.cos(myData.mercuryg.lon)) +
(forceVenusEarth_p * Math.cos(myData.venusg.lon)) +
(forceMarsEarth_p * Math.cos(myData.marsg.lon)) +
(forceJupiterEarth_p * Math.cos(myData.jupiterg.lon)) +
(forceSaturnEarth_p * Math.cos(myData.saturng.lon)) +
(forceNeptuneEarth_p * Math.cos(myData.neptuneg.lon));
let y_p = (forceMercuryEarth_p * Math.sin(myData.mercuryg.lon)) +
(forceVenusEarth_p * Math.sin(myData.venusg.lon)) +
(forceMarsEarth_p * Math.sin(myData.marsg.lon)) +
(forceJupiterEarth_p * Math.sin(myData.jupiterg.lon)) +
(forceSaturnEarth_p * Math.sin(myData.saturng.lon)) +
(forceNeptuneEarth_p * Math.sin(myData.neptuneg.lon));
console.log('x_p exponential:', x_p.toExponential(), 'y_p exponential:', y_p.toExponential());
let globalVectorLong_p = Math.atan(y_p/x_p) * 180 / Math.PI;
let globalVectorForce_p = Math.sqrt((x_p**2) + (y_p**2));
let globalVectorLong_p_SD = math.std(myData.mercuryg.lon,myData.venusg.lon,myData.marsg.lon, myData.jupiterg.lon,myData.saturng.lon,myData.neptuneg.lon);
let globalVectorLong_p_SDnorm = globalVectorLong_p_SD/360;
let globalVectorLong_p_SDnorm1 = 1 - globalVectorLong_p_SD/360;
console.log('global vector longitude_p:', globalVectorLong_p, 'degrees');
console.log('global vector force_p:', globalVectorForce_p, 'Newtons');
// let's compute the dispersion of the longitudes as SD of all values, then divide by 360:
console.log('global vector longitude_p SD/360:', globalVectorLong_p_SDnorm, 'degrees');
// The effect sould be bigger when the dispersion is smaller, hence let's make it 1-SDnorm
console.log('global vector longitude_p SD/360 inverted:', globalVectorLong_p_SDnorm1, 'degrees');
let moon_IF = myData.moon_IF;
const forceVectors = JSON.stringify({
tractionEarth: globalVectorForce,
vectorDirection_E:globalVectorLong,
tractionSubject:globalVectorForce_p,
vector_direction_S:globalVectorLong_p,
globalVectorLong_p_SDnorm1:globalVectorLong_p_SDnorm1,
moon_illumination_fraction: moon_IF}, null, 4);
console.log(forceVectors);
await writeFile("./files/forceVectors.json", forceVectors);
}
fetchText();