base

package
v3.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 10, 2018 License: MIT Imports: 2 Imported by: 1

Documentation

Overview

Base: Functions and other definitions useful with multiple packages.

Base contains various definitions and support functions useful in multiple chapters.

Bessellian and Julian Year

Chapter 21, Precession actually contains these definitions. They are moved here because of their general utility.

Chapter 22, Nutation contains the function for Julian centuries since J2000.

Phase angle functions

Two functions, Illuminated and Limb, concern the illumnated phase of a body and are given in two chapters, 41 an 48. They are collected here because the identical functions apply in both chapters.

General purpose math functions

SmallAngle is recommended in chapter 17, p. 109.

PMod addresses the issue on p. 7, chapter 1, in the section "Trigonometric functions of large angles", but the function is not written to be specific to angles and so has more general utility.

Horner is described on p. 10, chapter 1.

FloorDiv and FloorDiv64 are optimizations for the INT function described on p. 60, chapter 7.

Unit types and conversions

While the library uses float64s for many parameter and return values, it sometimes uses a defined type to clarify interpretation of a value. Types Angle, RA, HourAngle, and Time are defined here for this purpose. These defined types have a number of constructors and methods that perform useful conversions.

Also the function FromSexa takes sexagesimal components such as degrees minutes and seconds and returns a single value.

Index

Examples

Constants

View Source
const (
	SOblJ2000 = .397777156
	COblJ2000 = .917482062
)

SOblJ2000, COblJ2000 are sine and cosine of obliquity at J2000.

View Source
const (
	J1900 = 2415020.0
	B1900 = 2415020.3135
	B1950 = 2433282.4235
)

Julian days of common epochs.

View Source
const (
	JulianYear    = 365.25      // days
	JulianCentury = 36525       // days
	BesselianYear = 365.2421988 // days
)

JulianYear and other common periods.

View Source
const AU = 149597870

AU is one astronomical unit in km.

View Source
const J2000 = 2451545.0

J2000 is the Julian date corresponding to January 1.5, year 2000.

View Source
const JMod = 2400000.5

JMod is the Julian date of the modified Julian date epoch.

View Source
const K = .01720209895

K is the Gaussian gravitational constant.

Variables

View Source
var (
	SmallAngle    = unit.AngleFromMin(10) // about .003 radians
	CosSmallAngle = SmallAngle.Cos()      // about .999996
)

SmallAngle is threshold used by various routines for switching between trigonometric functions and Pythagorean approximations.

In chapter 17, p. 109, Meeus recommends 10′.

Functions

func BesselianYearToJDE

func BesselianYearToJDE(by float64) float64

BesselianYearToJDE returns the Julian ephemeris day for a Besselian year.

func Cmp

func Cmp(a, b float64) int

Cmp compares two float64s and returns -1, 0, or 1 if a is <, ==, or > b, respectively.

The name and semantics are chosen to match big.Cmp in the Go standard library.

func FloorDiv

func FloorDiv(x, y int) (q int)

FloorDiv returns the integer floor of the fractional value (x / y).

It uses integer math only, so is more efficient than using floating point intermediate values. This function can be used in many places where INT() appears in AA. As with built in integer division, it panics with y == 0.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/meeus/v3/base"
)

func main() {
	// compare to / operator examples in Go spec at
	// https://golang.org/ref/spec#Arithmetic_operators
	fmt.Println(base.FloorDiv(+5, +3))
	fmt.Println(base.FloorDiv(-5, +3))
	fmt.Println(base.FloorDiv(+5, -3))
	fmt.Println(base.FloorDiv(-5, -3))
	fmt.Println()
	// exact divisors, no remainders
	fmt.Println(base.FloorDiv(+6, +3))
	fmt.Println(base.FloorDiv(-6, +3))
	fmt.Println(base.FloorDiv(+6, -3))
	fmt.Println(base.FloorDiv(-6, -3))
}
Output:

1
-2
-2
1

