Skip to content
This repository has been archived by the owner on Apr 25, 2020. It is now read-only.

Commit

Permalink
add solar.sin_elevation, fix solar.declination
Browse files Browse the repository at this point in the history
  • Loading branch information
Jay LaPorte committed Apr 4, 2019
1 parent 0a989e4 commit edc21b1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
27 changes: 22 additions & 5 deletions lib/solar.js
Expand Up @@ -67,6 +67,15 @@ function _distance(t) {
return D0 + D1 * cos_g + D2 * cos_2g;
}

function _sin_declination(t) {
return Math.sin(_longitude(t)) * Math.sin(_obliquity(t));
}

function _right_ascension(t) {
const l = _longitude(t);
return Math.atan2(Math.sin(l) * Math.cos(_obliquity(t)), Math.cos(l));
}

// solar transit time
const J0 = 0.0009; // Leap second correction
function _julian_cycle(t, lon) {
Expand All @@ -87,7 +96,7 @@ function _transit(t, lon) {
}

function _altitude(sin_h0, rise, t, lat, lon) {
const sin_dec = Math.sin(_longitude(t)) * Math.sin(_obliquity(t));
const sin_dec = _sin_declination(t);
const cos_dec = Math.sqrt(1 - sin_dec * sin_dec);

return _transit(t, lon) + rise * Math.acos(
Expand Down Expand Up @@ -121,14 +130,21 @@ function distance(ms) {
}

function declination(ms) {
const t = julian.to(ms);
return Math.sin(_longitude(t)) * Math.sin(_obliquity(t));
return Math.asin(_sin_declination(julian.to(ms)));
}

function right_ascension(ms) {
return _right_ascension(julian.to(ms));
}

function sin_elevation(ms, lat, lon) {
const t = julian.to(ms);
const l = _longitude(t);
return Math.atan2(Math.sin(l) * Math.cos(_obliquity(t)), Math.cos(l));
const sin_lat = Math.sin(lat * RAD);
const cos_lat = Math.cos(lat * RAD);
const sin_dec = _sin_declination(t);
const cos_dec = Math.sqrt(1 - sin_dec * sin_dec);
const hour_angle = sidereal.local(t, lon * RAD) - _right_ascension(t);
return sin_lat * sin_dec + cos_lat * cos_dec * Math.cos(hour_angle);
}

// Solar position classes. Helpful if you need to cache results!
Expand Down Expand Up @@ -230,6 +246,7 @@ exports.obliquity = obliquity;
exports.distance = distance;
exports.declination = declination;
exports.right_ascension = right_ascension;
exports.sin_elevation = sin_elevation;
exports.position = position;
exports.transit = transit;
exports.rise = rise;
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "astro",
"version": "2.0.3",
"version": "2.0.4",
"description": "Solar and lunar position calculations",
"main": "index.js",
"devDependencies": {
Expand Down

0 comments on commit edc21b1

Please sign in to comment.