pub enum Angle {
    Degree(f64),
    Radian(f64),
    Hour(f64),
}
Expand description

Enum containing common angle variants

Variants§

§

Degree(f64)

Variant containing decimal degree

§

Radian(f64)

Variant containing decimal radian

§

Hour(f64)

Variant containing decimal hour

Implementations§

Convert to decimal degree

Examples found in repository?
src/angle.rs (line 161)
160
161
162
    fn from(angle: Angle) -> Self {
        Self::angle_to_ams(angle.to_deg())
    }

Convert to decimal radian

Examples found in repository?
src/angle.rs (line 65)
64
65
66
67
68
69
70
71
72
    pub fn sin(&self) -> f64 {
        Self::to_rad(self).sin()
    }
    pub fn cos(&self) -> f64 {
        Self::to_rad(self).cos()
    }
    pub fn tan(&self) -> f64 {
        Self::to_rad(self).tan()
    }
More examples
Hide additional examples
src/coord.rs (line 28)
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
    fn new(angle: &Angle) -> Self {
        let rad = angle.to_rad();
        if !(0.0..=PI).contains(&rad) {
            panic!("ZenithAngle must be between 0 and pi!")
        }
        Self(*angle)
    }
    fn value(&self) -> Angle {
        self.0
    }
}

/**
Declination

<https://en.wikipedia.org/wiki/Declination>
 */
#[derive(Debug, Copy, Clone)]
pub struct Declination(pub Angle);

impl ConstrainedAngle for Declination {
    fn new(angle: &Angle) -> Self {
        let rad = angle.to_rad();
        if !(-PI_HALF..=PI_HALF).contains(&rad) {
            panic!("Declination must be between -pi/2 and pi/2!")
        }
        Self(*angle)
    }
    fn value(&self) -> Angle {
        self.0
    }
}

/**
Altitude

<https://en.wikipedia.org/wiki/Horizontal_coordinate_system>
 */
#[derive(Debug, Copy, Clone)]
pub struct Altitude(pub Angle);

impl ConstrainedAngle for Altitude {
    fn new(angle: &Angle) -> Self {
        let rad = angle.to_rad();
        if !(-PI_HALF..=PI_HALF).contains(&rad) {
            panic!("Altitude must be between -pi/2 and pi/2!")
        }
        Self(*angle)
    }
    fn value(&self) -> Angle {
        self.0
    }
}

/**
Latitude

<https://en.wikipedia.org/wiki/Latitude>
 */
#[derive(Debug, Copy, Clone)]
pub struct Latitude(pub Angle);

impl ConstrainedAngle for Latitude {
    fn new(angle: &Angle) -> Self {
        let rad = angle.to_rad();
        if !(-PI_HALF..=PI_HALF).contains(&rad) {
            panic!("Latitude must be between -pi/2 and pi/2!")
        }
        Self(*angle)
    }
    fn value(&self) -> Angle {
        self.0
    }
}

/**
Right Ascension

<https://en.wikipedia.org/wiki/Right_ascension>
 */
#[derive(Debug, Copy, Clone)]
pub struct RightAscension(pub Angle);

/**
Azimuth

<https://en.wikipedia.org/wiki/Azimuth>
 */
#[derive(Debug, Copy, Clone)]
pub struct Azimuth(pub Angle);

/**
Longitude

<https://en.wikipedia.org/wiki/Longitude>
 */
#[derive(Debug, Copy, Clone)]
pub struct Longitude(pub Angle);

/**
Cartesian Coordinates

<https://en.wikipedia.org/wiki/Cartesian_coordinate_system>
 */
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub struct Cartesian {
    pub x: f64,
    pub y: f64,
    pub z: f64,
}

/**
Geographic Coordinates (Latitude/Longitude)

<https://en.wikipedia.org/wiki/Geographic_coordinate_system>
 */
#[derive(Debug, Copy, Clone)]
pub struct Geographic {
    pub latitude: Latitude,
    pub longitude: Longitude,
}

/**
Two-dimensional Polar Coordinates

<https://en.wikipedia.org/wiki/Polar_coordinate_system>
 */
#[derive(Debug, Copy, Clone)]
#[allow(dead_code)]
pub struct Polar {
    pub radius: f64,
    pub angle: Angle,
}

/**
Equitorial Astronomical Coordinates

<https://en.wikipedia.org/wiki/Astronomical_coordinate_systems#Equatorial_system>
 */
#[derive(Debug, Copy, Clone)]
pub struct Equitorial {
    pub right_ascension: RightAscension,
    pub declination: Declination,
}

