Skip to content

Commit

Permalink
Go: added function MassProduct.
Browse files Browse the repository at this point in the history
  • Loading branch information
cosinekitty committed Oct 27, 2023
1 parent 0e29235 commit 7b8ec77
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 10 deletions.
39 changes: 39 additions & 0 deletions generate/template/astronomy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
30 changes: 20 additions & 10 deletions source/golang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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>)
Expand Down Expand Up @@ -157,7 +158,7 @@ const (
```

<a name="AngleBetween"></a>
## func [AngleBetween](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L805>)
## func [AngleBetween](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L844>)

```go
func AngleBetween(avec AstroVector, bvec AstroVector) float64
Expand All @@ -175,7 +176,7 @@ func DaysFromCalendar(year, month, day, hour, minute int, second float64) float6


<a name="DefineStar"></a>
## func [DefineStar](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L843>)
## func [DefineStar](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L882>)

```go
func DefineStar(body Body, ra, dec, distanceLightYears float64) error
Expand All @@ -201,6 +202,15 @@ func Dot(a, b AstroVector) float64

Returns the scalar dot product of two vectors.

<a name="MassProduct"></a>
## func [MassProduct](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L789>)

```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

<a name="RadiansFromDegrees"></a>
## func [RadiansFromDegrees](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L777>)

Expand All @@ -211,7 +221,7 @@ func RadiansFromDegrees(degrees float64) float64
RadiansFromDegrees converts an angle expressed in degrees to an angle expressed in radians.

<a name="SiderealTime"></a>
## func [SiderealTime](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L995>)
## func [SiderealTime](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1034>)

```go
func SiderealTime(time *AstroTime) float64
Expand Down Expand Up @@ -339,7 +349,7 @@ type AstroVector struct {
```

<a name="GeoMoon"></a>
### func [GeoMoon](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1422>)
### func [GeoMoon](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1461>)

```go
func GeoMoon(time AstroTime) AstroVector
Expand All @@ -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.

<a name="RotateVector"></a>
### func [RotateVector](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1164>)
### func [RotateVector](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1203>)

```go
func RotateVector(rotation RotationMatrix, vector AstroVector) AstroVector
Expand Down Expand Up @@ -495,7 +505,7 @@ type JupiterMoonsInfo struct {
```

<a name="JupiterMoons"></a>
### func [JupiterMoons](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1585>)
### func [JupiterMoons](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1624>)

```go
func JupiterMoons(time AstroTime) JupiterMoonsInfo
Expand Down Expand Up @@ -584,7 +594,7 @@ type RotationMatrix struct {
```

<a name="CombineRotation"></a>
### func [CombineRotation](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1186>)
### func [CombineRotation](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1225>)

```go
func CombineRotation(a, b RotationMatrix) RotationMatrix
Expand All @@ -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.

<a name="RotationEqdEqj"></a>
### func [RotationEqdEqj](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1208>)
### func [RotationEqdEqj](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1247>)

```go
func RotationEqdEqj(time *AstroTime) RotationMatrix
Expand All @@ -620,7 +630,7 @@ func RotationEqdEqj(time *AstroTime) RotationMatrix
Calculates a rotation matrix that converts equator\-of\-date \(EQD\) to J2000 mean equator \(EQJ\).

<a name="SearchContext"></a>
## type [SearchContext](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1618-L1620>)
## type [SearchContext](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1657-L1659>)



Expand Down Expand Up @@ -675,7 +685,7 @@ type StateVector struct {
```

<a name="RotateState"></a>
### func [RotateState](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1173>)
### func [RotateState](<https://github.com/cosinekitty/astronomy/blob/golang/source/golang/astronomy.go#L1212>)

```go
func RotateState(rotation RotationMatrix, state StateVector) StateVector
Expand Down
39 changes: 39 additions & 0 deletions source/golang/astronomy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 7b8ec77

Please sign in to comment.