| @@ -21,6 +21,26 @@ public struct SkyEvent: Sendable, Identifiable, Equatable { |
| 21 | 21 | public var id: String { "\(kind.rawValue)-\(title)-\(Int(date.timeIntervalSince1970))" } |
| 22 | 22 | } |
| 23 | 23 | |
| 24 | extension MeteorShower { |
| 25 | /// When in `window` the radiant stands highest, and how high (degrees), sampled every 10 minutes. |
| 26 | public func highestRadiant(in window: DateInterval, from observer: Observer) -> (date: Date, altitude: Double) { |
| 27 | let eq = SkyEngine.equatorOfDate(j2000: (ra, dec), at: window.start) |
| 28 | let steps = max(1, Int(window.duration / 600)) |
| 29 | return (0...steps).map { i -> (date: Date, altitude: Double) in |
| 30 | let t = min(window.end, window.start.addingTimeInterval(Double(i) * 600)) |
| 31 | return (t, SkyEngine.horizontal(rightAscension: eq.ra / 15, declination: eq.dec, at: t, from: observer).altitude) |
| 32 | }.max { $0.altitude < $1.altitude }! |
| 33 | } |
| 34 | |
| 35 | /// The radiant's best altitude in `window` and the rate it allows, ZHR × sin(altitude), as a sentence. |
| 36 | public func radiantNote(in window: DateInterval, from observer: Observer, time: Date.FormatStyle = .init(date: .omitted, time: .shortened)) -> String { |
| 37 | let best = highestRadiant(in: window, from: observer) |
| 38 | guard best.altitude > 0 else { return "The radiant stays below the horizon while it is dark." } |
| 39 | let rate = Int((Double(zhr) * sin(best.altitude * .pi / 180)).rounded()) |
| 40 | return "Radiant highest at \(best.date.formatted(time)), \(Int(best.altitude.rounded()))° up: about \(rate) an hour then." |
| 41 | } |
| 42 | } |
| 43 | |
| 24 | 44 | extension SkyEvent { |
| 25 | 45 | /// When a Lock Screen activity for a meteor shower's peak night starts: 10 minutes before dark, or `now` if that |
| 26 | 46 | /// has passed. Nil for other events, once the night is over, or more than a day ahead. |
| @@ -38,16 +58,19 @@ public struct MeteorShower: Sendable { |
| 38 | 58 | public var day: Int |
| 39 | 59 | /// Zenithal hourly rate at peak under ideal skies. |
| 40 | 60 | public var zhr: Int |
| 61 | /// Radiant at peak, J2000 degrees. |
| 62 | public var ra: Double |
| 63 | public var dec: Double |
| 41 | 64 | |
| 42 | 65 | public static let major: [MeteorShower] = [ |
| 43 | | MeteorShower(name: "Quadrantids", month: 1, day: 3, zhr: 80), |
| 44 | | MeteorShower(name: "Lyrids", month: 4, day: 22, zhr: 18), |
| 45 | | MeteorShower(name: "Eta Aquariids", month: 5, day: 6, zhr: 50), |
| 46 | | MeteorShower(name: "Perseids", month: 8, day: 12, zhr: 100), |
| 47 | | MeteorShower(name: "Orionids", month: 10, day: 21, zhr: 20), |
| 48 | | MeteorShower(name: "Leonids", month: 11, day: 17, zhr: 15), |
| 49 | | MeteorShower(name: "Geminids", month: 12, day: 14, zhr: 150), |
| 50 | | MeteorShower(name: "Ursids", month: 12, day: 22, zhr: 10), |
| 66 | MeteorShower(name: "Quadrantids", month: 1, day: 3, zhr: 80, ra: 230, dec: 49), |
| 67 | MeteorShower(name: "Lyrids", month: 4, day: 22, zhr: 18, ra: 271, dec: 34), |
| 68 | MeteorShower(name: "Eta Aquariids", month: 5, day: 6, zhr: 50, ra: 338, dec: -1), |
| 69 | MeteorShower(name: "Perseids", month: 8, day: 12, zhr: 100, ra: 48, dec: 58), |
| 70 | MeteorShower(name: "Orionids", month: 10, day: 21, zhr: 20, ra: 95, dec: 16), |
| 71 | MeteorShower(name: "Leonids", month: 11, day: 17, zhr: 15, ra: 152, dec: 22), |
| 72 | MeteorShower(name: "Geminids", month: 12, day: 14, zhr: 150, ra: 112, dec: 33), |
| 73 | MeteorShower(name: "Ursids", month: 12, day: 22, zhr: 10, ra: 217, dec: 75), |
| 51 | 74 | ] |
| 52 | 75 | } |
| 53 | 76 | |
| @@ -169,7 +192,7 @@ extension SkyEngine { |
| 169 | 192 | let dark = try? darkness(from: night.start, to: night.end, observer: observer) |
| 170 | 193 | let moon = moonAndDarkness(night: night, dark: dark, |
| 171 | 194 | moonUp: (try? moonUp(from: night.start, to: night.end, observer: observer)) ?? [], moonIllumination: lit) |
| 172 | | out.append(SkyEvent(kind: .meteorShower, date: d, title: "\(m.name) peak", detail: "Up to about \(m.zhr) meteors an hour under dark skies. \(moon)", visibleHere: nil, window: dark ?? night, |
| 195 | out.append(SkyEvent(kind: .meteorShower, date: d, title: "\(m.name) peak", detail: "Up to about \(m.zhr) meteors an hour under dark skies. \(m.radiantNote(in: dark ?? night, from: observer)) \(moon)", visibleHere: nil, window: dark ?? night, |
| 173 | 196 | zhr: m.zhr, moonIllumination: lit)) |
| 174 | 197 | } |
| 175 | 198 | } |