Update code concept, readme and the accuration is getting closer with the real on

master v1.0.2
Orion Stark 7 years ago
parent 1172597312
commit 75ab08062b
  1. 42
      README.md
  2. 89
      dist/solar-calculation.js
  3. 4
      main.js
  4. 6
      package.json

@ -7,12 +7,23 @@ This program is not really accurate about the calculation. For the sunrise and s
## Install with npm
npm install calculation-ofsun
## Without npm
1. Clone this project
2. Create your new js file
3. Import the solar-calculation.js to your code. You could find the script in dist directory
4. Then, have fun
## Attention
If you didn't understand what I'm saying about how to use it without npm. You could check the main.js.
That's it.
## How to Use It
```javascript
const cls = require('calculation-ofsun')
console.log(cls.getSunInformation(new Date(), 33, 3))
/* Get Sun Information expected 3 parameters */
/* Date, lat, long */
/* For the other function and it's parameter. You could check on the table below */
```
## How to use another functions that require juliandate as the parameter
@ -46,18 +57,25 @@ sunriseandsunset | JulianDate
Nethereland GMT +1
It'll return time denpend on your local time
{ sun_position: { azimuth: -77.80678591967518, altitude: 4.0819291879429525 },
date: 'Sat Mar 10 2018 13:39:40 GMT+0700 (WIB)',
sunrise: 'Sat Mar 10 2018 13:07:56 GMT+0700 (WIB)',
sunset: 'Sun Mar 11 2018 00:36:33 GMT+0700 (WIB)',
mean_anomaly: { degrees: 64.65251729583633, rad: 1.1283992965149248 },
solar_transit: 2458187.994618933,
equation_of_center: { degrees: 1.7458618484586093, rad: 0.03047103754055702 },
h: 282.14627224302416,
RA: { degrees: -9.80213468943287, rad: -0.17107952405455543 },
clientJD: 2458187.777554097,
true_anomaly: { degrees: 66.39837914429494, rad: 1.1588703340554818 },
sideraltime: 272.3441375535913 }
{ sun_position: {
azimuth: -101.53872252647008,
altitude: 57.268164438252526
},
date: 'Sat Apr 14 2018 10:16:32 GMT+0700 (WIB)',
observe_location: {
latitude: 3.597031,
longitude: 98.678513
},
sunrise: 'Sat Apr 14 2018 06:21:42 GMT+0700 (WIB)',
sunset: 'Sat Apr 14 2018 18:32:54 GMT+0700 (WIB)',
solar_transit: 2458222.7272965494,
hour_angle: 327.53679257420777,
right_ascension:
{ degrees: 22.060782554336377,
rad: 0.38503329113969464
},
clientJD: 2458222.6364905904
}

