unit

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 3, 2018 License: MIT Imports: 1 Imported by: 161

README

Unit

Four types: Angle, HourAngle, RA, and Time, useful in astronomy applications.

These types are all angle-like types. The Time type is at least angle-related. It has conversions to and from the other types and has a function to wrap a Time value to the fractional part of a day.

Motivation

This package supports two other packages, github.com/soniakeys/sexagesimal and github.com/soniakeys/meeus. The sexagesimal package adds formatting to the four types defined here. The meeus package implements a large colection of astronomy algorithms.

Install

Go get

Technically, go get github.com/soniakeys/unit is sufficient as usual.

The tests also require the sexagesimal package, so use the -t option to prompt go get to find it as a test dependency:

go get -t github.com/soniakeys/unit
Vgo

Experimentally, you can try vgo.

To run package tests, clone the repository -- anywhere! it doesn't have to be under GOPATH -- and from the cloned directory run

vgo test

Vgo will fetch the sexagesimal test dependency as needed and run the unit package tests.

Or don't install it

If you only need unit as dependency of some other package that you are installing, the normal installation of that package will likely install unit for you. Try that first.

License

MIT

Documentation

Overview

Unit defines some types used in astronomy, and heavily used by the packages in github.com/soniakeys/meeus. Four types are currently defined, Angle, HourAngle, RA, and Time. All are commonly formatted in sexagesimal notation and the external package github.com/soniakeys/sexagesimal has formatting routines. Routines here are methods on the four types and a few other related functions.

The underlying type for these four types is simply float64. For Angle, HourAngle, and RA, the value is always in radians. For Time, it is seconds.

The choice of methods defined is somewhat arbitrary. Methods were defined as they were found convenient for the Meeus library, and then filled out somewhat for consistency. The convenience is often syntactic; as the underlying type is float64 conversions to and from float64 are often free and otherwise typically only incur a multiplication.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromSexa

func FromSexa(neg byte, d, m int, s float64) float64

FromSexa converts from parsed sexagesimal angle components to a single float64 value.

The result is in the units of d, the first or "largest" sexagesimal component.

Typically you pass non-negative values for d, m, and s, and to indicate a negative value, pass '-' for neg. Any other value, such as ' ', '+', or simply 0, leaves the result non-negative.

There are no limits on d, m, or s however. Negative values or values > 60 for m and s are allowed for example. The segment values are combined and then if neg is '-' that sum is negated.

This function would commonly be called something like DMSToDegrees, but the interpretation of d as degrees is arbitrary. The function works as well on hours minutes and seconds. Regardless of the units of d, m is a sexagesimal part of d and s is a sexagesimal part of m.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	// Typical usage:  non-negative d, m, s, and '-' to indicate negative:
	fmt.Println(unit.FromSexa('-', 20, 30, 0))
	// Putting the minus sign on d is not equivalent:
	fmt.Println(unit.FromSexa(' ', -20, 30, 0))
	fmt.Println()
	// Other combinations can give the same result though:
	fmt.Println(unit.FromSexa(' ', -20, -30, 0))
	fmt.Println(unit.FromSexa(' ', -21, 30, 0))
	fmt.Println(unit.FromSexa(' ', -22, 90, 0))
	fmt.Println(unit.FromSexa('-', 22, -90, 0))
}
Output:

-20.5
-19.5

-20.5
-20.5
-20.5
-20.5

func FromSexaSec

func FromSexaSec(neg byte, d, m int, s float64) float64

FromSexaSec converts from parsed sexagesimal angle components to a single float64 value.

The result is in the units of s, the last or "smallest" sexagesimal component.

Otherwise FromSexaSec works as FromSexa. See FromSexa.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	fmt.Println(unit.FromSexaSec(' ', 1, 0, 0))
}
Output:

3600

func PMod

func PMod(x, y float64) float64

PMod returns a positive floating-point x mod y for a positive y.

Argument x can be positive or negative, but y should be positive. With this restriction on y, PMod returns a value in the range [0,y).

