mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-05-24 16:56:39 -04:00
C: Added Astronomy_VectorFromEquator and Astronomy_EquatorFromVector.
These helper routines in the JavaScript code make sense for C also.
This commit is contained in:
@@ -2167,8 +2167,7 @@ static int Test_EQJ_EQD(astro_body_t body)
|
||||
{
|
||||
astro_time_t time;
|
||||
astro_observer_t observer;
|
||||
astro_equatorial_t eq2000, eqdate;
|
||||
astro_spherical_t sphere;
|
||||
astro_equatorial_t eq2000, eqdate, eqcheck;
|
||||
astro_vector_t v2000, vdate, t2000;
|
||||
astro_rotation_t r;
|
||||
double ra_diff, dec_diff, dist_diff, diff;
|
||||
@@ -2184,12 +2183,8 @@ static int Test_EQJ_EQD(astro_body_t body)
|
||||
eqdate = Astronomy_Equator(body, &time, observer, EQUATOR_OF_DATE, ABERRATION);
|
||||
CHECK_STATUS(eqdate);
|
||||
|
||||
/* Convert EQJ spherical coordinates to vector. */
|
||||
sphere.status = ASTRO_SUCCESS;
|
||||
sphere.lat = eq2000.dec;
|
||||
sphere.lon = 15.0 * eq2000.ra;
|
||||
sphere.dist = eq2000.dist;
|
||||
v2000 = Astronomy_VectorFromSphere(sphere, time);
|
||||
/* Convert EQJ angular coordinates to vector. */
|
||||
v2000 = Astronomy_VectorFromEquator(eq2000, time);
|
||||
CHECK_STATUS(v2000);
|
||||
|
||||
/* Find rotation matrix. */
|
||||
@@ -2200,14 +2195,14 @@ static int Test_EQJ_EQD(astro_body_t body)
|
||||
vdate = Astronomy_RotateVector(r, v2000);
|
||||
CHECK_STATUS(vdate);
|
||||
|
||||
/* Convert vector back to spherical coordinates. */
|
||||
sphere = Astronomy_SphereFromVector(vdate);
|
||||
CHECK_STATUS(sphere);
|
||||
/* Convert vector back to angular coordinates. */
|
||||
eqcheck = Astronomy_EquatorFromVector(vdate);
|
||||
CHECK_STATUS(eqcheck);
|
||||
|
||||
/* Compare the result with the eqdate. */
|
||||
ra_diff = fabs((sphere.lon / 15.0) - eqdate.ra);
|
||||
dec_diff = fabs(sphere.lat - eqdate.dec);
|
||||
dist_diff = fabs(sphere.dist - eqdate.dist);
|
||||
ra_diff = fabs(eqcheck.ra - eqdate.ra);
|
||||
dec_diff = fabs(eqcheck.dec - eqdate.dec);
|
||||
dist_diff = fabs(eqcheck.dist - eqdate.dist);
|
||||
printf("Test_EQJ_EQD: %s ra=%0.3lf, dec=%0.3lf, dist=%0.3lf, ra_diff=%lg, dec_diff=%lg, dist_diff=%lg\n", Astronomy_BodyName(body), eqdate.ra, eqdate.dec, eqdate.dist, ra_diff, dec_diff, dist_diff);
|
||||
if (ra_diff > 1.0e-14 || dec_diff > 1.0e-14 || dist_diff > 4.0e-15)
|
||||
{
|
||||
@@ -2240,8 +2235,8 @@ static int Test_EQD_HOR(astro_body_t body)
|
||||
astro_equatorial_t eqd, eqj;
|
||||
astro_horizon_t hor;
|
||||
astro_rotation_t rot;
|
||||
astro_vector_t vec_eqd, vec_eqj, vec_hor, check_eqd, check_eqj, check_hor;
|
||||
astro_spherical_t sphere;
|
||||
astro_vector_t vec_eqd, vec_eqj, vec_hor, check_eqd, check_eqj, check_hor;
|
||||
double diff_az, diff_alt, diff;
|
||||
int error;
|
||||
|
||||
@@ -2253,11 +2248,7 @@ static int Test_EQD_HOR(astro_body_t body)
|
||||
hor = Astronomy_Horizon(&time, observer, eqd.ra, eqd.dec, REFRACTION_NORMAL);
|
||||
|
||||
/* Calculate the position of the body as an equatorial vector of date. */
|
||||
sphere.status = ASTRO_SUCCESS;
|
||||
sphere.dist = eqd.dist;
|
||||
sphere.lat = eqd.dec;
|
||||
sphere.lon = 15.0 * eqd.ra;
|
||||
CHECK_VECTOR(vec_eqd, Astronomy_VectorFromSphere(sphere, time));
|
||||
CHECK_VECTOR(vec_eqd, Astronomy_VectorFromEquator(eqd, time));
|
||||
|
||||
/* Calculate rotation matrix to convert equatorial J2000 vector to horizontal vector. */
|
||||
rot = Astronomy_Rotation_EQD_HOR(time, observer);
|
||||
@@ -2306,11 +2297,7 @@ static int Test_EQD_HOR(astro_body_t body)
|
||||
|
||||
/* Exercise HOR to EQJ translation. */
|
||||
CHECK_EQU(eqj, Astronomy_Equator(body, &time, observer, EQUATOR_J2000, ABERRATION));
|
||||
sphere.status = ASTRO_SUCCESS;
|
||||
sphere.dist = eqj.dist;
|
||||
sphere.lat = eqj.dec;
|
||||
sphere.lon = 15.0 * eqj.ra;
|
||||
CHECK_VECTOR(vec_eqj, Astronomy_VectorFromSphere(sphere, time));
|
||||
CHECK_VECTOR(vec_eqj, Astronomy_VectorFromEquator(eqj, time));
|
||||
|
||||
rot = Astronomy_Rotation_HOR_EQJ(time, observer);
|
||||
CHECK_ROTMAT(rot);
|
||||
|
||||
@@ -4210,6 +4210,64 @@ astro_spherical_t Astronomy_SphereFromVector(astro_vector_t vector)
|
||||
return sphere;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Given angular equatorial coordinates in `equ`, calculates equatorial vector.
|
||||
*
|
||||
* @param equ
|
||||
* An object that contains angular equatorial coordinates to be converted to a vector.
|
||||
*
|
||||
* @param time
|
||||
* The date and time of the observation. This is needed because the returned
|
||||
* vector object requires a valid time value when passed to certain other functions.
|
||||
*
|
||||
* @return
|
||||
* A vector in the equatorial system.
|
||||
*/
|
||||
astro_vector_t Astronomy_VectorFromEquator(astro_equatorial_t equ, astro_time_t time)
|
||||
{
|
||||
astro_spherical_t sphere;
|
||||
|
||||
if (equ.status != ASTRO_SUCCESS)
|
||||
return VecError(ASTRO_INVALID_PARAMETER, time);
|
||||
|
||||
sphere.status = ASTRO_SUCCESS;
|
||||
sphere.lat = equ.dec;
|
||||
sphere.lon = 15.0 * equ.ra; /* convert sidereal hours to degrees */
|
||||
sphere.dist = equ.dist;
|
||||
|
||||
return Astronomy_VectorFromSphere(sphere, time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an equatorial vector, calculates equatorial angular coordinates.
|
||||
*
|
||||
* @param vector
|
||||
* A vector in an equatorial coordinate system.
|
||||
*
|
||||
* @return
|
||||
* Angular coordinates expressed in the same equatorial system as `vec`.
|
||||
*/
|
||||
astro_equatorial_t Astronomy_EquatorFromVector(astro_vector_t vector)
|
||||
{
|
||||
astro_equatorial_t equ;
|
||||
astro_spherical_t sphere;
|
||||
|
||||
sphere = Astronomy_SphereFromVector(vector);
|
||||
if (sphere.status != ASTRO_SUCCESS)
|
||||
return EquError(sphere.status);
|
||||
|
||||
equ.status = ASTRO_SUCCESS;
|
||||
equ.dec = sphere.lat;
|
||||
equ.ra = sphere.lon / 15.0; /* convert degrees to sidereal hours */
|
||||
equ.dist = sphere.dist;
|
||||
|
||||
return equ;
|
||||
}
|
||||
|
||||
|
||||
static double ToggleAzimuthDirection(double az)
|
||||
{
|
||||
az = 360.0 - az;
|
||||
|
||||
@@ -3354,7 +3354,7 @@ Astronomy.VectorFromSphere = function(sphere, time) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given angular equatorial coordinates in `sphere`, calculates equatorial vector.
|
||||
* Given angular equatorial coordinates in `equ`, calculates equatorial vector.
|
||||
*
|
||||
* @param {Astronomy.EquatorialCoordinates} equ
|
||||
* An object that contains angular equatorial coordinates to be converted to a vector.
|
||||
|
||||
@@ -354,6 +354,28 @@ Correction for aberration is optional, using the `aberration` parameter.
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
<a name="Astronomy_EquatorFromVector"></a>
|
||||
### Astronomy_EquatorFromVector(vector) ⇒ [`astro_equatorial_t`](#astro_equatorial_t)
|
||||
|
||||
|
||||
|
||||
Given an equatorial vector, calculates equatorial angular coordinates.
|
||||
|
||||
|
||||
|
||||
**Returns:** Angular coordinates expressed in the same equatorial system as `vec`.
|
||||
|
||||
|
||||
|
||||
| Type | Parameter | Description |
|
||||
| --- | --- | --- |
|
||||
| [`astro_vector_t`](#astro_vector_t) | `vector` | A vector in an equatorial coordinate system. |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
<a name="Astronomy_GeoMoon"></a>
|
||||
@@ -1558,6 +1580,29 @@ After calculating the date and time of an astronomical event in the form of an [
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
<a name="Astronomy_VectorFromEquator"></a>
|
||||
### Astronomy_VectorFromEquator(equ, time) ⇒ [`astro_vector_t`](#astro_vector_t)
|
||||
|
||||
**Given angular equatorial coordinates in `equ`, calculates equatorial vector.**
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
**Returns:** A vector in the equatorial system.
|
||||
|
||||
|
||||
|
||||
| Type | Parameter | Description |
|
||||
| --- | --- | --- |
|
||||
| [`astro_equatorial_t`](#astro_equatorial_t) | `equ` | An object that contains angular equatorial coordinates to be converted to a vector. |
|
||||
| [`astro_time_t`](#astro_time_t) | `time` | The date and time of the observation. This is needed because the returned vector object requires a valid time value when passed to certain other functions. |
|
||||
|
||||
|
||||
|
||||
|
||||
---
|
||||
|
||||
<a name="Astronomy_VectorFromHorizon"></a>
|
||||
|
||||
@@ -5449,6 +5449,64 @@ astro_spherical_t Astronomy_SphereFromVector(astro_vector_t vector)
|
||||
return sphere;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @brief
|
||||
* Given angular equatorial coordinates in `equ`, calculates equatorial vector.
|
||||
*
|
||||
* @param equ
|
||||
* An object that contains angular equatorial coordinates to be converted to a vector.
|
||||
*
|
||||
* @param time
|
||||
* The date and time of the observation. This is needed because the returned
|
||||
* vector object requires a valid time value when passed to certain other functions.
|
||||
*
|
||||
* @return
|
||||
* A vector in the equatorial system.
|
||||
*/
|
||||
astro_vector_t Astronomy_VectorFromEquator(astro_equatorial_t equ, astro_time_t time)
|
||||
{
|
||||
astro_spherical_t sphere;
|
||||
|
||||
if (equ.status != ASTRO_SUCCESS)
|
||||
return VecError(ASTRO_INVALID_PARAMETER, time);
|
||||
|
||||
sphere.status = ASTRO_SUCCESS;
|
||||
sphere.lat = equ.dec;
|
||||
sphere.lon = 15.0 * equ.ra; /* convert sidereal hours to degrees */
|
||||
sphere.dist = equ.dist;
|
||||
|
||||
return Astronomy_VectorFromSphere(sphere, time);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Given an equatorial vector, calculates equatorial angular coordinates.
|
||||
*
|
||||
* @param vector
|
||||
* A vector in an equatorial coordinate system.
|
||||
*
|
||||
* @return
|
||||
* Angular coordinates expressed in the same equatorial system as `vec`.
|
||||
*/
|
||||
astro_equatorial_t Astronomy_EquatorFromVector(astro_vector_t vector)
|
||||
{
|
||||
astro_equatorial_t equ;
|
||||
astro_spherical_t sphere;
|
||||
|
||||
sphere = Astronomy_SphereFromVector(vector);
|
||||
if (sphere.status != ASTRO_SUCCESS)
|
||||
return EquError(sphere.status);
|
||||
|
||||
equ.status = ASTRO_SUCCESS;
|
||||
equ.dec = sphere.lat;
|
||||
equ.ra = sphere.lon / 15.0; /* convert degrees to sidereal hours */
|
||||
equ.dist = sphere.dist;
|
||||
|
||||
return equ;
|
||||
}
|
||||
|
||||
|
||||
static double ToggleAzimuthDirection(double az)
|
||||
{
|
||||
az = 360.0 - az;
|
||||
|
||||
@@ -616,8 +616,10 @@ astro_rotation_t Astronomy_InverseRotation(astro_rotation_t rotation);
|
||||
astro_rotation_t Astronomy_CombineRotation(astro_rotation_t a, astro_rotation_t b);
|
||||
astro_vector_t Astronomy_VectorFromSphere(astro_spherical_t sphere, astro_time_t time);
|
||||
astro_spherical_t Astronomy_SphereFromVector(astro_vector_t vector);
|
||||
astro_spherical_t Astronomy_HorizonFromVector(astro_vector_t vector, astro_refraction_t refraction);
|
||||
astro_vector_t Astronomy_VectorFromEquator(astro_equatorial_t equ, astro_time_t time);
|
||||
astro_equatorial_t Astronomy_EquatorFromVector(astro_vector_t vector);
|
||||
astro_vector_t Astronomy_VectorFromHorizon(astro_spherical_t sphere, astro_time_t time, astro_refraction_t refraction);
|
||||
astro_spherical_t Astronomy_HorizonFromVector(astro_vector_t vector, astro_refraction_t refraction);
|
||||
astro_vector_t Astronomy_RotateVector(astro_rotation_t rotation, astro_vector_t vector);
|
||||
|
||||
astro_rotation_t Astronomy_Rotation_EQD_EQJ(astro_time_t time);
|
||||
|
||||
@@ -1149,7 +1149,7 @@ includes the time, as required by <code>AstroTime</code>.
|
||||
<a name="Astronomy.VectorFromEquator"></a>
|
||||
|
||||
### Astronomy.VectorFromEquator(equ, time) ⇒ [<code>Vector</code>](#Astronomy.Vector)
|
||||
Given angular equatorial coordinates in `sphere`, calculates equatorial vector.
|
||||
Given angular equatorial coordinates in `equ`, calculates equatorial vector.
|
||||
|
||||
**Kind**: static method of [<code>Astronomy</code>](#Astronomy)
|
||||
**Returns**: [<code>Vector</code>](#Astronomy.Vector) - A vector in the equatorial system.
|
||||
|
||||
@@ -4375,7 +4375,7 @@ Astronomy.VectorFromSphere = function(sphere, time) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given angular equatorial coordinates in `sphere`, calculates equatorial vector.
|
||||
* Given angular equatorial coordinates in `equ`, calculates equatorial vector.
|
||||
*
|
||||
* @param {Astronomy.EquatorialCoordinates} equ
|
||||
* An object that contains angular equatorial coordinates to be converted to a vector.
|
||||
|
||||
Reference in New Issue
Block a user