diff --git a/generate/template/astronomy.go b/generate/template/astronomy.go index ebc2e8aa..7087261b 100644 --- a/generate/template/astronomy.go +++ b/generate/template/astronomy.go @@ -778,6 +778,45 @@ func RadiansFromDegrees(degrees float64) float64 { return degrees * (math.Pi / 180.0) } +// 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 MassProduct(body Body) float64 { + switch body { + case Sun: + return gmSun + case Mercury: + return gmMercury + case Venus: + return gmVenus + case Earth: + return gmEarth + case Moon: + return gmMoon + case Emb: + return gmEarth + gmMoon + case Mars: + return gmMars + case Jupiter: + return gmJupiter + case Saturn: + return gmSaturn + case Uranus: + return gmUranus + case Neptune: + return gmNeptune + case Pluto: + return gmPluto + default: + return -1.0 // invalid body + } +} + func longitudeOffset(diff float64) float64 { offset := diff for offset <= -180.0 { diff --git a/source/golang/README.md b/source/golang/README.md index e09b8b73..66761154 100644 --- a/source/golang/README.md +++ b/source/golang/README.md @@ -18,6 +18,7 @@ It provides a suite of well\-tested functions for calculating positions of the S - [func DefineStar\(body Body, ra, dec, distanceLightYears float64\) error](<#DefineStar>) - [func DegreesFromRadians\(radians float64\) float64](<#DegreesFromRadians>) - [func Dot\(a, b AstroVector\) float64](<#Dot>) +- [func MassProduct\(body Body\) float64](<#MassProduct>) - [func RadiansFromDegrees\(degrees float64\) float64](<#RadiansFromDegrees>) - [func SiderealTime\(time \*AstroTime\) float64](<#SiderealTime>) - [type AstroMoonQuarter](<#AstroMoonQuarter>) @@ -157,7 +158,7 @@ const ( ``` -## func [AngleBetween]() +## func [AngleBetween]() ```go func AngleBetween(avec AstroVector, bvec AstroVector) float64 @@ -175,7 +176,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 @@ -201,6 +202,15 @@ func Dot(a, b AstroVector) float64 Returns the scalar dot product of two vectors. + +## func [MassProduct]() + +```go +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 [RadiansFromDegrees]() @@ -211,7 +221,7 @@ func RadiansFromDegrees(degrees float64) float64 RadiansFromDegrees converts an angle expressed in degrees to an angle expressed in radians. -## func [SiderealTime]() +## func [SiderealTime]() ```go func SiderealTime(time *AstroTime) float64 @@ -339,7 +349,7 @@ type AstroVector struct { ``` -### func [GeoMoon]() +### func [GeoMoon]() ```go func GeoMoon(time AstroTime) AstroVector @@ -348,7 +358,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 @@ -495,7 +505,7 @@ type JupiterMoonsInfo struct { ``` -### func [JupiterMoons]() +### func [JupiterMoons]() ```go func JupiterMoons(time AstroTime) JupiterMoonsInfo @@ -584,7 +594,7 @@ type RotationMatrix struct { ``` -### func [CombineRotation]() +### func [CombineRotation]() ```go func CombineRotation(a, b RotationMatrix) RotationMatrix @@ -611,7 +621,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 [RotationEqdEqj]() +### func [RotationEqdEqj]() ```go func RotationEqdEqj(time *AstroTime) RotationMatrix @@ -620,7 +630,7 @@ func RotationEqdEqj(time *AstroTime) RotationMatrix Calculates a rotation matrix that converts equator\-of\-date \(EQD\) to J2000 mean equator \(EQJ\). -## type [SearchContext]() +## type [SearchContext]() @@ -675,7 +685,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 fe7c3fc6..fe47714d 100644 --- a/source/golang/astronomy.go +++ b/source/golang/astronomy.go @@ -778,6 +778,45 @@ func RadiansFromDegrees(degrees float64) float64 { return degrees * (math.Pi / 180.0) } +// 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 MassProduct(body Body) float64 { + switch body { + case Sun: + return gmSun + case Mercury: + return gmMercury + case Venus: + return gmVenus + case Earth: + return gmEarth + case Moon: + return gmMoon + case Emb: + return gmEarth + gmMoon + case Mars: + return gmMars + case Jupiter: + return gmJupiter + case Saturn: + return gmSaturn + case Uranus: + return gmUranus + case Neptune: + return gmNeptune + case Pluto: + return gmPluto + default: + return -1.0 // invalid body + } +} + func longitudeOffset(diff float64) float64 { offset := diff for offset <= -180.0 {