The method is intended only for positive y. If y is negative, the result is not particularly useful.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	// Example numbers from the go language spec:
	fmt.Println(" x      y     x % y   PMod(x, y)")
	{
		y := 3
		for _, x := range []int{5, -5} {
			fmt.Printf("%2d %6d %7d %12.1f\n",
				x, y, x%y, unit.PMod(float64(x), float64(y)))
		}
	}
	// A more typical use:
	x := -2.5
	y := 360.
	fmt.Printf("%.1f %4.0f %20.1f\n", x, y, unit.PMod(x, y))
}
Output:

 x      y     x % y   PMod(x, y)
 5      3       2          2.0
-5      3      -2          1.0
-2.5  360                357.5

Types

type Angle

type Angle float64

Angle represents a general purpose angle.

The value is stored as radians.

There is no "AngleFromRad" constructor. If you have a value `rad` in radians, construct a corresponding Angle simply with the Go type conversion `unit.Angle(rad)`.

func AngleFromDeg

func AngleFromDeg(d float64) Angle

AngleFromDeg constructs an Angle value from a value representing angular degrees where there are 360 degrees to a circle or revolution.

This provides "Deg2Rad" functionality but hopefully in a more clear way.

Example
a := unit.AngleFromDeg(180)
fmt.Println(a)
fmt.Println(sexa.FmtAngle(a))
Output:

3.141592653589793
180°0′0″

func AngleFromMin

func AngleFromMin(m float64) Angle

AngleFromMin constructs an Angle value from a value representing angular minutes where there are 60 minutes to a degree, and 360 degrees to a circle.

Example
a := unit.AngleFromMin(83)
fmt.Println(sexa.FmtAngle(a))
Output:

1°23′0″

func AngleFromSec

func AngleFromSec(s float64) Angle

AngleFromSec constructs an Angle value from a value representing angular seconds where there are 60 seconds to a minute, 60 minutes to a degree, and 360 degrees to a circle.

Example
a := unit.AngleFromSec(83)
fmt.Println(sexa.FmtAngle(a))
Output:

1′23″

func NewAngle

func NewAngle(neg byte, d, m int, s float64) Angle

NewAngle constructs a new Angle value from sign, degree, minute, and second components.

For argument neg, pass '-' to negate the result. Any other argument value, such as ' ', '+', or simply 0, leaves the result non-negated.

Example
fmt.Println(sexa.FmtAngle(unit.NewAngle('-', 0, 32, 41)))
fmt.Println(sexa.FmtAngle(unit.NewAngle(' ', 0, 32, 41)))
fmt.Println(sexa.FmtAngle(unit.NewAngle('+', 0, 32, 41)))
fmt.Println(sexa.FmtAngle(unit.NewAngle(0, 0, 32, 41)))
Output:

-32′41″
32′41″
32′41″
32′41″

func (Angle) Cos

func (a Angle) Cos() float64

Cos returns the trigonometric cosine of a.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.AngleFromDeg(60)
	fmt.Printf("%f\n", a.Cos())
}
Output:

0.500000

func (Angle) Deg

func (a Angle) Deg() float64

Deg returns the angle in degrees.

This provides a "Rad2Deg" functionality but hopefully in a more clear way.

Example
package main

import (
	"fmt"
	"math"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.Angle(math.Pi / 2)
	fmt.Println(a.Deg())
}
Output:

90

func (Angle) Div

func (a Angle) Div(d float64) Angle

Div returns the scalar quotient a/d

Example
a := unit.AngleFromDeg(90)
fmt.Println(sexa.FmtAngle(a.Div(2)))
Output:

45°0′0″

func (Angle) HourAngle

func (a Angle) HourAngle() HourAngle

HourAngle constructs an HourAngle value corresponding to angle a.

As both types represent angles in radians, this is a zero-cost conversion.

Example
a := unit.AngleFromDeg(-30)
fmt.Println(sexa.FmtAngle(a))
fmt.Println(sexa.FmtHourAngle(a.HourAngle()))
Output:

-30°0′0″
-2ʰ0ᵐ0ˢ

func (Angle) Min

