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 ¶
- func FromSexa(neg byte, d, m int, s float64) float64
- func FromSexaSec(neg byte, d, m int, s float64) float64
- func PMod(x, y float64) float64
- type Angle
- func (a Angle) Cos() float64
- func (a Angle) Deg() float64
- func (a Angle) Div(d float64) Angle
- func (a Angle) HourAngle() HourAngle
- func (a Angle) Min() float64
- func (a Angle) Mod1() Angle
- func (a Angle) Mul(f float64) Angle
- func (a Angle) RA() RA
- func (a Angle) Rad() float64
- func (a Angle) Sec() float64
- func (a Angle) Sin() float64
- func (a Angle) Sincos() (float64, float64)
- func (a Angle) Tan() float64
- func (a Angle) Time() Time
- type HourAngle
- func (h HourAngle) Angle() Angle
- func (h HourAngle) Cos() float64
- func (h HourAngle) Div(f float64) HourAngle
- func (h HourAngle) Hour() float64
- func (h HourAngle) Min() float64
- func (h HourAngle) Mul(f float64) HourAngle
- func (h HourAngle) RA() RA
- func (h HourAngle) Rad() float64
- func (h HourAngle) Sec() float64
- func (h HourAngle) Sin() float64
- func (h HourAngle) Sincos() (float64, float64)
- func (h HourAngle) Tan() float64
- func (h HourAngle) Time() Time
- type RA
- func (ra RA) Add(h HourAngle) RA
- func (ra RA) Angle() Angle
- func (ra RA) Cos() float64
- func (ra RA) Deg() float64
- func (ra RA) Hour() float64
- func (ra RA) HourAngle() HourAngle
- func (ra RA) Min() float64
- func (ra RA) Rad() float64
- func (ra RA) Sec() float64
- func (ra RA) Sin() float64
- func (ra RA) Sincos() (float64, float64)
- func (ra RA) Tan() float64
- func (ra RA) Time() Time
- type Time
- func (t Time) Angle() Angle
- func (t Time) Day() float64
- func (t Time) Div(d float64) Time
- func (t Time) Hour() float64
- func (t Time) HourAngle() HourAngle
- func (t Time) Min() float64
- func (t Time) Mod1() Time
- func (t Time) Mul(f float64) Time
- func (t Time) RA() RA
- func (t Time) Rad() float64
- func (t Time) Sec() float64
Examples ¶
- Angle.Cos
- Angle.Deg
- Angle.Div
- Angle.HourAngle
- Angle.Min
- Angle.Mod1
- Angle.Mul
- Angle.RA
- Angle.Rad
- Angle.Sec
- Angle.Sin
- Angle.Sincos
- Angle.Tan
- Angle.Time
- AngleFromDeg
- AngleFromMin
- AngleFromSec
- FromSexa
- FromSexaSec
- HourAngle.Angle
- HourAngle.Cos
- HourAngle.Div
- HourAngle.Hour
- HourAngle.Min
- HourAngle.Mul
- HourAngle.RA
- HourAngle.Rad
- HourAngle.Sec
- HourAngle.Sin
- HourAngle.Sincos
- HourAngle.Tan
- HourAngle.Time
- HourAngleFromHour
- HourAngleFromMin
- HourAngleFromSec
- NewAngle
- NewHourAngle
- NewRA
- NewTime
- PMod
- RA.Add
- RA.Angle
- RA.Cos
- RA.Deg
- RA.Hour
- RA.HourAngle
- RA.Min
- RA.Rad
- RA.Sec
- RA.Sin
- RA.Sincos
- RA.Tan
- RA.Time
- RAFromDeg
- RAFromHour
- RAFromMin
- RAFromRad
- RAFromSec
- Time
- Time.Angle
- Time.Day
- Time.Div
- Time.Hour
- Time.HourAngle
- Time.Min
- Time.Mod1
- Time.Mul
- Time.RA
- Time.Rad
- Time.Sec
- TimeFromDay
- TimeFromHour
- TimeFromMin
- TimeFromRad
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromSexa ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
type HourAngle ¶
type HourAngle float64
HourAngle represents an angle corresponding to angular rotation of the Earth.
The value is stored as radians.
func HourAngleFromHour ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
type RA ¶
type RA float64
RA represents a value of right ascension.
The value is stored as radians.
func NewRA ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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
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 ¶
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 ¶
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 ¶
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 ¶
TimeFromMin constructs a Time value from a value representing minutes of time.
Example ¶
fmt.Println(sexa.FmtTime(unit.TimeFromMin(.5)))
Output: 30ˢ
func TimeFromRad ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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 ¶
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ˢ