/**
Horizontal Astronomical Coordinates

<https://en.wikipedia.org/wiki/Astronomical_coordinate_systems#Horizontal_system>
 */
#[derive(Debug, Copy, Clone)]
pub struct Horizontal {
    pub altitude: Altitude,
    pub azimuth: Azimuth,
}

impl Horizontal {
    /**
    Convert equitorial coordinates to horizontal given a place and time.

    <https://en.wikipedia.org/wiki/Astronomical_coordinate_systems#Equatorial_%E2%86%94_horizontal>
     */
    pub fn from_equitorial(eq: &Equitorial, geo: &Geographic, sidereal_time: &GMST) -> Self {
        let hour_local: Angle = sidereal_time.0 + geo.longitude.0 - eq.right_ascension.0;
        let x_horiz: f64 = -(geo.latitude.0.sin()) * (eq.declination.0.cos()) * (hour_local.cos())
            + geo.latitude.0.cos() * (eq.declination.0.sin());
        let y_horiz: f64 = eq.declination.0.cos() * hour_local.sin();
        let azimuth_rad: Angle = Angle::Radian(-(y_horiz.atan2(x_horiz)));
        let altitude_rad: Angle = Angle::Radian(
            (geo.latitude.0.sin() * eq.declination.0.sin()
                + geo.latitude.0.cos() * eq.declination.0.cos() * hour_local.cos())
            .asin(),
        );
        Self {
            altitude: Altitude(azimuth_rad),
            azimuth: Azimuth(altitude_rad),
        }
    }

    /**
    Stereographic map projection of coordinates.

    <https://en.wikipedia.org/wiki/Stereographic_map_projection>
     */
    pub fn stereo_project(&self) -> Polar {
        Polar {
            radius: 2.0 * (PI_FOURTH - self.altitude.0.to_rad() / 2.0).tan(),
            angle: self.azimuth.0,
        }
    }

Convert to decimal hour

Examples found in repository?
src/angle.rs (line 167)
166
167
168
    fn from(angle: Angle) -> Self {
        Self::angle_to_ams(angle.to_hr())
    }
More examples
Hide additional examples
src/time.rs (line 69)
67
68
69
70
    fn from(julian_date: JulianDate) -> Self {
        // https://en.wikipedia.org/wiki/Sidereal_time
        Self(Angle::Hour(earth_rotation_angle(julian_date).to_hr()))
    }
Examples found in repository?
src/coord.rs (line 192)
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
    pub fn from_equitorial(eq: &Equitorial, geo: &Geographic, sidereal_time: &GMST) -> Self {
        let hour_local: Angle = sidereal_time.0 + geo.longitude.0 - eq.right_ascension.0;
        let x_horiz: f64 = -(geo.latitude.0.sin()) * (eq.declination.0.cos()) * (hour_local.cos())
            + geo.latitude.0.cos() * (eq.declination.0.sin());
        let y_horiz: f64 = eq.declination.0.cos() * hour_local.sin();
        let azimuth_rad: Angle = Angle::Radian(-(y_horiz.atan2(x_horiz)));
        let altitude_rad: Angle = Angle::Radian(
            (geo.latitude.0.sin() * eq.declination.0.sin()
                + geo.latitude.0.cos() * eq.declination.0.cos() * hour_local.cos())
            .asin(),
        );
        Self {
            altitude: Altitude(azimuth_rad),
            azimuth: Azimuth(altitude_rad),
        }
    }
Examples found in repository?
src/coord.rs (line 192)
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
    pub fn from_equitorial(eq: &Equitorial, geo: &Geographic, sidereal_time: &GMST) -> Self {
        let hour_local: Angle = sidereal_time.0 + geo.longitude.0 - eq.right_ascension.0;
        let x_horiz: f64 = -(geo.latitude.0.sin()) * (eq.declination.0.cos()) * (hour_local.cos())
            + geo.latitude.0.cos() * (eq.declination.0.sin());
        let y_horiz: f64 = eq.declination.0.cos() * hour_local.sin();
        let azimuth_rad: Angle = Angle::Radian(-(y_horiz.atan2(x_horiz)));
        let altitude_rad: Angle = Angle::Radian(
            (geo.latitude.0.sin() * eq.declination.0.sin()
                + geo.latitude.0.cos() * eq.declination.0.cos() * hour_local.cos())
            .asin(),
        );
        Self {
            altitude: Altitude(azimuth_rad),
            azimuth: Azimuth(altitude_rad),
        }
    }

Trait Implementations§

The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
The resulting type after applying the + operator.
Performs the + operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more
The resulting type after applying the - operator.
Performs the - operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.