func (a Angle) Min() float64

Min returns the angle in minutes.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.NewAngle(' ', 1, 23, 0)
	fmt.Printf("%f\n", a.Min())
}
Output:

83.000000

func (Angle) Mod1

func (a Angle) Mod1() Angle

Mod1 returns Angle a wrapped to 1 circle.

Example
fmt.Println(sexa.FmtAngle(unit.AngleFromDeg(23).Mod1()))
fmt.Println(sexa.FmtAngle(unit.AngleFromDeg(383).Mod1()))
fmt.Println(sexa.FmtAngle(unit.AngleFromDeg(-337).Mod1()))
Output:

23°0′0″
23°0′0″
23°0′0″

func (Angle) Mul

func (a Angle) Mul(f float64) Angle

Mul returns the scalar product a*f

Example
a := unit.AngleFromDeg(45)
fmt.Println(sexa.FmtAngle(a.Mul(2)))
Output:

90°0′0″

func (Angle) RA

func (a Angle) RA() RA

RA constructs an RA value corresponding to angle a.

As usual for right ascension, the value is wrapped to the range [0,24h).

Example
a := unit.AngleFromDeg(-30)
fmt.Println(sexa.FmtAngle(a))
fmt.Println(sexa.FmtRA(a.RA()))
Output:

-30°0′0″
22ʰ0ᵐ0ˢ

func (Angle) Rad

func (a Angle) Rad() float64

Rad returns the angle in radians.

This is the underlying representation and involves no scaling.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.NewAngle(' ', 180, 0, 0) // conversion to radians happens here
	fmt.Println(a.Rad())               // no cost to access radians here
}
Output:

3.141592653589793

func (Angle) Sec

func (a Angle) Sec() float64

Sec returns the angle in seconds.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.NewAngle(' ', 0, 1, 23)
	fmt.Printf("%f\n", a.Sec())
}
Output:

83.000000

func (Angle) Sin

func (a Angle) Sin() float64

Sin returns the trigonometric sine of a.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.AngleFromDeg(60)
	fmt.Printf("%f\n", a.Sin())
}
Output:

0.866025

func (Angle) Sincos

func (a Angle) Sincos() (float64, float64)

Sincos returns the trigonometric sine and cosine of a.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.AngleFromDeg(60)
	s, c := a.Sincos()
	fmt.Printf("%f  %f\n", s, c)
}
Output:

0.866025  0.500000

func (Angle) Tan

func (a Angle) Tan() float64

Tan returns the trigonometric tangent of a.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.AngleFromDeg(60)
	fmt.Printf("%f\n", a.Tan())
}
Output:

1.732051

func (Angle) Time

func (a Angle) Time() Time

Time constructs a Time value where one circle of Angle corresponds to one day of Time.

Example
a := unit.AngleFromDeg(-30)
fmt.Println(sexa.FmtAngle(a))
fmt.Println(sexa.FmtTime(a.Time()))
Output:

-30°0′0″
-2ʰ0ᵐ0ˢ

type HourAngle

type HourAngle float64

HourAngle represents an angle corresponding to angular rotation of the Earth.

The value is stored as radians.

func HourAngleFromHour

func HourAngleFromHour(h float64) HourAngle

HourAngleFromHour constructs an HourAngle value from a value representing hours of rotation or revolution where there are 24 hours to a revolution.

Example
h := unit.HourAngleFromHour(12)
fmt.Println(h)
fmt.Println(sexa.FmtHourAngle(h))
fmt.Println(sexa.FmtHourAngle(unit.HourAngleFromHour(-2)))
Output:

3.141592653589793
12ʰ0ᵐ0ˢ
-2ʰ0ᵐ0ˢ

func HourAngleFromMin

func HourAngleFromMin(m float64) HourAngle

HourAngleFromMin constructs an HourAngle value from a value representing minutes of revolution where there are 60 minutes to an hour and 24 hours to a revolution.

Example
fmt.Println(sexa.FmtHourAngle(unit.HourAngleFromMin(-83)))
Output:

-1ʰ23ᵐ0ˢ