@ -21,6 +21,27 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
const JD1970 = 2440588;
const JD2000 = 2451545;
const earthC_coefficient_component = {
C1: 1.9148,
C2: 0.0200,
C3: 0.0003,
C4: 0,
C5: 0,
C6: 0,
EC: 0.0000
}
const earth_perihelion = 102.9373;
const earth_obliquity = 23.4393 * (Math.PI / 180);
const earth_obliquity_degrees = 23.4393;
const earth_sideral_time = {
at_zero_long: 280.1470,
rate_of_change: 360.9856235
};
class Sunpositioning {
/* Earth */
@ -48,36 +69,16 @@ class Sunpositioning {
Neptune 256.2250 0.00598103
Pluto 14.882 0.00396
*/
constructor(){
this.JD1970 = 2440588;
this.JD2000 = 2451545;
this.earthC_coefficient_component = {
C1: 1.9148,
C2: 0.0200,
C3: 0.0003,
C4: 0,
C5: 0,
C6: 0,
EC: 0.0000
};
this.earth_perihelion = 102.9373;
this.earth_obliquity = 23.4393 * (Math.PI / 180);
this.earth_obliquity_degrees = 23.4393;
this.earth_sideral_time = {
at_zero_long: 280.1470,
rate_of_change: 360.9856235
};
}
constructor(){}
/*
@function
Get Information of sun by giving a date, latitude and longtitude
Get Information of sun by giving a date, latitude and longitude
*/
getSunInformation(date, lat, long) {
this.CLIENT_JD = this.dateToJD(date);
this.CLIENT_LATITUDE = lat;
this.CLIENT_LONGTITUDE = long;
this.CLIENT_LONGITUDE = long;
this.CLIENT_lw = -long;
let position = this.getSunPosition();
return {
@ -86,34 +87,34 @@ class Sunpositioning {
altitude: position.altitude.degrees
},
date: this.jdToDate(this.CLIENT_JD).toString(),
observe_location: {
latitude: this.CLIENT_LATITUDE,
longitude: this.CLIENT_LONGITUDE
},
sunrise: this.jdToDate(this.sunriseandsunset(this.CLIENT_JD).sunrise).toString(),
sunset: this.jdToDate(this.sunriseandsunset(this.CLIENT_JD).sunset).toString(),
mean_anomaly: this.earthMeanAnomaly(this.CLIENT_JD),
solar_transit: this.solarTransit(this.CLIENT_JD),
equation_of_center: this.equation_of_center(this.CLIENT_JD),
h: this.getHourAngle(this.CLIENT_JD),
RA: this.rightAscension(this.CLIENT_JD),
hour_angle: this.getHourAngle(this.CLIENT_JD),
right_ascension: this.rightAscension(this.CLIENT_JD),
clientJD: this.CLIENT_JD,
true_anomaly: this.earthTrueAnomaly(this.CLIENT_JD),
sideraltime: this.sideraltime(this.CLIENT_JD)
};
}
dateToJD(date) {
return date.valueOf() / ( 1000 * 60 * 60 * 24 ) - 0.5 + this.JD1970;
return date.valueOf() / ( 1000 * 60 * 60 * 24 ) - 0.5 + JD1970;
}
jdToDate(jd) {
return new Date((jd + 0.5 - this.JD1970) * ( 1000 * 60 * 60 * 24 ) )
return new Date((jd + 0.5 - JD1970) * ( 1000 * 60 * 60 * 24 ) )
}
equation_of_center(jd) {
/*
the C4 - C6 are 0, so I just calculate for Coefficient 1 - 3.
*/
let results = this.earthC_coefficient_component.C1 * Math.sin(this.earthMeanAnomaly(jd).rad) +
this.earthC_coefficient_component.C2 * Math.sin(2 * this.earthMeanAnomaly(jd).rad) +
this.earthC_coefficient_component.C3 * Math.sin(3 * this.earthMeanAnomaly(jd).rad);
let results = earthC_coefficient_component.C1 * Math.sin(this.earthMeanAnomaly(jd).rad) +
earthC_coefficient_component.C2 * Math.sin(2 * this.earthMeanAnomaly(jd).rad) +
earthC_coefficient_component.C3 * Math.sin(3 * this.earthMeanAnomaly(jd).rad);
return {
degrees: results,
rad: results * (Math.PI / 180)
@ -122,8 +123,8 @@ class Sunpositioning {
earthMeanAnomaly(jd) {
return {
degrees: ( 357.5291 + 0.98560028 * ( jd - this.JD2000 ) ) % 360,
rad: (( 357.5291 + 0.98560028 * ( jd - this.JD2000 ) ) % 360) * (Math.PI / 180)
degrees: ( 357.5291 + 0.98560028 * ( jd - JD2000 ) ) % 360,
rad: (( 357.5291 + 0.98560028 * ( jd - JD2000 ) ) % 360) * (Math.PI / 180)
}
}
@ -137,7 +138,7 @@ class Sunpositioning {
eclipticLongtitude(jd) {
let true_anomaly = this.earthTrueAnomaly(jd);
let results = (true_anomaly.degrees + this.earth_perihelion + 180) % 360;
let results = (true_anomaly.degrees + earth_perihelion + 180) % 360;
return {
degrees: results,
rad: results * (Math.PI / 180)
@ -145,8 +146,8 @@ class Sunpositioning {
}
rightAscension(jd) {
let ecliptic_longtitude = this.eclipticLongtitude(jd);
let results = Math.atan2(Math.sin(ecliptic_longtitude.rad) * Math.cos(this.earth_obliquity), Math.cos(ecliptic_longtitude.rad));
let ecliptic_longitude = this.eclipticLongtitude(jd);
let results = Math.atan2(Math.sin(ecliptic_longitude.rad) * Math.cos(earth_obliquity), Math.cos(ecliptic_longitude.rad));
return {
degrees: results / (Math.PI / 180),
rad: results
@ -154,8 +155,8 @@ class Sunpositioning {
}
declination(jd) {
let ecliptic_longtitude = this.eclipticLongtitude(jd);
let results = Math.asin(Math.sin(ecliptic_longtitude.rad) * Math.sin(this.earth_obliquity));
let ecliptic_longitude = this.eclipticLongtitude(jd);
let results = Math.asin(Math.sin(ecliptic_longitude.rad) * Math.sin(earth_obliquity));
return {
degrees: results / (Math.PI / 180),
rad: results
@ -163,7 +164,7 @@ class Sunpositioning {
}
sideraltime(jd) {
let results = (this.earth_sideral_time.at_zero_long + this.earth_sideral_time.rate_of_change * (jd - this.JD2000) - (this.CLIENT_lw)) % 360;
let results = (earth_sideral_time.at_zero_long + earth_sideral_time.rate_of_change * (jd - JD2000) - (this.CLIENT_lw)) % 360;
return results;
}
@ -191,12 +192,12 @@ class Sunpositioning {
solarTransit(jd) {
let lw = this.CLIENT_lw;
let _JD2000 = this.JD2000
let _JD2000 = JD2000
function nx() { return ((jd - _JD2000 - 0.0009) / 1 - (lw / 360)); }
let n = Math.round(nx());
function JDX() { return jd + 1 * ( n - nx() ); }
let M = this.earthMeanAnomaly(JDX()).degrees;
let L = (M + this.earth_perihelion + 180) % 360;
let L = (M + earth_perihelion + 180) % 360;
let JDtmp = JDX() + 0.0053 * Math.sin(M * Math.PI / 180) - 0.0068 * Math.sin(2 * (L * (Math.PI / 180)));
return JDtmp - (0 / 360 ) * 1;
}

@ -0,0 +1,4 @@
const algorithm = require('./dist/solar-calculation');
const myJD = algorithm.dateToJD(new Date())
console.log(algorithm.getSunInformation(new Date(), 3.597031, 98.678513));

@ -1,6 +1,6 @@
{
"name": "calculation-ofsun",
"version": "1.0.0",
"version": "1.0.2",
"description": "Sun calculation based on formula from http://aa.quae.nl/en/reken/zonpositie.html",
"main": "./dist/solar-calculation.js",
"scripts": {
@ -13,5 +13,9 @@
"sun calculation",
"science"
],
"repository": {
"type": "git",
"url": "https://github.com/OrionStark/calculation-of-sun.git"
},
"readme": "README.md"
}

Loading…
Cancel
Save