slowe / astro.js Goto Github PK
View Code? Open in Web Editor NEWA Javascript library for astronomy
Home Page: http://slowe.github.com/astro.js/
A Javascript library for astronomy
Home Page: http://slowe.github.com/astro.js/
Hi!
I tried to use your astro.js lib but when I call
var sunazel = astrojs.coordinates.ecliptic2azel(sunpos.lat, sunpos.lon, lst, lat);
I get the error
SCRIPT438: Object doesn't support property or method 'vectorMultiply'
Did I something wrong? All parameters are numeric values!
Thanks
Peter
<!DOCTYPE html>
<html>
<!-- astro.js : http://slowe.github.io/astro.js/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style type="text/css">
</style>
<script language="javascript" type="text/javascript" src="astro.js/astro.js"></script>
<script language="javascript" type="text/javascript" src="astro.js/astro.dates.js"></script> <!-- JD, GST, LST -->
<script language="javascript" type="text/javascript" src="astro.js/astro.ephem.js"></script> <!-- sunPos, moonPos -->
<script language="javascript" type="text/javascript" src="astro.js/astro.coords.js"></script> <!-- coordinates and value transformation -->
<script language="javascript" type="text/javascript" src="astro.js/astro.coordinates.js"></script> <!-- coordinates and value transformation -->
<script language="javascript" type="text/javascript">
var lng = 48.12;
var lat = -16.32;
var tz = -1;
function initAstro() {
//astrojs.ready(function(e){ });
// ...
doAstro();
return;
}
function doAstro() {
var txt = "";
var dt = new Date();
txt += dt + "<br>\n";
var jd = astrojs.dates.getJulianDate(dt);
txt += "Julian Date (JD) : " + jd + "<br>\n";
txt += "Greenwich Sidereal Time (GST) : " + astrojs.dates.getGST(dt) + "<br>\n";
var lst = astrojs.dates.getLST(dt, lng);
txt += "Local Sidereal Time (LST) : " + lst + "<br>\n";
var sunpos = astrojs.ephem.sunPos(jd);
txt += "Sun Pos : lat:" + sunpos.lat + " lon:" + sunpos.lon + " Mo:" + sunpos.Mo +
" D:" + sunpos.D + " N:" + sunpos.N + "<br>\n";
var sunazel = astrojs.coordinates.ecliptic2azel(sunpos.lat, sunpos.lon, lst, lat); // <<<< ERROR
txt += "Sun Pos : az:" + sunazel.az + " el:" + sunazel.el + "<br>\n";
var moonpos = astrojs.ephem.moonPos(jd, sunpos);
txt += "Moon Pos : lat:" + moonpos.lat + " lon:" + moonpos.lon + "<br>\n";
txt += "mean Obliquity : " + astrojs.coordinates.meanObliquity(jd) + "<br>\n";
document.getElementById("output").innerHTML = txt;
return;
}
</script>
</head>
<body onload="initAstro()">
<form name="astro" action="#" onsubmit="doAstro();">
<button onclick="doAstro();">submit</button>
</form>
<br><br>
Result:<br>
<p id="output">*</p>
</body>
</html>
Hi,
First of all, thanks for your library. I am not exploring yet, but it's definitively quite something !
Using your library, I am trying to reproduce the following moon phase indicator : http://www.patek.com/en/collection/movements-complications/moonphase-indicator
For now, I've something like this:
this.illum = this.getMoonIllumination(new Date());
this.pos = this.getMoonPosition(new Date(), 0, 0);
this.angleMoon = this.illum.angle - this.pos.parallacticAngle;
Which gives me the actual moon position at Date() rather than the moon phase.
I've tried to adapt the calculation so they match this code by Xavier Jubier, without success:
/**
* The following code is
* Adapted from http://xjubier.free.fr/en/site_pages/LunarEclipseCalculator.html
* Copyright Xavier Jubier
*/
var myPhaseName = "";
var forecastImage = new Array();
function moonPhasePercent(theDate)
{
var synodic = 29.53058867;
var msPerDay = 86400000;
var baseDate = new Date();
baseDate.setUTCFullYear(2005);
baseDate.setUTCMonth(4);
baseDate.setUTCDate(8);
baseDate.setUTCHours(8);
baseDate.setUTCMinutes(48);
var diff = theDate - baseDate;
var phase = diff / (synodic * msPerDay);
phase *= 100;
phase %= 100;
if ( phase < 0 )
phase += 100;
return(phase);
}
function getMoonPhase()
{
var theDate = new Date();
var phasePercent = moonPhasePercent(theDate);
var phaseNames = [
"New Moon", "New Moon",
"Waxing Crescent", "Waxing Crescent", "Waxing Crescent", "Waxing Crescent",
"First Quarter", "First Quarter", "First Quarter",
"Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous", "Waxing Gibbous",
"Full Moon", "Full Moon",
"Waning Gibbous", "Waning Gibbous", "Waning Gibbous", "Waning Gibbous",
"Last Quarter", "Last Quarter", "Last Quarter",
"Waning Crescent", "Waning Crescent", "Waning Crescent", "Waning Crescent",
"New Moon"
];
thePhase = Math.round(phasePercent * 0.279);
myPhaseName = phaseNames[thePhase];
return thePhase;
}
Thanks,
M.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.