func HourAngleFromSec

func HourAngleFromSec(s float64) HourAngle

HourAngleFromSec constructs an HourAngle value from a value representing seconds of revolution where there are 60 seconds to a minute, 60 minutes to an hour, and 24 hours to a revolution.

Example
fmt.Println(sexa.FmtHourAngle(unit.HourAngleFromSec(-83)))
Output:

-1ᵐ23ˢ

func NewHourAngle

func NewHourAngle(neg byte, h, m int, s float64) HourAngle

NewHourAngle constructs a new HourAngle value from sign, hour, minute, and second components.

For argument neg, pass '-' to indicate a negative hour angle. Any other argument value, such as ' ', '+', or simply 0, leaves the result non-negative.

Example
fmt.Println(sexa.FmtHourAngle(unit.NewHourAngle(' ', 0, 32, 41)))
Output:

32ᵐ41ˢ

func (HourAngle) Angle

func (h HourAngle) Angle() Angle

Angle returns an Angle value where one revolution or 24 hours of HourAngle corresponds to one circle of Angle.

Example
h := unit.HourAngleFromHour(-2)
fmt.Println(sexa.FmtHourAngle(h))
fmt.Println(sexa.FmtAngle(h.Angle()))
Output:

-2ʰ0ᵐ0ˢ
-30°0′0″

func (HourAngle) Cos

func (h HourAngle) Cos() float64

Cos returns the trigonometric cosine of h.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	h := unit.HourAngleFromHour(4)
	fmt.Printf("%f\n", h.Cos())
}
Output:

0.500000

func (HourAngle) Div

func (h HourAngle) Div(f float64) HourAngle

Div returns the scalar quotient h/f

Example
h := unit.HourAngleFromHour(6)
fmt.Println(sexa.FmtHourAngle(h.Div(2)))
Output:

3ʰ0ᵐ0ˢ

func (HourAngle) Hour

func (h HourAngle) Hour() float64

Hour returns the hour angle as hours of revolution.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	h := unit.NewHourAngle(' ', 1, 30, 0)
	fmt.Println(h.Hour())
}
Output:

1.5

func (HourAngle) Min

func (h HourAngle) Min() float64

Min returns the hour angle as minutes of revolution.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	h := unit.NewHourAngle(' ', 1, 23, 0)
	fmt.Printf("%f\n", h.Min())
}
Output:

83.000000

func (HourAngle) Mul

func (h HourAngle) Mul(f float64) HourAngle

Mul returns the scalar product h*f

Example
h := unit.HourAngleFromHour(3)
fmt.Println(sexa.FmtHourAngle(h.Mul(2)))
Output:

6ʰ0ᵐ0ˢ

func (HourAngle) RA

func (h HourAngle) RA() RA

RA returns an RA value corresponding to h but wrapped to the range [0,24h).

Example
h := unit.HourAngleFromHour(-2)
fmt.Println(sexa.FmtHourAngle(h))
fmt.Println(sexa.FmtRA(h.RA()))
Output:

-2ʰ0ᵐ0ˢ
22ʰ0ᵐ0ˢ

func (HourAngle) Rad

func (h HourAngle) Rad() float64

Rad returns the hour angle as an angle in radians.

This is the underlying representation and involves no scaling.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.NewHourAngle(' ', 12, 0, 0) // conversion to radians happens here
	fmt.Println(a.Rad())                  // no cost to access radians here
}
Output:

3.141592653589793

func (HourAngle) Sec

func (h HourAngle) Sec() float64

Sec returns the hour angle as seconds of revolution.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	a := unit.NewHourAngle(' ', 0, 1, 23)
	fmt.Printf("%f\n", a.Sec())
}
Output:

83.000000

func (HourAngle) Sin

func (h HourAngle) Sin() float64

Sin returns the trigonometric sine of h.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	h := unit.HourAngleFromHour(4)
	fmt.Printf("%f\n", h.Sin())
}
Output:

0.866025

func (HourAngle) Sincos

func (h HourAngle) Sincos() (float64, float64)

