Skip to content

Instantly share code, notes, and snippets.

@srikumarks
Created January 23, 2023 05:18
Show Gist options
  • Save srikumarks/984e419b80427137cdb893a87a2b66f6 to your computer and use it in GitHub Desktop.
Save srikumarks/984e419b80427137cdb893a87a2b66f6 to your computer and use it in GitHub Desktop.
Calculating your "birth position"
using Dates, TimeZones, SatelliteToolbox
"""
upcoming_birthpos gives you the exact time and date within the
next year, at which the earth arrives again closest to where it
was when you were born (relative to the sun). It also gives
this minimum distance value in km.
"""
function upcoming_birthpos(y,m,d,h,min,s,tzstr="Asia/Kolkata")
dob = ZonedDateTime(y,m,d,h,min,s,0,TimeZone(tzstr))
jdthen = datetime2julian(dob.utc_datetime)
jdnow = datetime2julian(now(tz"UTC").utc_datetime)
pthen = sun_position_i(jdthen)
# This is position in earth-centered inertial MOD frame.
# This means we can use it as relative position of earth
# from sun as well. To check that this is true, if you
# calculate the corresponding sun_velocity_i(jdthen),
# you'll find it correlates well with the earth's orbital
# speed.
onemin = 1/(24*60)
start = 1.0
trange = (jdnow-start):onemin:(jdnow-start+365)
dist(p1,p2) = sqrt(sum((p1-p2).^2))
exact_ix = argmin(dist(pthen, sun_position_i(t)) for t in trange)
exact_jd = (jdnow-start) + (exact_ix-1)*onemin
pnow = sun_position_i(exact_jd)
(;years = (exact_jd - jdthen) / 365.25,
birthday = ZonedDateTime(julian2datetime(exact_jd), TimeZone(tzstr), from_utc=true),
distance_from_birthpos_km = dist(pnow,pthen)/1000)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment