Files
astronomy/generate/test.html
Don Cross eac7750fba Fixed #86 - eliminated redundant JS functions MakeObserver and MakeSpherical.
In the TypeScript/JavaScript code, the functions MakeObserver and MakeSpherical
are no longer needed, because the classes Observer and Spherical are now exported,
along with their constructors. I deleted those functions and reworked callers
to use the equivalent constructors instead.

Also fixed a few breakages in the html/browser examples that crept in recently.
2021-02-09 19:49:00 -05:00

253 lines
9.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<title>Astronomy unit test</title>
<script src="../source/js/astronomy.browser.js"></script>
<script>
window.onload = function() {
function FormatDec(x) {
var neg = (x < 0);
x = Math.abs(x);
var deg = Math.floor(x);
var dz = '';
if (deg < 10) dz += '0';
var min = 60 * (x % 1);
var mz = '';
if (min < 10) mz += '0';
var prefix = neg ? '-' : '+';
return `${prefix}${dz}${deg.toFixed(0)}:${mz}${min.toFixed(2)}`;
}
function FormatRa(x) {
var neg = (x < 0);
x = Math.abs(x);
var deg = Math.floor(x);
var dz = '';
if (deg < 10) dz += '0';
var min = 60 * (x % 1);
var mz = '';
if (min < 10) mz += '0';
return `${dz}${deg.toFixed(0)}:${mz}${min.toFixed(2)}`;
}
var now = new Date();
const observer = new Astronomy.Observer(29, -81, 10);
var body, pos;
document.getElementById('CurrentDateTime').innerText = now.toLocaleString();
for (body of ['Sun', 'Moon', 'Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptune', 'Pluto']) {
if (body === 'Moon')
pos = Astronomy.GeoVector(body, now, false);
else
pos = Astronomy.HelioVector(body, now);
var cell = document.getElementById('pos_' + body);
cell.innerText = `(${pos.x.toFixed(6)}, ${pos.y.toFixed(6)}, ${pos.z.toFixed(6)})`;
if (body !== 'Earth') {
if (body !== 'Moon') // prevent redundant calculation
pos = Astronomy.GeoVector(body, now, false);
var j2000 = Astronomy.Equator(body, now, observer, false, false);
var ofdate = Astronomy.Equator(body, now, observer, true, true);
var hor = Astronomy.Horizon(now, observer, ofdate.ra, ofdate.dec);
var raCell = document.getElementById('ra_' + body);
raCell.innerText = FormatRa(j2000.ra);
var decCell = document.getElementById('dec_' + body);
decCell.innerText = FormatDec(j2000.dec);
var azCell = document.getElementById('az_' + body);
azCell.innerText = hor.azimuth.toFixed(3);
var altCell = document.getElementById('alt_' + body);
altCell.innerText = hor.altitude.toFixed(3);
var culm = Astronomy.SearchHourAngle(body, observer, 0, now);
cell = document.getElementById('culm_' + body);
cell.innerText = culm.time.date.toLocaleTimeString();
const illum = Astronomy.Illumination(body, now);
cell = document.getElementById('phase_' + body);
cell.innerText = illum.phase_angle.toFixed(3);
cell = document.getElementById('dist_' + body);
cell.innerText = illum.geo_dist.toFixed(6);
cell = document.getElementById('mag_' + body);
cell.innerText = (illum.mag > 0 ? '+' : '') + illum.mag.toFixed(2);
}
}
const sun = Astronomy.SunPosition(now);
document.getElementById('SunEcliptic_x').innerText = sun.ex.toFixed(6);
document.getElementById('SunEcliptic_y').innerText = sun.ey.toFixed(6);
document.getElementById('SunEcliptic_z').innerText = sun.ez.toFixed(6);
document.getElementById('SunEcliptic_lat').innerText = sun.elat.toFixed(6);
document.getElementById('SunEcliptic_lon').innerText = sun.elon.toFixed(6);
}
</script>
</head>
<body style="font-family: 'Courier New', Courier, monospace;">
<div id='CurrentDateTime'></div>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<td>body</td>
<td>coords</td>
<td>RA</td>
<td>DEC</td>
<td>azimuth</td>
<td>altitude</td>
<td>culm</td>
<td>phase</td>
<td>dist</td>
<td>mag</td>
</tr>
<tr>
<td>Sun</td>
<td id='pos_Sun'></td>
<td id='ra_Sun'></td>
<td id='dec_Sun'></td>
<td id='az_Sun'></td>
<td id='alt_Sun'></td>
<td id='culm_Sun'></td>
<td id='phase_Sun'></td>
<td id='dist_Sun'></td>
<td id='mag_Sun'></td>
</tr>
<tr>
<td>Moon</td>
<td id='pos_Moon'></td>
<td id='ra_Moon'></td>
<td id='dec_Moon'></td>
<td id='az_Moon'></td>
<td id='alt_Moon'></td>
<td id='culm_Moon'></td>
<td id='phase_Moon'></td>
<td id='dist_Moon'></td>
<td id='mag_Moon'></td>
</tr>
<tr>
<td>Mercury</td>
<td id='pos_Mercury'></td>
<td id='ra_Mercury'></td>
<td id='dec_Mercury'></td>
<td id='az_Mercury'></td>
<td id='alt_Mercury'></td>
<td id='culm_Mercury'></td>
<td id='phase_Mercury'></td>
<td id='dist_Mercury'></td>
<td id='mag_Mercury'></td>
</tr>
<tr>
<td>Venus</td>
<td id='pos_Venus'></td>
<td id='ra_Venus'></td>
<td id='dec_Venus'></td>
<td id='az_Venus'></td>
<td id='alt_Venus'></td>
<td id='culm_Venus'></td>
<td id='phase_Venus'></td>
<td id='dist_Venus'></td>
<td id='mag_Venus'></td>
</tr>
<tr>
<td>Earth</td>
<td id='pos_Earth'></td>
</tr>
<tr>
<td>Mars</td>
<td id='pos_Mars'></td>
<td id='ra_Mars'></td>
<td id='dec_Mars'></td>
<td id='az_Mars'></td>
<td id='alt_Mars'></td>
<td id='culm_Mars'></td>
<td id='phase_Mars'></td>
<td id='dist_Mars'></td>
<td id='mag_Mars'></td>
</tr>
<tr>
<td>Jupiter</td>
<td id='pos_Jupiter'></td>
<td id='ra_Jupiter'></td>
<td id='dec_Jupiter'></td>
<td id='az_Jupiter'></td>
<td id='alt_Jupiter'></td>
<td id='culm_Jupiter'></td>
<td id='phase_Jupiter'></td>
<td id='dist_Jupiter'></td>
<td id='mag_Jupiter'></td>
</tr>
<tr>
<td>Saturn</td>
<td id='pos_Saturn'></td>
<td id='ra_Saturn'></td>
<td id='dec_Saturn'></td>
<td id='az_Saturn'></td>
<td id='alt_Saturn'></td>
<td id='culm_Saturn'></td>
<td id='phase_Saturn'></td>
<td id='dist_Saturn'></td>
<td id='mag_Saturn'></td>
</tr>
<tr>
<td>Uranus</td>
<td id='pos_Uranus'></td>
<td id='ra_Uranus'></td>
<td id='dec_Uranus'></td>
<td id='az_Uranus'></td>
<td id='alt_Uranus'></td>
<td id='culm_Uranus'></td>
<td id='phase_Uranus'></td>
<td id='dist_Uranus'></td>
<td id='mag_Uranus'></td>
</tr>
<tr>
<td>Neptune</td>
<td id='pos_Neptune'></td>
<td id='ra_Neptune'></td>
<td id='dec_Neptune'></td>
<td id='az_Neptune'></td>
<td id='alt_Neptune'></td>
<td id='culm_Neptune'></td>
<td id='phase_Neptune'></td>
<td id='dist_Neptune'></td>
<td id='mag_Neptune'></td>
</tr>
<tr>
<td>Pluto</td>
<td id='pos_Pluto'></td>
<td id='ra_Pluto'></td>
<td id='dec_Pluto'></td>
<td id='az_Pluto'></td>
<td id='alt_Pluto'></td>
<td id='culm_Pluto'></td>
<td id='phase_Pluto'></td>
<td id='dist_Pluto'></td>
<td id='mag_Pluto'></td>
</tr>
</table>
<br>
<br>
<div>Sun Ecliptic Coordinates</div>
<table border="1" cellspacing="0" cellpadding="8">
<tr>
<td>x</td>
<td id="SunEcliptic_x"></td>
</tr>
<tr>
<td>y</td>
<td id="SunEcliptic_y"></td>
</tr>
<tr>
<td>z</td>
<td id="SunEcliptic_z"></td>
</tr>
<tr>
<td>lat</td>
<td id="SunEcliptic_lat"></td>
</tr>
<tr>
<td>lon</td>
<td id="SunEcliptic_lon"></td>
</tr>
</table>
</body>
</html>