Sincos returns the trigonometric sine and cosine of h.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	h := unit.HourAngleFromHour(4)
	s, c := h.Sincos()
	fmt.Printf("%f  %f\n", s, c)
}
Output:

0.866025  0.500000

func (HourAngle) Tan

func (h HourAngle) Tan() float64

Tan returns the trigonometric tangent of h.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	h := unit.HourAngleFromHour(4)
	fmt.Printf("%f\n", h.Tan())
}
Output:

1.732051

func (HourAngle) Time

func (h HourAngle) Time() Time

Time returns a Time value where one revolution or 24 hours or HourAngle corresponds to one day of Time.

Example
h := unit.HourAngleFromHour(-2)
fmt.Println(sexa.FmtHourAngle(h))
fmt.Println(sexa.FmtTime(h.Time()))
Output:

-2ʰ0ᵐ0ˢ
-2ʰ0ᵐ0ˢ

type RA

type RA float64

RA represents a value of right ascension.

The value is stored as radians.

func NewRA

func NewRA(h, m int, s float64) RA

NewRA constructs a new RA value from hour, minute, and second components.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
r := unit.NewRA(9, 14, 55.8) // converts to radians
fmt.Println(r)               // radians, native representation
fmt.Println(r.Hour())        // hours, just scaled from radians
fmt.Println(sexa.FmtRA(r))   // sexagesimal
Output:

2.4213389045230334
9.248833333333334
9ʰ14ᵐ56ˢ

func RAFromDeg

func RAFromDeg(d float64) RA

RAFromDeg constructs an RA value from a value representing degrees of right ascension where there are 360 degrees to a circle or revolution.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
fmt.Println(sexa.FmtRA(unit.RAFromDeg(-30)))
Output:

22ʰ0ᵐ0ˢ

func RAFromHour

func RAFromHour(h float64) RA

RAFromHour constructs an RA value from a value representing hours of RA where there are 24 hours to a revolution.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
fmt.Println(sexa.FmtRA(unit.RAFromHour(-2)))
Output:

22ʰ0ᵐ0ˢ

func RAFromMin

func RAFromMin(m float64) RA

RAFromMin constructs an RA value from a value representing minutes of RA where there are 60 minutes to an hour and 24 hours to a revolution.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
fmt.Println(sexa.FmtRA(unit.RAFromMin(83)))
Output:

1ʰ23ᵐ0ˢ

func RAFromRad

func RAFromRad(rad float64) RA

RAFromRad constructs a new RA value from radians.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
fmt.Println(sexa.FmtRA(unit.RAFromRad(math.Pi)))
Output:

12ʰ0ᵐ0ˢ

func RAFromSec

func RAFromSec(s float64) RA

RAFromSec constructs an RA value from a value representing seconds of RA where there are 60 seconds to a minute, 60 minutes to an hour, and 24 hours to a revolution.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
fmt.Println(sexa.FmtRA(unit.RAFromSec(83)))
Output:

1ᵐ23ˢ

func (RA) Add

func (ra RA) Add(h HourAngle) RA

Add adds hour angle h to RA ra giving a new RA value.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
r := unit.RAFromHour(22)
fmt.Println(sexa.FmtRA(r.Add(unit.HourAngleFromHour(4))))
Output:

2ʰ0ᵐ0ˢ

func (RA) Angle

func (ra RA) Angle() Angle

Angle returns an Angle value where 24 hours or one revolution of RA corresponds to one circle of Angle.

As both types represent angles in radians, this is a zero-cost conversion.

Example
r := unit.RAFromHour(2)
fmt.Println(sexa.FmtRA(r))
fmt.Println(sexa.FmtAngle(r.Angle()))
Output:

2ʰ0ᵐ0ˢ
30°0′0″

func (RA) Cos

func (ra RA) Cos() float64

Cos returns the trigonometric cosine of ra.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	h := unit.RAFromHour(4)
	fmt.Printf("%f\n", h.Cos())
}
Output:

0.500000

func (RA) Deg

func (ra RA) Deg() float64

