pub struct Period(/* private fields */);Expand description
Angles and Time are the most prominent use for this type
| Property | To Method | From Method |
|---|---|---|
| Degrees (Decimal) | Period::degrees() | Period::from_degrees() |
| Radians | Period::radians() | Period::from_radians() |
| Turns ([0,1]) | Period::turns() | Period::from_turns() |
| Hours (Decimal) | Period::decimal() | Period::from_decimal() |
| Clock Time | Period::clock() | Period::from_clock() |
| Degrees (DMS) | Period::degminsec() | Period::from_degminsec() |
| Sine | Period::sin() | Period::asin() |
| Cosine | Period::cos() | Period::acos() |
| Tangent | Period::tan() | Period::atan2() |
Additional Methods:
- Latitude displaying:
Period::to_latitude() - GST Correction:
Period::gst()andPeriod::ungst() - Inverse of angle:
Period::inverse()
Implementations§
Source§impl Period
impl Period
Sourcepub const fn radians(self) -> f64
pub const fn radians(self) -> f64
Returns the angle as radians.
This is the only function that should directly access the fields of the type.
use pracstro::time::Period;
Period::from_degrees(180.0).radians(); // PiSourcepub const fn from_radians(x: f64) -> Self
pub const fn from_radians(x: f64) -> Self
Constructs a angle from radians, reducing it to the range of [0, 2*PI].
This is the one of the two only functions that directly access Period.
Reduction to the desired range is done with Least Positive Residue instead of the remainder operator.
use pracstro::time::Period;
Period::from_radians(std::f64::consts::PI).degrees(); // 180.0Sourcepub const fn to_latitude(self) -> Self
pub const fn to_latitude(self) -> Self
Converts angles internally so that formatting them as latitudes makes sense
This should be used directly in conjunction with a formatting function.
The main use case for this is in coordinate handling where angles of latitude can be negative.
This is the only other function that should be able to directly access Period than Period::from_radians().
use pracstro::time::Period;
Period::from_degrees(-25.0).degrees(); // 335.0
Period::from_degrees(-25.0).to_latitude().degrees(); // -25.0Examples found in repository?
More examples
3fn main() {
4 let now = time::Date::now();
5 for p in sol::PLANETS {
6 let (ra, de) = p.location(now).equatorial();
7 let ((rah, ram, _), (ded, dem, _)) = (ra.clock(), de.to_latitude().degminsec());
8 println!(
9 "{:<10} {:>2}h{:02} RA {:>3}°{:02}' De {:.2} AU",
10 p.name,
11 rah,
12 ram,
13 ded,
14 dem,
15 p.distance(now)
16 );
17 }
18}Sourcepub const fn degrees(self) -> f64
pub const fn degrees(self) -> f64
Returns the angle as fractional degrees.
A wrapper around f64::to_degrees()
use pracstro::time::Period;
Period::from_degrees(-25.0).degrees(); // 335.0Sourcepub const fn from_degrees(x: f64) -> Self
pub const fn from_degrees(x: f64) -> Self
Constructs an angle from fractional degrees.
A wrapper around f64::to_radians()
use pracstro::time::Period;
Period::from_degrees(-25.0).degrees(); // 335.0Sourcepub const fn turns(self) -> f64
pub const fn turns(self) -> f64
Returns the angle in the range between 0 and 1 (i.e. turns)
Used in the calculation for the illuminated fraction of planets
Sourcepub const fn from_turns(x: f64) -> Self
pub const fn from_turns(x: f64) -> Self
Constructs an angle from a value between 0 and 1
Used in the calculation for the illuminated fraction of planets
Sourcepub const fn decimal(self) -> f64
pub const fn decimal(self) -> f64
Returns the angle in fractional number of hours
A wrapper around Period::degrees() and one division by 15. Since one hour is 15 degrees of rotation
use pracstro::time::Period;
Period::from_degrees(120.0).decimal(); // 8.0Sourcepub const fn from_decimal(x: f64) -> Self
pub const fn from_decimal(x: f64) -> Self
Constructs an angle from a fractional number of hours
A wrapper around Period::from_degrees() and one multiplication by 15. Since one hour is 15 degrees of rotation
use pracstro::time::Period;
Period::from_decimal(8.0).degrees(); // 120.00Sourcepub fn clock(self) -> (u8, u8, f64)
pub fn clock(self) -> (u8, u8, f64)
Returns (Hour, Minute, Second) of a time/angle
Used in hour-angle displays for some coordinate systems, and in times.
use pracstro::time::Period;
Period::from_decimal(8.0).clock(); // (8, 0, 0.0)Examples found in repository?
More examples
3fn main() {
4 let now = time::Date::now();
5 for p in sol::PLANETS {
6 let (ra, de) = p.location(now).equatorial();
7 let ((rah, ram, _), (ded, dem, _)) = (ra.clock(), de.to_latitude().degminsec());
8 println!(
9 "{:<10} {:>2}h{:02} RA {:>3}°{:02}' De {:.2} AU",
10 p.name,
11 rah,
12 ram,
13 ded,
14 dem,
15 p.distance(now)
16 );
17 }
18}Sourcepub fn from_clock(h: u8, m: u8, s: f64) -> Self
pub fn from_clock(h: u8, m: u8, s: f64) -> Self
Constructs an angle out of an hour, minute, and second
Used in hour-angle displays for some coordinate systems, and in times.
use pracstro::time::Period;
Period::from_clock(8, 0, 0.0).decimal(); // 8.0Sourcepub fn degminsec(self) -> (i16, u8, f64)
pub fn degminsec(self) -> (i16, u8, f64)
Converts an angle to a degree with arcminutes and arcseconds
Examples found in repository?
More examples
3fn main() {
4 let now = time::Date::now();
5 for p in sol::PLANETS {
6 let (ra, de) = p.location(now).equatorial();
7 let ((rah, ram, _), (ded, dem, _)) = (ra.clock(), de.to_latitude().degminsec());
8 println!(
9 "{:<10} {:>2}h{:02} RA {:>3}°{:02}' De {:.2} AU",
10 p.name,
11 rah,
12 ram,
13 ded,
14 dem,
15 p.distance(now)
16 );
17 }
18}Sourcepub fn from_degminsec(d: i16, m: u8, s: f64) -> Self
pub fn from_degminsec(d: i16, m: u8, s: f64) -> Self
Identical to from_clock in math
Sourcepub fn gst(self, date: Date) -> Self
pub fn gst(self, date: Date) -> Self
Handles the discontinuity created by the orbit of the earth as compared to its rotation.
Algorithm from Practical Astronomy with Your Calculator, although similar algorithms exist in other sources
Sourcepub fn ungst(self, date: Date) -> Self
pub fn ungst(self, date: Date) -> Self
Handles the discontinuity created by the orbit of the earth as compared to its rotation.
Algorithm from Practical Astronomy with Your Calculator, although similar algorithms exist in other sources
Sourcepub fn hourangle_rightas(self, date: Date, time: Period, longi: Period) -> Self
pub fn hourangle_rightas(self, date: Date, time: Period, longi: Period) -> Self
Gets the hour angle from the angle as if it were a right ascension, and vice versa.
Used in horizontal coordinates.