aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lisp/calendar/solar.el35
1 files changed, 14 insertions, 21 deletions
diff --git a/lisp/calendar/solar.el b/lisp/calendar/solar.el
index 93ecd208e63..5acef8aa759 100644
--- a/lisp/calendar/solar.el
+++ b/lisp/calendar/solar.el
@@ -145,7 +145,7 @@ Returns nil if nothing was entered."
145 145
146(defun solar-degrees-to-quadrant (angle) 146(defun solar-degrees-to-quadrant (angle)
147 "Determines the quadrant of ANGLE." 147 "Determines the quadrant of ANGLE."
148 (1+ (truncate (/ (solar-mod angle 360.0) 90.0)))) 148 (1+ (truncate (/ (mod angle 360.0) 90.0))))
149 149
150(defun solar-arctan (x quad) 150(defun solar-arctan (x quad)
151 "Arctangent of X in quadrant QUAD." 151 "Arctangent of X in quadrant QUAD."
@@ -163,13 +163,6 @@ Returns nil if nothing was entered."
163 (let ((x (sqrt (- 1 (* y y))))) 163 (let ((x (sqrt (- 1 (* y y)))))
164 (solar-arctan (/ y x) (solar-xy-to-quadrant x y)))) 164 (solar-arctan (/ y x) (solar-xy-to-quadrant x y))))
165 165
166(defun solar-mod (x y)
167 "Returns X mod Y; value is *always* non-negative."
168 (let ((v (% x y)))
169 (if (> 0 v)
170 (+ v y)
171 v)))
172
173(defconst solar-earth-inclination 23.441884 166(defconst solar-earth-inclination 23.441884
174 "Inclination of earth's equator to its solar orbit in degrees.") 167 "Inclination of earth's equator to its solar orbit in degrees.")
175 168
@@ -191,11 +184,11 @@ Returns nil if nothing was entered."
191(defun solar-longitude-of-sun (day) 184(defun solar-longitude-of-sun (day)
192 "Longitude of the sun at DAY in the year." 185 "Longitude of the sun at DAY in the year."
193 (let ((mean-anomaly (- (* 0.9856 day) 3.289))) 186 (let ((mean-anomaly (- (* 0.9856 day) 3.289)))
194 (solar-mod (+ mean-anomaly 187 (mod (+ mean-anomaly
195 (* 1.916 (solar-sin-degrees mean-anomaly)) 188 (* 1.916 (solar-sin-degrees mean-anomaly))
196 (* 0.020 (solar-sin-degrees (* 2 mean-anomaly))) 189 (* 0.020 (solar-sin-degrees (* 2 mean-anomaly)))
197 282.634) 190 282.634)
198 360))) 191 360)))
199 192
200(defun solar-right-ascension (longitude) 193(defun solar-right-ascension (longitude)
201 "Right ascension of the sun, given its LONGITUDE." 194 "Right ascension of the sun, given its LONGITUDE."
@@ -235,10 +228,10 @@ of hours. Returns nil if the sun does not rise at that location on that day."
235 (let* ((local-sunrise (solar-degrees-to-hours 228 (let* ((local-sunrise (solar-degrees-to-hours
236 (- 360 (solar-arccos cos-local-sunrise)))) 229 (- 360 (solar-arccos cos-local-sunrise))))
237 (local-mean-sunrise 230 (local-mean-sunrise
238 (solar-mod (- (+ local-sunrise solar-right-ascension-at-sunrise) 231 (mod (- (+ local-sunrise solar-right-ascension-at-sunrise)
239 (+ (* 0.065710 approx-sunrise) 232 (+ (* 0.065710 approx-sunrise)
240 6.622)) 233 6.622))
241 24))) 234 24)))
242 (+ (- local-mean-sunrise (solar-degrees-to-hours calendar-longitude)) 235 (+ (- local-mean-sunrise (solar-degrees-to-hours calendar-longitude))
243 (/ calendar-time-zone 60.0)))))) 236 (/ calendar-time-zone 60.0))))))
244 237
@@ -267,9 +260,9 @@ of hours. Returns nil if the sun does not set at that location on that day."
267 (let* ((local-sunset (solar-degrees-to-hours 260 (let* ((local-sunset (solar-degrees-to-hours
268 (solar-arccos cos-local-sunset))) 261 (solar-arccos cos-local-sunset)))
269 (local-mean-sunset 262 (local-mean-sunset
270 (solar-mod (- (+ local-sunset solar-right-ascension-at-sunset) 263 (mod (- (+ local-sunset solar-right-ascension-at-sunset)
271 (+ (* 0.065710 approx-sunset) 6.622)) 264 (+ (* 0.065710 approx-sunset) 6.622))
272 24))) 265 24)))
273 (+ (- local-mean-sunset (solar-degrees-to-hours calendar-longitude)) 266 (+ (- local-mean-sunset (solar-degrees-to-hours calendar-longitude))
274 (/ calendar-time-zone 60.0)))))) 267 (/ calendar-time-zone 60.0))))))
275 268
@@ -379,7 +372,7 @@ several minutes."
379 app 372 app
380 (correction 1000)) 373 (correction 1000))
381 (while (> correction 0.00001) 374 (while (> correction 0.00001)
382 (setq app (solar-mod (solar-apparent-longitude-of-sun date) 360.0)) 375 (setq app (mod (solar-apparent-longitude-of-sun date) 360.0))
383 (setq correction (* 58 (solar-sin-degrees (- (* k 90) app)))) 376 (setq correction (* 58 (solar-sin-degrees (- (* k 90) app))))
384 (setq date (list (extract-calendar-month date) 377 (setq date (list (extract-calendar-month date)
385 (+ (extract-calendar-day date) correction) 378 (+ (extract-calendar-day date) correction)