Deg returns the RA as degrees of RA.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.RAFromHour(2)
	fmt.Printf("%f\n", r.Deg())
}
Output:

30.000000

func (RA) Hour

func (ra RA) Hour() float64

Hour returns the RA as hours of RA.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.NewRA(1, 30, 0)
	fmt.Println(r.Hour())
}
Output:

1.5

func (RA) HourAngle

func (ra RA) HourAngle() HourAngle

HourAngle constructs an HourAngle value corresponding to RA ra.

As both types represent angles in radians, this is a zero-cost conversion.

Example
r := unit.RAFromHour(2)
fmt.Println(sexa.FmtRA(r))
fmt.Println(sexa.FmtHourAngle(r.HourAngle()))
Output:

2ʰ0ᵐ0ˢ
2ʰ0ᵐ0ˢ

func (RA) Min

func (ra RA) Min() float64

Min returns the RA as minutes of RA.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.NewRA(1, 23, 0)
	fmt.Printf("%f\n", r.Min())
}
Output:

83.000000

func (RA) Rad

func (ra RA) Rad() float64

Rad returns the RA as an angle in radians.

This is the underlying representation and involves no scaling.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.NewRA(12, 0, 0) // conversion to radians happens here
	fmt.Println(r.Rad())      // no cost to access radians here
}
Output:

3.141592653589793

func (RA) Sec

func (ra RA) Sec() float64

Sec returns the RA as seconds of RA.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.NewRA(0, 1, 23)
	fmt.Printf("%f\n", r.Sec())
}
Output:

83.000000

func (RA) Sin

func (ra RA) Sin() float64

Sin returns the trigonometric sine of ra.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.RAFromHour(4)
	fmt.Printf("%f\n", r.Sin())
}
Output:

0.866025

func (RA) Sincos

func (ra RA) Sincos() (float64, float64)

Sincos returns the trigonometric sine and cosineof ra.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.RAFromHour(4)
	s, c := r.Sincos()
	fmt.Printf("%f  %f\n", s, c)
}
Output:

0.866025  0.500000

func (RA) Tan

func (ra RA) Tan() float64

Tan returns the trigonometric tangent of ra.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	r := unit.RAFromHour(4)
	fmt.Printf("%f\n", r.Tan())
}
Output:

1.732051

func (RA) Time

func (ra RA) Time() Time

Time constructs a Time value where 24 hours or one revolution of RA corresponds to one day of Time.

Example
r := unit.RAFromHour(2)
fmt.Println(sexa.FmtRA(r))
fmt.Println(sexa.FmtTime(r.Time()))
Output:

2ʰ0ᵐ0ˢ
2ʰ0ᵐ0ˢ

type Time

type Time float64

Time represents a duration or relative time.

The value is stored as seconds.

There is no "TimeFromSec" constructor. If you have a value `sec` in seconds, construct a corresponding Time value simply with the Go type conversion `unit.Time(sec)`.

Example
t := unit.Time(1.23)
fmt.Println(t)
fmt.Printf("%.2s\n", sexa.FmtTime(t))
Output:

1.23
1.23ˢ

func NewTime

func NewTime(neg byte, h, m int, s float64) Time

NewTime constructs a new Time value from sign, hour, minute, and second components.

For argument neg, pass '-' to indicate a negative time such as a negative delta. Any other argument value, such as ' ', '+', or simply 0, leaves the result non-negative.

Example
t := unit.NewTime('-', 12, 34, 45.6)
fmt.Println(sexa.FmtTime(t))
Output:

-12ʰ34ᵐ46ˢ

func TimeFromDay

func TimeFromDay(d float64) Time

TimeFromDay constructs a Time value from a value representing days.

Example
t := unit.TimeFromDay(1)
fmt.Println(t)
fmt.Println(sexa.FmtTime(t))
Output:

86400
24ʰ0ᵐ0ˢ

func TimeFromHour

func TimeFromHour(h float64) Time

TimeFromHour constructs a Time value from a value representing hours of time.

Example
t := unit.TimeFromHour(-1)
fmt.Println(t)
fmt.Println(sexa.FmtTime(t))
Output:

