mirror of
https://github.com/cosinekitty/astronomy.git
synced 2025-12-31 11:38:11 -05:00
200 lines
12 KiB
Handlebars
200 lines
12 KiB
Handlebars
# Astronomy Engine (JavaScript / TypeScript)
|
|
|
|
[](https://www.npmjs.com/package/astronomy-engine)
|
|
|
|
This is the complete programming reference for the JavaScript version
|
|
of Astronomy Engine. It supports client side programming
|
|
in the browser, and backend use of [Node.js](https://nodejs.org).
|
|
|
|
[Astronomy Engine is available as an npm package](https://www.npmjs.com/package/astronomy-engine).
|
|
|
|
Both the browser and backend versions of the JavaScript code are generated from
|
|
[TypeScript](https://www.typescriptlang.org/) code in `astronomy.ts`,
|
|
which is also provided here for those who want to use it directly.
|
|
|
|
Other programming languages are supported also.
|
|
See the [home page](https://github.com/cosinekitty/astronomy) for more info.
|
|
|
|
---
|
|
|
|
## Quick Start
|
|
To use Astronomy Engine in your own project, you can use the TypeScript file `astronomy.ts`
|
|
from this directory.
|
|
|
|
For convenience, this directory also contains human-readable JavaScript files `astronomy.js`
|
|
and minified versions for the browser (`astronomy.browser.min.js`) and Node.js (`astronomy.min.js`).
|
|
These JavaScript sources are all compiled from the TypeScript source `astronomy.ts`.
|
|
|
|
To get started quickly, here are some [browser scripting examples](../../demo/browser/)
|
|
and some [Node.js examples](../../demo/nodejs/).
|
|
|
|
---
|
|
|
|
## Topic Index
|
|
|
|
### Position of Sun, Moon, and planets
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [HelioVector](#HelioVector) | Calculates body position vector with respect to the center of the Sun. |
|
|
| [GeoVector](#GeoVector) | Calculates body position vector with respect to the center of the Earth. |
|
|
| [Equator](#Equator) | Calculates right ascension and declination. |
|
|
| [Ecliptic](#Ecliptic) | Converts J2000 mean equator (EQJ) coordinates to true ecliptic of date (ECT) coordinates. |
|
|
| [EclipticLongitude](#EclipticLongitude) | Calculates true ecliptic of date (ECT) longitude for a body. |
|
|
| [Horizon](#Horizon) | Calculates horizontal coordinates (azimuth, altitude) for a given observer on the Earth. |
|
|
| [PairLongitude](#PairLongitude) | Calculates the difference in apparent ecliptic longitude between two bodies, as seen from the Earth. |
|
|
| [BaryState](#BaryState) | Calculates the barycentric position and velocity vectors of the Sun or a planet. |
|
|
|
|
### Geographic helper functions
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [ObserverVector](#ObserverVector) | Calculates a vector from the center of the Earth to an observer on the Earth's surface. |
|
|
| [VectorObserver](#VectorObserver) | Calculates the geographic coordinates for a geocentric equatorial vector. |
|
|
|
|
### Rise, set, and culmination times
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [SearchRiseSet](#SearchRiseSet) | Finds time of rise or set for a body as seen by an observer on the Earth. |
|
|
| [SearchAltitude](#SearchAltitude) | Finds time when a body reaches a given altitude above or below the horizon. Useful for finding civil, nautical, or astronomical twilight. |
|
|
| [SearchHourAngle](#SearchHourAngle) | Finds when body reaches a given hour angle for an observer on the Earth. Hour angle = 0 finds culmination, the highest point in the sky. |
|
|
|
|
### Moon phases
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [MoonPhase](#MoonPhase) | Determines the Moon's phase expressed as an ecliptic longitude. |
|
|
| [SearchMoonQuarter](#SearchMoonQuarter) | Find the first quarter moon phase after a given date and time. |
|
|
| [NextMoonQuarter](#NextMoonQuarter) | Find the next quarter moon phase after a previous one that has been found. |
|
|
|
|
### Eclipses and Transits
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [SearchLunarEclipse](#SearchLunarEclipse) | Search for the first lunar eclipse after a given date. |
|
|
| [NextLunarEclipse](#NextLunarEclipse) | Continue searching for more lunar eclipses. |
|
|
| [SearchGlobalSolarEclipse](#SearchGlobalSolarEclipse) | Search for the first solar eclipse after a given date that is visible anywhere on the Earth. |
|
|
| [NextGlobalSolarEclipse](#NextGlobalSolarEclipse) | Continue searching for solar eclipses visible anywhere on the Earth. |
|
|
| [SearchLocalSolarEclipse](#SearchLocalSolarEclipse) | Search for the first solar eclipse after a given date that is visible at a particular location on the Earth. |
|
|
| [NextLocalSolarEclipse](#NextLocalSolarEclipse) | Continue searching for solar eclipses visible at a particular location on the Earth. |
|
|
| [SearchTransit](#SearchTransit) | Search for the next transit of Mercury or Venus. |
|
|
| [NextTransit](#NextTransit) | Continue searching for transits of Mercury or Venus. |
|
|
|
|
### Lunar perigee and apogee
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [SearchLunarApsis](#SearchLunarApsis) | Finds the next perigee or apogee of the Moon after a specified date. |
|
|
| [NextLunarApsis](#NextLunarApsis) | Given an already-found apsis, find the next perigee or apogee of the Moon. |
|
|
|
|
### Planet perihelion and aphelion
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [SearchPlanetApsis](#SearchPlanetApsis) | Finds the next perihelion or aphelion of a planet after a specified date. |
|
|
| [NextPlanetApsis](#NextPlanetApsis) | Given an already-found apsis, find the next perihelion or aphelion of a planet. |
|
|
|
|
### Visual magnitude and elongation
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [Illumination](#Illumination) | Calculates visual magnitude and phase angle of bodies as seen from the Earth. |
|
|
| [SearchPeakMagnitude](#SearchPeakMagnitude) | Searches for the date and time Venus will next appear brightest as seen from the Earth. |
|
|
| [AngleFromSun](#AngleFromSun) | Returns full angle seen from Earth between body and Sun. |
|
|
| [Elongation](#Elongation) | Calculates ecliptic longitude angle between a body and the Sun, as seen from the Earth. |
|
|
| [SearchMaxElongation](#SearchMaxElongation) | Searches for the next maximum elongation event for Mercury or Venus that occurs after the given date. |
|
|
|
|
### Oppositions and conjunctions
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [SearchRelativeLongitude](#SearchRelativeLongitude) | Find oppositions and conjunctions of planets. |
|
|
|
|
### Equinoxes and solstices
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [Seasons](#Seasons) | Finds the equinoxes and solstices for a given calendar year. |
|
|
| [SunPosition](#SunPosition) | Calculates the Sun's apparent true ecliptic of date (ECT) coordinates as seen from the Earth. |
|
|
|
|
### Date and time
|
|
|
|
Astronomy Engine performs its calculations in UTC using the [`AstroTime`](#AstroTime) class,
|
|
which does not contain timezone information.
|
|
AstroTime objects can be created in several ways, including through a Javascript `Date` object.
|
|
|
|
A JavaScript Date object in UTC can be created using:
|
|
- a Z-terminating string: <code>new Date('2024-07-01T09:00:00Z')</code>
|
|
- a set of numbers, where the month is 0-based: <code>new Date(Date.UTC(2024, 6, 1, 9, 0, 0))</code>
|
|
|
|
Both examples create a Date object set to July 1st 2024 at 9:00:00 UTC.
|
|
|
|
Note that, when displaying Date objects as strings (with `toUTCString()` for instance), JavaScript incorrectly refers to UTC as 'GMT'.
|
|
|
|
### Coordinate transforms
|
|
|
|
The following orientation systems are supported.
|
|
Astronomy Engine can convert a vector from any of these orientations to any of the others.
|
|
It also allows converting from a vector to spherical (angular) coordinates and back,
|
|
within a given orientation. Note the 3-letter codes for each of the orientation systems;
|
|
these are used in function and type names.
|
|
|
|
- **EQJ = J2000 Mean Equator**: Uses the Earth's mean equator (corrected for precession but ignoring nutation) on January 1, 2000, at noon UTC. This moment in time is called J2000.
|
|
- **EQD = True Equator of Date**: Uses the Earth's equator on a given date and time, adjusted for precession and nutation.
|
|
- **ECL = J2000 Mean Ecliptic**: Uses the plane of the Earth's orbit around the Sun at J2000. The x-axis is referenced against the J2000 mean equinox.
|
|
- **ECT = True Ecliptic of Date**: Uses the true (corrected for precession and nutation) orbital plane of the Earth on the given date. The x-axis is referenced against the true equinox for that date.
|
|
- **HOR = Horizontal**: Uses the viewpoint of an observer at a specific location on the Earth at a given date and time.
|
|
- **GAL = Galactic**: Based on the IAU 1958 definition of galactic coordinates.
|
|
|
|
| Function | Description |
|
|
| -------- | ----------- |
|
|
| [RotateVector](#RotateVector) | Applies a rotation matrix to a vector, yielding a vector in another orientation system. |
|
|
| [InverseRotation](#InverseRotation) | Given a rotation matrix, finds the inverse rotation matrix that does the opposite transformation. |
|
|
| [CombineRotation](#CombineRotation) | Given two rotation matrices, returns a rotation matrix that combines them into a net transformation. |
|
|
| [IdentityMatrix](#IdentityMatrix) | Returns a 3x3 identity matrix, which can be used to form other rotation matrices. |
|
|
| [Pivot](#Pivot) | Transforms a rotation matrix by pivoting it around a given axis by a given angle. |
|
|
| [VectorFromSphere](#VectorFromSphere) | Converts spherical coordinates to Cartesian coordinates. |
|
|
| [SphereFromVector](#SphereFromVector) | Converts Cartesian coordinates to spherical coordinates. |
|
|
| [EquatorFromVector](#EquatorFromVector) | Given an equatorial vector, calculates equatorial angular coordinates. |
|
|
| [VectorFromHorizon](#VectorFromHorizon) | Given apparent angular horizontal coordinates, calculates horizontal vector. |
|
|
| [HorizonFromVector](#HorizonFromVector) | Given a vector in horizontal orientation, calculates horizontal angular coordinates. |
|
|
| [Rotation_EQD_EQJ](#Rotation_EQD_EQJ) | Calculates a rotation matrix from true equator of date (EQD) to J2000 mean equator (EQJ). |
|
|
| [Rotation_EQD_ECT](#Rotation_EQD_ECT) | Calculates a rotation matrix from true equator of date (EQD) to true ecliptic of date (ECT). |
|
|
| [Rotation_EQD_ECL](#Rotation_EQD_ECL) | Calculates a rotation matrix from true equator of date (EQD) to J2000 mean ecliptic (ECL). |
|
|
| [Rotation_EQD_HOR](#Rotation_EQD_HOR) | Calculates a rotation matrix from true equator of date (EQD) to horizontal (HOR). |
|
|
| [Rotation_EQJ_EQD](#Rotation_EQJ_EQD) | Calculates a rotation matrix from J2000 mean equator (EQJ) to true equator of date (EQD). |
|
|
| [Rotation_EQJ_ECT](#Rotation_EQJ_ECT) | Calculates a rotation matrix from J2000 mean equator (EQJ) to true ecliptic of date (ECT). |
|
|
| [Rotation_EQJ_ECL](#Rotation_EQJ_ECL) | Calculates a rotation matrix from J2000 mean equator (EQJ) to J2000 mean ecliptic (ECL). |
|
|
| [Rotation_EQJ_HOR](#Rotation_EQJ_HOR) | Calculates a rotation matrix from J2000 mean equator (EQJ) to horizontal (HOR). |
|
|
| [Rotation_ECT_EQD](#Rotation_ECT_EQD) | Calculates a rotation matrix from true ecliptic of date (ECT) to true equator of date (EQD). |
|
|
| [Rotation_ECT_EQJ](#Rotation_ECT_EQJ) | Calculates a rotation matrix from true ecliptic of date (ECT) J2000 mean equator (EQJ). |
|
|
| [Rotation_ECL_EQD](#Rotation_ECL_EQD) | Calculates a rotation matrix from J2000 mean ecliptic (ECL) to true equator of date (EQD). |
|
|
| [Rotation_ECL_EQJ](#Rotation_ECL_EQJ) | Calculates a rotation matrix from J2000 mean ecliptic (ECL) to J2000 mean equator (EQJ). |
|
|
| [Rotation_ECL_HOR](#Rotation_ECL_HOR) | Calculates a rotation matrix from J2000 mean ecliptic (ECL) to horizontal (HOR). |
|
|
| [Rotation_HOR_EQD](#Rotation_HOR_EQD) | Calculates a rotation matrix from horizontal (HOR) to true equator of date (EQD). |
|
|
| [Rotation_HOR_EQJ](#Rotation_HOR_EQJ) | Calculates a rotation matrix from horizontal (HOR) to J2000 mean equator (EQJ). |
|
|
| [Rotation_HOR_ECL](#Rotation_HOR_ECL) | Calculates a rotation matrix from horizontal (HOR) to J2000 mean ecliptic (ECL). |
|
|
| [Rotation_EQJ_GAL](#Rotation_EQJ_GAL) | Calculates a rotation matrix from J2000 mean equator (EQJ) to galactic (GAL). |
|
|
| [Rotation_GAL_EQJ](#Rotation_GAL_EQJ) | Calculates a rotation matrix from galactic (GAL) to J2000 mean equator (EQJ). |
|
|
|
|
### Gravitational simulation of small bodies
|
|
|
|
Astronomy Engine provides a [GravitySimulator](#GravitySimulator) class
|
|
that allows you to model the trajectories of one or more small bodies like asteroids,
|
|
comets, or coasting spacecraft. If you know an initial position vector
|
|
and velocity vector for a small body, the gravity simulator can incrementally
|
|
simulate the pull of gravity on it from the Sun and planets, to calculate its
|
|
movement through the Solar System.
|
|
|
|
---
|
|
|
|
## API Reference
|
|
|
|
{{#orphans ~}}
|
|
{{>header~}}
|
|
{{>body}}
|
|
{{>separator~}}
|
|
{{>members~}}
|
|
{{/orphans~}}
|