From 8a73ecee494894d7d7e79e3d12e4211af2bca3c1 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Mon, 30 Oct 2023 13:28:25 -0400 Subject: [PATCH] Go: added function vsopSphereToRect. --- generate/template/astronomy.go | 9 ++++++++ source/golang/README.md | 40 +++++++++++++++++----------------- source/golang/astronomy.go | 9 ++++++++ 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/generate/template/astronomy.go b/generate/template/astronomy.go index ba857a5e..9960439a 100644 --- a/generate/template/astronomy.go +++ b/generate/template/astronomy.go @@ -912,6 +912,15 @@ func vsopRotate(eclip terseVector) terseVector { } } +func vsopSphereToRect(lon, lat, radius float64) terseVector { + rcoslat := radius * math.Cos(lat) + return terseVector{ + rcoslat * math.Cos(lon), + rcoslat * math.Sin(lon), + radius * math.Sin(lat), + } +} + type jupiterMoon struct { mu float64 al0 float64 diff --git a/source/golang/README.md b/source/golang/README.md index 04c10d71..9030ef8b 100644 --- a/source/golang/README.md +++ b/source/golang/README.md @@ -169,7 +169,7 @@ const ( ``` -## func [AngleBetween]() +## func [AngleBetween]() ```go func AngleBetween(avec AstroVector, bvec AstroVector) float64 @@ -187,7 +187,7 @@ func DaysFromCalendar(year, month, day, hour, minute int, second float64) float6 -## func [DefineStar]() +## func [DefineStar]() ```go func DefineStar(body Body, ra, dec, distanceLightYears float64) error @@ -196,7 +196,7 @@ func DefineStar(body Body, ra, dec, distanceLightYears float64) error -## func [DegreesFromRadians]() +## func [DegreesFromRadians]() ```go func DegreesFromRadians(radians float64) float64 @@ -214,7 +214,7 @@ func Dot(a, b AstroVector) float64 Returns the scalar dot product of two vectors. -## func [MassProduct]() +## func [MassProduct]() ```go func MassProduct(body Body) float64 @@ -223,7 +223,7 @@ func MassProduct(body Body) float64 Returns the product of mass and universal gravitational constant of a Solar System body. For problems involving the gravitational interactions of Solar System bodies, it is helpful to know the product GM, where G = the universal gravitational constant and M = the mass of the body. In practice, GM is known to a higher precision than either G or M alone, and thus using the product results in the most accurate results. This function returns the product GM in the units au^3/day^2. The values come from page 10 of a JPL memorandum regarding the DE405/LE405 ephemeris: https://web.archive.org/web/20120220062549/http://iau-comm4.jpl.nasa.gov/de405iom/de405iom.pdf -## func [ObserverGravity]() +## func [ObserverGravity]() ```go func ObserverGravity(latitude, height float64) float64 @@ -232,7 +232,7 @@ func ObserverGravity(latitude, height float64) float64 Calculates the gravitational acceleration experienced by an observer on the Earth. This function implements the WGS 84 Ellipsoidal Gravity Formula. The result is a combination of inward gravitational acceleration with outward centrifugal acceleration, as experienced by an observer in the Earth's rotating frame of reference. The resulting value increases toward the Earth's poles and decreases toward the equator, consistent with changes of the weight measured by a spring scale of a fixed mass moved to different latitudes and heights on the Earth. The latitude is of the observer in degrees north or south of the equator. By formula symmetry, positive latitudes give the same answer as negative latitudes, so the sign does not matter. The height is specified above the sea level geoid in meters. No range checking is done; however, accuracy is only valid in the range 0 to 100000 meters. The return value is the gravitational acceleration expressed in meters per second squared. -## func [PlanetOrbitalPeriod]() +## func [PlanetOrbitalPeriod]() ```go func PlanetOrbitalPeriod(body Body) float64 @@ -241,7 +241,7 @@ func PlanetOrbitalPeriod(body Body) float64 PlanetOrbitalPeriod returns the average number of days it takes for a planet to orbit the Sun. -## func [RadiansFromDegrees]() +## func [RadiansFromDegrees]() ```go func RadiansFromDegrees(degrees float64) float64 @@ -259,7 +259,7 @@ func RefractionAngle(refraction Refraction, altitude float64) float64 RefractionAngle calculates the amount of "lift" to an altitude angle caused by atmospheric refraction. Given an altitude angle and a refraction option, calculates the amount of "lift" caused by atmospheric refraction. This is the number of degrees higher in the sky an object appears due to the lensing of the Earth's atmosphere. This function works best near sea level. To correct for higher elevations, call Atmosphere for that elevation and multiply the refraction angle by the resulting relative density. The refraction parameter specifies which refraction correction to use. If set to NormalRefraction, uses a well\-behaved refraction model that works well for all valid values \(\-90 to \+90\) of altitude. If set to JplHorizonsRefraction, this function returns a value compatible with the JPL Horizons tool. This is provided for internal unit tests that compare against JPL Horizons data. Any other value, including NoRefraction, causes this function to return 0.0. The return value is a non\-negative value expressed in degrees of refraction above the horizontal. -## func [SiderealTime]() +## func [SiderealTime]() ```go func SiderealTime(time *AstroTime) float64 @@ -387,7 +387,7 @@ type AstroVector struct { ``` -### func [GeoMoon]() +### func [GeoMoon]() ```go func GeoMoon(time AstroTime) AstroVector @@ -396,7 +396,7 @@ func GeoMoon(time AstroTime) AstroVector GeoMoon calculates the equatorial geocentric position of the Moon at a given time. The returned vector indicates the Moon's center relative to the Earth's center. The vector components are expressed in AU \(astronomical units\). The coordinates are oriented with respect to the Earth's equator at the J2000 epoch. In Astronomy Engine, this orientation is called EQJ. -### func [RotateVector]() +### func [RotateVector]() ```go func RotateVector(rotation RotationMatrix, vector AstroVector) AstroVector @@ -552,7 +552,7 @@ type JupiterMoonsInfo struct { ``` -### func [JupiterMoons]() +### func [JupiterMoons]() ```go func JupiterMoons(time AstroTime) JupiterMoonsInfo @@ -641,7 +641,7 @@ type RotationMatrix struct { ``` -### func [CombineRotation]() +### func [CombineRotation]() ```go func CombineRotation(a, b RotationMatrix) RotationMatrix @@ -668,7 +668,7 @@ func InverseRotation(rotation RotationMatrix) RotationMatrix Calculates the inverse of a rotation matrix. Given a rotation matrix that performs some coordinate transform, this function returns the matrix that reverses that transform. -### func [Pivot]() +### func [Pivot]() ```go func Pivot(rotation RotationMatrix, axis int, angle float64) (*RotationMatrix, error) @@ -677,7 +677,7 @@ func Pivot(rotation RotationMatrix, axis int, angle float64) (*RotationMatrix, e Pivot re\-orients a rotation matrix by pivoting it by an angle around one of its axes. Given a rotation matrix, a selected coordinate axis, and an angle in degrees, this function pivots the rotation matrix by that angle around that coordinate axis. For example, if you have rotation matrix that converts ecliptic coordinates \(ECL\) to horizontal coordinates \(HOR\), but you really want to convert ECL to the orientation of a telescope camera pointed at a given body, you can use Pivot twice: \(1\) pivot around the zenith axis by the body's azimuth, then \(2\) pivot around the western axis by the body's altitude angle. The resulting rotation matrix will then reorient ECL coordinates to the orientation of your telescope camera. The axis parameter is an integer that selects which axis to pivot about: 0=x, 1=y, 2=z. The angle parameter is an angle in degrees indicating the amount of rotation around the specified axis. Positive angles indicate rotation counterclockwise as seen from the positive direction along that axis, looking towards the origin point of the orientation system. Any finite number of degrees is allowed, but best precision will result from keeping angle in the range \[\-360, \+360\]. -### func [RotationEclEqj]() +### func [RotationEclEqj]() ```go func RotationEclEqj() RotationMatrix @@ -686,7 +686,7 @@ func RotationEclEqj() RotationMatrix Calculates a rotation matrix from J2000 mean ecliptic \(ECL\) to J2000 mean equator \(EQJ\). -### func [RotationEqdEqj]() +### func [RotationEqdEqj]() ```go func RotationEqdEqj(time *AstroTime) RotationMatrix @@ -695,7 +695,7 @@ func RotationEqdEqj(time *AstroTime) RotationMatrix Calculates a rotation matrix that converts equator\-of\-date \(EQD\) to J2000 mean equator \(EQJ\). -### func [RotationEqjEcl]() +### func [RotationEqjEcl]() ```go func RotationEqjEcl() RotationMatrix @@ -704,7 +704,7 @@ func RotationEqjEcl() RotationMatrix Calculates a rotation matrix from J2000 mean equator \(EQJ\) to J2000 mean ecliptic \(ECL\). -### func [RotationEqjGal]() +### func [RotationEqjGal]() ```go func RotationEqjGal() RotationMatrix @@ -713,7 +713,7 @@ func RotationEqjGal() RotationMatrix Calculates a rotation matrix from J2000 mean equator \(EQJ\) to galactic \(GAL\). -### func [RotationGalEqj]() +### func [RotationGalEqj]() ```go func RotationGalEqj() RotationMatrix @@ -722,7 +722,7 @@ func RotationGalEqj() RotationMatrix -## type [SearchContext]() +## type [SearchContext]() @@ -786,7 +786,7 @@ type StateVector struct { ``` -### func [RotateState]() +### func [RotateState]() ```go func RotateState(rotation RotationMatrix, state StateVector) StateVector diff --git a/source/golang/astronomy.go b/source/golang/astronomy.go index 8f8ebfba..c223fd5e 100644 --- a/source/golang/astronomy.go +++ b/source/golang/astronomy.go @@ -912,6 +912,15 @@ func vsopRotate(eclip terseVector) terseVector { } } +func vsopSphereToRect(lon, lat, radius float64) terseVector { + rcoslat := radius * math.Cos(lat) + return terseVector{ + rcoslat * math.Cos(lon), + rcoslat * math.Sin(lon), + radius * math.Sin(lat), + } +} + type jupiterMoon struct { mu float64 al0 float64