-3600
-1ʰ0ᵐ0ˢ

func TimeFromMin

func TimeFromMin(m float64) Time

TimeFromMin constructs a Time value from a value representing minutes of time.

Example
fmt.Println(sexa.FmtTime(unit.TimeFromMin(.5)))
Output:

30ˢ

func TimeFromRad

func TimeFromRad(rad float64) Time

TimeFromRad constructs a Time value from radians where 2 pi radians corresponds to one day.

Example
t := unit.TimeFromRad(math.Pi)
fmt.Println(sexa.FmtTime(t))
Output:

12ʰ0ᵐ0ˢ

func (Time) Angle

func (t Time) Angle() Angle

Angle returns time t as an equivalent angle where 1 day = 2 Pi radians.

Example
t := unit.TimeFromHour(-2)
fmt.Println(sexa.FmtTime(t))
fmt.Println(sexa.FmtAngle(t.Angle()))
Output:

-2ʰ0ᵐ0ˢ
-30°0′0″

func (Time) Day

func (t Time) Day() float64

Day returns time in days.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	t := unit.NewTime(0, 48, 36, 0)
	fmt.Println(t.Day())
}
Output:

2.025

func (Time) Div

func (t Time) Div(d float64) Time

Div returns the scalar quotient t/d

Example
t := unit.TimeFromHour(6)
fmt.Println(sexa.FmtTime(t.Div(2)))
Output:

3ʰ0ᵐ0ˢ

func (Time) Hour

func (t Time) Hour() float64

Hour returns time in hours.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	t := unit.NewTime(0, 2, 15, 0)
	fmt.Println(t.Hour())
}
Output:

2.25

func (Time) HourAngle

func (t Time) HourAngle() HourAngle

HourAngle returns time t as an equivalent hour angle where 1 day = 2 Pi radians or 24 hours of HourAngle.

Example
t := unit.TimeFromHour(-1.5)
fmt.Println(sexa.FmtHourAngle(t.HourAngle()))
Output:

-1ʰ30ᵐ0ˢ

func (Time) Min

func (t Time) Min() float64

Min returns time in minutes.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	t := unit.NewTime(0, 0, 1, 30)
	fmt.Println(t.Min())
}
Output:

1.5

func (Time) Mod1

func (t Time) Mod1() Time

Mod1 returns a new Time wrapped to one day, the range [0,86400) seconds.

Example
t := unit.TimeFromHour(25)
fmt.Println(t)
fmt.Println(t.Mod1())
fmt.Println(sexa.FmtTime(t.Mod1()))
Output:

90000
3600
1ʰ0ᵐ0ˢ

func (Time) Mul

func (t Time) Mul(f float64) Time

Mul returns the scalar product t*f

Example
t := unit.TimeFromHour(3)
fmt.Println(sexa.FmtTime(t.Mul(2)))
Output:

6ʰ0ᵐ0ˢ

func (Time) RA

func (t Time) RA() RA

RA returns time t as an equivalent RA where 1 day = 24 hours of RA.

The result is wrapped to the range [0,2π), or [0,24) hours.

Example
t := unit.TimeFromHour(-2)
fmt.Println(sexa.FmtTime(t))
fmt.Println(sexa.FmtRA(t.RA()))
Output:

-2ʰ0ᵐ0ˢ
22ʰ0ᵐ0ˢ

func (Time) Rad

func (t Time) Rad() float64

Rad returns time in radians, where 1 day = 2 Pi radians of rotation.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	t := unit.NewTime(0, 12, 0, 0)
	fmt.Println(t.Rad())
}
Output:

3.141592653589793

func (Time) Sec

func (t Time) Sec() float64

Sec returns the time in seconds.

This is the underlying representation and involves no scaling.

Example
package main

import (
	"fmt"

	"github.com/soniakeys/unit"
)

func main() {
	t := unit.NewTime(0, 0, 1, 30)
	fmt.Println(t.Sec())
}
Output:

90

Jump to

Keyboard shortcuts

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