2
-2
-2
2

func FloorDiv64

func FloorDiv64(x, y int64) (q int64)

FloorDiv64 returns the integer floor of the fractional value (x / y).

It uses integer math only, so is more efficient than using floating point intermediate values. This function can be used in many places where INT() appears in AA. As with built in integer division, it panics with y == 0.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/meeus/v3/base"
)

func main() {
	// compare to / operator examples in Go spec at
	// https://golang.org/ref/spec#Arithmetic_operators
	fmt.Println(base.FloorDiv64(+5, +3))
	fmt.Println(base.FloorDiv64(-5, +3))
	fmt.Println(base.FloorDiv64(+5, -3))
	fmt.Println(base.FloorDiv64(-5, -3))
	fmt.Println()
	// exact divisors, no remainders
	fmt.Println(base.FloorDiv64(+6, +3))
	fmt.Println(base.FloorDiv64(-6, +3))
	fmt.Println(base.FloorDiv64(+6, -3))
	fmt.Println(base.FloorDiv64(-6, -3))
}
Output:

1
-2
-2
1

2
-2
-2
2

func Hav

func Hav(a unit.Angle) float64

Hav implements the haversine trigonometric function.

See https://en.wikipedia.org/wiki/Haversine_formula.

func Horner

func Horner(x float64, c ...float64) float64

Horner evaluates a polynomal with coefficients c at x. The constant term is c[0]. The function panics with an empty coefficient list.

func Illuminated

func Illuminated(i unit.Angle) float64

Illuminated returns the illuminated fraction of a body's disk.

The illuminated body can be the Moon or a planet.

Argument i is the phase angle.

Example (Moon)
package main

import (
	"fmt"

	"github.com/soniakeys/meeus/v3/base"
	"github.com/soniakeys/unit"
)

func main() {
	// Example 48.a, p. 347.
	k := base.Illuminated(unit.AngleFromDeg(69.0756))
	fmt.Printf("k = %.4f\n", k)
}
Output:

k = 0.6786
Example (Venus)
package main

import (
	"fmt"
	"math"

	"github.com/soniakeys/meeus/v3/base"
	"github.com/soniakeys/unit"
)

func main() {
	// Example 41.a, p. 284.
	k := base.Illuminated(unit.Angle(math.Acos(.29312)))
	fmt.Printf("%.3f\n", k)
}
Output:

0.647

func J2000Century

func J2000Century(jde float64) float64

J2000Century returns the number of Julian centuries since J2000.

The quantity appears as T in a number of time series.

func JDEToBesselianYear

func JDEToBesselianYear(jde float64) float64

JDEToBesselianYear returns the Besselian year for a Julian ephemeris day.

func JDEToJulianYear

func JDEToJulianYear(jde float64) float64

JDEToJulianYear returns a Julian year for a Julian ephemeris day.

func JulianYearToJDE

func JulianYearToJDE(jy float64) float64

JulianYearToJDE returns the Julian ephemeris day for a Julian year.

func LightTime

func LightTime(Δ float64) float64

LightTime returns time for light to travel a given distance.

Δ is distance in AU.

Result in days.

func Limb

func Limb(α unit.RA, δ unit.Angle, α0 unit.RA, δ0 unit.Angle) unit.Angle

Limb returns the position angle of the midpoint of an illuminated limb.

The illuminated body can be the Moon or a planet.

Arguments α, δ are equatorial coordinates of the body; α0, δ0 are apparent coordinates of the Sun.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/meeus/v3/base"
	"github.com/soniakeys/unit"
)

func main() {
	// Example 48.a, p. 347.
	χ := base.Limb(
		unit.RAFromDeg(134.6885),
		unit.AngleFromDeg(13.7684),
		unit.RAFromDeg(20.6579),
		unit.AngleFromDeg(8.6964))
	fmt.Printf("χ = %.1f\n", χ.Deg())
}
Output:

χ = 285.0

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL