Code
# install.packages(c("plotly","jsonlite"))
library(plotly)Everything in the solar system moves, each body on its own orbit around the Sun. This story places the planets, the asteroids, the comets and the spacecraft that are leaving the solar system where they are today, and asks five questions:
The data are NASA’s, from its Jet Propulsion Laboratory (JPL): the orbits of the planets, the dwarf planets and the comets, and the paths of the spacecraft, from its Horizons system, which computes them from the JPL ephemerides (Park et al. 2021); and the orbits of thousands of asteroids and of every known object beyond Neptune from its Small-Body Database. They are downloaded when the page is rendered. The charts can be turned with the mouse and zoomed, and every body shows its name when the pointer is over it. The page follows The Crowded Sky, which does the same for the satellites around the Earth.
The words of this page:
An orbit is given by six numbers: its size, its shape, its tilt to the ecliptic, how it is turned around the Sun and within its own plane, and where the body is on it at a given moment. Horizons gives these numbers for each planet, dwarf planet and comet as they are today (its osculating orbit: the orbit that the body would keep if the planets stopped pulling on it), and the page draws the orbit and places the body from them. For the spacecraft, Horizons gives the path itself, from launch to today. The Small-Body Database gives the orbits of the asteroids and of the objects beyond Neptune at an earlier moment, and Kepler’s equation moves each one along its orbit to today.
# the copies of the answers kept on this computer: an answer of Horizons is kept under the date of
# the page and downloaded at most once a day; the orbits of the small bodies change little and are
# downloaded again after 30 days. A service that does not answer is asked again, up to three more
# times, 10 seconds apart; if it still does not answer, an older copy is used if there is one
kept<-tools::R_user_dir("illustration",which="cache")
dir.create(kept,recursive=TRUE,showWarnings=FALSE)
download_kept<-function(url,name,hours=Inf,tries=4) {
file<-file.path(kept,name)
if(file.exists(file)&&difftime(Sys.time(),file.mtime(file),units="hours")<hours)
return(file)
temporary<-tempfile()
for(k in seq_len(tries)) {
done<-tryCatch(download.file(url,temporary,quiet=TRUE,mode="wb")==0,
error=function(e) FALSE,warning=function(w) FALSE)
if(done) {
file.copy(temporary,file,overwrite=TRUE)
# at most one question a second to the services
Sys.sleep(1)
return(file)
}
if(k<tries)
Sys.sleep(10)
}
if(file.exists(file))
return(file)
stop("Could not download ",url)
}
# a name as a part of a file name: "Comet Hale–Bopp" becomes "comet_hale_bopp"
slug<-function(x) {
result<-gsub("^_|_$","",gsub("[^a-z0-9]+","_",tolower(iconv(x,to="ASCII//TRANSLIT"))))
return(result)
}
# a question to Horizons: the orbit (ELEMENTS) or the positions (VECTORS) of a body, seen from the
# center of the Sun, on the plane of the ecliptic, in AU and days
horizons<-function(command,type,start,stop,step) {
values<-c(COMMAND=command,OBJ_DATA="NO",MAKE_EPHEM="YES",EPHEM_TYPE=type,CENTER="500@10",
START_TIME=start,STOP_TIME=stop,STEP_SIZE=step,REF_PLANE="ECLIPTIC",
OUT_UNITS="AU-D",CSV_FORMAT="YES",VEC_TABLE="1")
query<-paste0(names(values),"=",vapply(paste0("'",values,"'"),URLencode,"",reserved=TRUE),
collapse="&")
result<-paste0("https://ssd.jpl.nasa.gov/api/horizons.api?format=json&",query)
return(result)
}
# the table of an answer of Horizons, between its lines $$SOE and $$EOE, with its column names
horizons_table<-function(file) {
text<-jsonlite::fromJSON(file)$result
lines<-strsplit(text,"\n")[[1]]
first<-which(lines=="$$SOE")
last<-which(lines=="$$EOE")
if(!length(first))
stop("Horizons gave no table: ",substr(text,1,300))
header<-trimws(strsplit(lines[first-2],",")[[1]])
rows<-read.csv(text=paste(lines[(first+1):(last-1)],collapse="\n"),header=FALSE,
strip.white=TRUE)[,seq_along(header)]
names(rows)<-header
result<-rows[,header!=""]
return(result)
}
# a question to the Small-Body Database: the orbits of a class of small bodies, with a condition
sbdb<-function(class,condition=NULL) {
query<-c(fields="full_name,a,e,i,om,w,ma,epoch,H",`sb-class`=class)
if(!is.null(condition))
query<-c(query,`sb-cdata`=condition)
url<-paste0("https://ssd-api.jpl.nasa.gov/sbdb_query.api?",
paste0(names(query),"=",vapply(query,URLencode,"",reserved=TRUE),collapse="&"))
answer<-jsonlite::fromJSON(download_kept(url,paste0("sbdb_",tolower(class),".json"),
hours=24*30))
result<-as.data.frame(answer$data,stringsAsFactors=FALSE)
names(result)<-answer$fields
for(v in c("a","e","i","om","w","ma","epoch","H"))
result[[v]]<-as.numeric(result[[v]])
result$name<-trimws(result$full_name)
# a body whose orbit is too poorly known to place it on it (no mean anomaly) is left out
result<-result[complete.cases(result[,c("a","e","i","om","w","ma","epoch")]),]
return(result)
}# the day of the page, at 0:00 UTC
today<-as.Date(format(Sys.time(),"%Y-%m-%d",tz="UTC"))
today_jd<-as.numeric(today)+2440587.5 # its Julian date
d2r<-pi/180
# a point of an orbit, in AU from the Sun: x towards the March equinox, y 90° further along the
# ecliptic, z towards the north of the ecliptic. q: the distance at perihelion, e: the shape (0 a
# circle, below 1 an ellipse, above 1 a hyperbola), the angles in radians, and nu the angle from
# the perihelion, seen from the Sun (the true anomaly)
orbit_point<-function(q,e,tilt,node,perihelion,nu) {
r<-q*(1+e)/(1+e*cos(nu))
u<-perihelion+nu
result<-data.frame(x=r*(cos(node)*cos(u)-sin(node)*sin(u)*cos(tilt)),
y=r*(sin(node)*cos(u)+cos(node)*sin(u)*cos(tilt)),
z=r*sin(u)*sin(tilt))
return(result)
}
# the line of an orbit from Horizons' numbers, in 360 steps; an orbit that reaches further than
# `reach` AU from the Sun, as an open orbit always does, is drawn only where it is closer
orbit_line<-function(b,reach=Inf) {
far<-if(b$EC<1) b$QR*(1+b$EC)/(1-b$EC) else Inf
limit<-if(far<=reach) pi else acos((b$QR*(1+b$EC)/reach-1)/b$EC)
result<-orbit_point(b$QR,b$EC,b$IN*d2r,b$OM*d2r,b$W*d2r,seq(-limit,limit,length.out=361))
return(result)
}
# where small bodies are today, from the orbits of the Small-Body Database at an earlier moment
# (epoch): each moves on along its orbit by its mean motion, from Gauss's constant (the Sun's
# gravity: radians a day on an orbit of 1 AU), and Kepler's equation gives the place
gauss<-0.01720209895
place_today<-function(s) {
motion<-gauss/s$a^1.5
anomaly<-(s$ma*d2r+motion*(today_jd-s$epoch))%%(2*pi)
# Kepler's equation, solved by Newton's method, starting from pi for very stretched orbits
eccentric<-ifelse(s$e>0.8,pi,anomaly)
for(step in 1:50)
eccentric<-eccentric-(eccentric-s$e*sin(eccentric)-anomaly)/(1-s$e*cos(eccentric))
nu<-2*atan2(sqrt(1+s$e)*sin(eccentric/2),sqrt(1-s$e)*cos(eccentric/2))
result<-cbind(s,orbit_point(s$a*(1-s$e),s$e,s$i*d2r,s$om*d2r,s$w*d2r,nu))
result$r<-sqrt(result$x^2+result$y^2+result$z^2)
return(result)
}# the planets, the dwarf planets, three comets and the three visitors from other stars that are
# known, with the names that Horizons knows them by
bodies<-data.frame(
name=c("Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune",
"Ceres","Pluto","Haumea","Makemake","Eris",
"Halley's comet","Comet 67P","Comet Hale–Bopp",
"1I/ʻOumuamua","2I/Borisov","3I/ATLAS"),
command=c("199","299","399","499","599","699","799","899",
"1;","999","136108;","136472;","136199;",
"DES=1P;CAP","DES=67P;CAP","C/1995 O1",
"A/2017 U1","C/2019 Q4","C/2025 N1"),
kind=c(rep("planet",8),rep("dwarf",5),rep("comet",3),rep("visitor",3)))
# their orbits as they are today: the shape (EC), the distance at perihelion (QR), the tilt (IN),
# the turns (OM, W), the date of perihelion (Tp, a Julian date), the angle from the perihelion
# today (TA) and the size (A, half the longest width; negative for an open orbit)
elements<-lapply(seq_len(nrow(bodies)),function(k)
horizons_table(download_kept(horizons(bodies$command[k],"ELEMENTS",format(today),
format(today+1),"1 d"),
paste0("horizons_",slug(bodies$name[k]),"_",today,".json")))[1,])
bodies<-cbind(bodies,do.call(rbind,elements)[,c("EC","QR","IN","OM","W","Tp","TA","A")])
bodies<-cbind(bodies,with(bodies,orbit_point(QR,EC,IN*d2r,OM*d2r,W*d2r,TA*d2r)))
bodies$r<-sqrt(bodies$x^2+bodies$y^2+bodies$z^2)
rownames(bodies)<-bodies$name
# the asteroids of the main belt whose absolute magnitude H is below 12, the brightest and so
# mostly the largest; Jupiter's Trojans with H below 13; and every object known beyond Neptune
main_belt<-place_today(sbdb("MBA",'{"AND":["H|LT|12"]}'))
trojans<-place_today(sbdb("TJN",'{"AND":["H|LT|13"]}'))
kuiper<-place_today(sbdb("TNO"))
# the five spacecraft that are leaving the solar system: their paths from a few days after launch to
# today, in 600 steps
probes<-data.frame(name=c("Pioneer 10","Pioneer 11","Voyager 2","Voyager 1","New Horizons"),
command=c("-23","-24","-32","-31","-98"),
start=as.Date(c("1972-03-05","1973-04-08","1977-08-23","1977-09-08",
"2006-01-21")))
paths<-lapply(seq_len(nrow(probes)),function(k) {
file<-download_kept(horizons(probes$command[k],"VECTORS",format(probes$start[k]),format(today),
"600"),
paste0("horizons_path_",slug(probes$name[k]),"_",today,".json"))
path<-horizons_table(file)
data.frame(date=as.Date(path$JDTDB-2440587.5),x=path$X,y=path$Y,z=path$Z)
})
names(paths)<-probes$name
for(k in names(paths))
paths[[k]]$r<-sqrt(paths[[k]]$x^2+paths[[k]]$y^2+paths[[k]]$z^2)
probes$r<-vapply(paths,function(p) p$r[nrow(p)],0)dark_gray<-"#6b6b6b" # also the color of the notes
orbit_gray<-"#b3b3b3"
planet_gray<-"#8f8f8f" # the bars of the planets
ink<-"#191919"
sun_yellow<-"#f2a600"
# the colors of the groups, told apart also by color-blind readers (each set checked)
blue<-"#257de0"
orange<-"#f47230"
green<-"#00b894"
probe_colour<-c(`Pioneer 10`=blue,`Pioneer 11`=orange,`Voyager 2`=green,`Voyager 1`="#6a4ce2",
`New Horizons`="#ee7fac")
# the source of a chart, as a note under it, and the common layout; note_shift moves the note down
# by a number of pixels, which stays the same however tall the plot is
chart<-function(p,title,source,y_title="",x_title="",y_axis=list(),x_axis=list(),
annotations=list(),margin=list(t=70,b=90),note_y=-0.16,note_shift=0,...) {
note<-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
yanchor="top",yshift=note_shift,align="left",showarrow=FALSE,
font=list(size=11,color=dark_gray))
result<-layout(p,
title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
margin=margin,
annotations=c(annotations,list(note)),
...)
if(nchar(paste0(y_title,x_title))>0||length(c(y_axis,x_axis))>0)
result<-layout(result,yaxis=modifyList(list(title=y_title),y_axis),
xaxis=modifyList(list(title=x_title),x_axis))
result<-config(result,displaylogo=FALSE)
return(result)
}
legend_top<-list(orientation="h",x=0,y=1.02,yanchor="bottom",itemsizing="constant")
horizons_source<-"NASA JPL Horizons: osculating orbits of today, Sun-centred, on the ecliptic."
sbdb_source<-"NASA JPL Small-Body Database, moved along their orbits to today."
# short labels of numbers and dates
number<-function(x) {
result<-format(round(x),big.mark=",",trim=TRUE,scientific=FALSE)
return(result)
}
one<-function(x) {
result<-format(round(x,1),nsmall=1,trim=TRUE)
return(result)
}
date_words<-function(x) {
result<-paste(as.integer(format(x,"%d")),month.name[as.integer(format(x,"%m"))],format(x,"%Y"))
return(result)
}
month_words<-function(x) {
result<-paste(month.name[as.integer(format(x,"%m"))],format(x,"%Y"))
return(result)
}
jd_date<-function(jd) {
result<-as.Date(jd-2440587.5)
return(result)
}
when<-date_words(today)
# 3D charts. Distances in hundredths of an AU, as whole numbers: plotly for R writes any other
# number with 17 digits (8.49 as 8.4900000000000002). The axes are hidden, all three as long as each
# other, out to r AU from the Sun, and the view is from above the ecliptic, a little to one side
au<-function(x) {
result<-round(100*x)
return(result)
}
eye<-c(x=0.45,y=-1.05,z=0.75)
space_scene<-function(r) {
axis<-list(range=c(-100*r,100*r),visible=FALSE)
result<-list(xaxis=axis,yaxis=axis,zaxis=axis,aspectmode="cube",dragmode="turntable",
camera=list(eye=as.list(eye)))
return(result)
}
# the directions to the right and upwards on the screen, as the charts are first seen from the eye
forward<-(-eye)/sqrt(sum(eye^2))
screen_right<-c(forward[["y"]],-forward[["x"]],0)/sqrt(forward[["x"]]^2+forward[["y"]]^2)
screen_up<-c(screen_right[2]*forward[["z"]],-screen_right[1]*forward[["z"]],
screen_right[1]*forward[["y"]]-screen_right[2]*forward[["x"]])
# the side of each body on which its name is written: away from the Sun as the chart is first
# seen; and two bodies close together on the screen (less than a quarter of the view apart) with
# their names on the same side get one name to the left and one to the right, the closest pairs
# first, each body once. view: the distance from the Sun in view, in AU
label_sides<-function(b,view) {
position<-as.matrix(b[,c("x","y","z")])/view
across<-as.vector(position%*%screen_right)
up<-as.vector(position%*%screen_up)
vertical<-ifelse(abs(up)<0.4*abs(across),"middle",ifelse(up>=0,"top","bottom"))
side<-ifelse(across>=0,"right","left")
pairs<-which(upper.tri(diag(length(side))),arr.ind=TRUE)
apart<-sqrt((across[pairs[,1]]-across[pairs[,2]])^2+(up[pairs[,1]]-up[pairs[,2]])^2)
moved<-rep(FALSE,length(side))
for(k in order(apart)) {
i<-pairs[k,1]
j<-pairs[k,2]
if(apart[k]<0.25&&!moved[i]&&!moved[j]&&vertical[i]==vertical[j]&&side[i]==side[j]) {
side[c(i,j)]<-if(across[i]<across[j]) c("left","right") else c("right","left")
moved[c(i,j)]<-TRUE
}
}
# a body near the left or right edge gets its name on the side towards the Sun, and above it if
# it was beside it, so that the name is not cut off on a narrow screen
edge<-abs(across)>0.6
vertical[edge&vertical=="middle"]<-"top"
side[edge]<-ifelse(across[edge]>0,"left","right")
result<-paste(vertical,side)
return(result)
}
# the orbits of several bodies as one line, with a gap after each orbit
orbit_lines<-function(b,reach=Inf) {
lines<-lapply(seq_len(nrow(b)),function(k) rbind(orbit_line(b[k,],reach),NA))
result<-do.call(rbind,lines)
result<-data.frame(x=au(result$x),y=au(result$y),z=au(result$z))
return(result)
}
# the Sun, and bodies as points with their names next to them; view: as in label_sides, others:
# bodies of the same chart added apart, whose names they must not cover, and group: the legend
# entry of their orbits, which then turn on and off with them
add_sun<-function(p,legend=TRUE) {
result<-add_trace(p,x=0,y=0,z=0,type="scatter3d",mode="markers",name="Sun",showlegend=legend,
marker=list(color=sun_yellow,size=8,line=list(color=ink,width=1)),
hovertemplate="<b>Sun</b><extra></extra>",inherit=FALSE)
return(result)
}
add_bodies<-function(p,b,name,view,colour=ink,size=4,others=NULL,group=NULL) {
sides<-label_sides(rbind(b[,c("x","y","z")],others[,c("x","y","z")]),view)[seq_len(nrow(b))]
result<-add_trace(p,data=data.frame(x=au(b$x),y=au(b$y),z=au(b$z),label=b$name,
hover=paste0("<b>",b$name,"</b><br>",one(b$r),
" AU from the Sun")),
x=~x,y=~y,z=~z,type="scatter3d",mode="markers+text",name=name,text=~label,
textposition=sides,textfont=list(size=11,color=ink),
customdata=~hover,hovertemplate="%{customdata}<extra></extra>",
marker=list(color=colour,size=size,line=list(color="#ffffff",width=1)),
legendgroup=group,inherit=FALSE)
return(result)
}
# a 3D chart is built once and its second copy of every number ("attrs") dropped. zooms: buttons
# that zoom in and out, a label and a distance from the Sun in AU for each. At every zoom a name
# is written only next to a body more than 6% of that distance from the Sun, so that the names of
# the bodies close to the Sun do not pile up on it; the chart opens at the zoom of its scene
finish_3d<-function(p,zooms=NULL) {
result<-plotly_build(p)
result$x$attrs<-NULL
if(is.null(zooms))
return(result)
named<-which(vapply(result$x$data,function(t) grepl("text",paste(t$mode,collapse="")),TRUE))
labels<-lapply(result$x$data[named],function(t) t$text)
far<-lapply(result$x$data[named],function(t) sqrt(t$x^2+t$y^2+t$z^2)/100)
zooms<-c(open=result$x$layout$scene$xaxis$range[2]/100,zooms)
shown<-lapply(zooms,function(view) Map(function(l,r) ifelse(r>0.06*view,l,""),labels,far))
for(k in seq_along(named))
result$x$data[[named[k]]]$text<-shown$open[[k]]
buttons<-lapply(names(zooms)[-1],function(z) {
range<-c(-100,100)*zooms[[z]]
list(label=z,method="update",
args=list(list(text=unname(shown[[z]])),
list(scene.xaxis.range=range,scene.yaxis.range=range,scene.zaxis.range=range),
as.list(named-1)))
})
result$x$layout$updatemenus<-list(list(type="buttons",direction="right",x=0,y=0,xanchor="left",
yanchor="top",showactive=FALSE,buttons=buttons))
return(result)
}
planets<-bodies[bodies$kind=="planet",]earth<-bodies["Earth",]
jupiter<-bodies["Jupiter",]
# the angle of each Trojan ahead of Jupiter (+) or behind it (−), along the ecliptic, in degrees
longitude<-function(x,y) {
result<-atan2(y,x)/d2r
return(result)
}
trojans$ahead<-((longitude(trojans$x,trojans$y)-longitude(jupiter$x,jupiter$y)+180)%%360)-180
leading<-trojans$ahead>0
belt_range<-quantile(main_belt$a,c(0.05,0.95))
# the time that each planet takes to go round the Sun, in years: by Kepler's third law, the size
# of its orbit (half its longest width, in AU) to the power 1.5
planets$years<-planets$A^1.5Eight planets in nearly one plane, and two crowds of asteroids. On 2 December 2026, the Earth was 0.986 AU from the Sun. Between Mars and Jupiter, the 2,016 brightest asteroids of the main belt orbit between 2.4 and 3.2 AU from the Sun (nine out of ten of them). Further out, Jupiter’s 1,558 brightest Trojans travel along its orbit in two crowds: 927 about 61° ahead of the planet, and 631 about 62° behind it, at the two points where the pulls of the Sun and of Jupiter hold them.
p<-plot_ly() %>%
add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip")
for(g in list(list(data=main_belt,colour=blue,name="Main belt"),
list(data=trojans,colour=orange,name="Jupiter's Trojans"))) {
points<-data.frame(x=au(g$data$x),y=au(g$data$y),z=au(g$data$z),
hover=paste0("<b>",g$data$name,"</b><br>",one(g$data$r)," AU from the Sun"))
p<-add_trace(p,data=points,x=~x,y=~y,z=~z,type="scatter3d",mode="markers",
name=paste0(g$name,": ",number(nrow(g$data))),customdata=~hover,
hovertemplate="%{customdata}<extra></extra>",
marker=list(color=g$colour,size=1.6,line=list(width=0)),inherit=FALSE)
}
p %>%
add_sun() %>%
add_bodies(planets,"Planets",6) %>%
chart(paste("The solar system on",when),paste(horizons_source,sbdb_source),
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(6)) %>%
finish_3d(c(`Inner planets`=1.8,`Out to Jupiter`=6,`Out to Neptune`=32))Each gray ring is the orbit of a planet, and each planet stands where it is today. Inner planets zooms in on Mercury, Venus, the Earth and Mars; Out to Neptune shows the four giants, and how far apart they are: the main belt and everything inside it shrink to a small disc around the Sun. Seen from this side, they all go round the Sun anticlockwise: the Earth in a year, Jupiter in 11.9 years and Neptune in 165.
light_seconds<-499.004784 # seconds that light takes to cover 1 AU
light_day<-86400/light_seconds # AU that light covers in a day
# Voyager 1 and the Earth every day from 2026 to 2028: when is Voyager 1 one light-day away from us?
window<-c("2026-01-01","2028-12-31")
daily<-lapply(c(`Voyager 1`="-31",Earth="399"),function(command)
horizons_table(download_kept(horizons(command,"VECTORS",window[1],window[2],"1 d"),
paste0("horizons_daily_",gsub("[^0-9]","",command),"_",
paste(window,collapse="_"),".json"))))
apart<-sqrt((daily$`Voyager 1`$X-daily$Earth$X)^2+(daily$`Voyager 1`$Y-daily$Earth$Y)^2+
(daily$`Voyager 1`$Z-daily$Earth$Z)^2)
days<-jd_date(daily$Earth$JDTDB)
first_day<-days[which(apart>light_day)[1]]
for_good<-days[max(which(apart<=light_day))+1]
voyager1<-paths[["Voyager 1"]][nrow(paths[["Voyager 1"]]),]
voyager1_earth<-sqrt((voyager1$x-earth$x)^2+(voyager1$y-earth$y)^2+(voyager1$z-earth$z)^2)
# the sentence about it: before, on or after the first day, and whether it comes back within a
# light-day while the Earth goes round the Sun, now towards Voyager 1 and now away from it
light_day_words<-paste0("one light-day (",one(light_day)," AU)")
voyager_day<-paste(if(today<first_day) "It will be" else "It was",light_day_words,
"away from the Earth for the first time on",date_words(first_day))
voyager_day<-if(for_good>first_day)
paste0(voyager_day,", and as the Earth goes round the Sun, now towards it and now away, ",
if(today<for_good) "it will come" else "it came"," back within a light-day until ",
date_words(for_good-1),".") else
paste0(voyager_day,", and it will never again be closer.")
# light time from the Sun, in hours, to the planets, Pluto, Eris and the spacecraft
chosen<-bodies[bodies$kind=="planet"|bodies$name%in%c("Pluto","Eris"),]
far<-rbind(data.frame(name=chosen$name,r=chosen$r,colour=planet_gray),
data.frame(name=probes$name,r=probes$r,colour=probe_colour[probes$name]))
far$hours<-far$r*light_seconds/3600
far<-far[order(far$r),]
light_words<-function(hours) {
result<-ifelse(hours<1,paste(one(60*hours),"min"),paste(one(hours),"h"))
return(result)
}
proxima<-4.24*365.25*24 # light-hours to the nearest star, Proxima Centauri, 4.24 light-yearsLight takes 8.3 minutes to reach us from the Sun, and almost a day to reach Voyager 1. Light from the Sun reaches Neptune in 4.1 hours and Eris, 95.4 AU away today, in 13.2 hours. Voyager 1, the furthest spacecraft, is 172.5 AU from the Sun: 23.9 light-hours, or 25.8 billion km. Today it is 173.3 AU from the Earth, so its radio signals take 24.0 hours to reach us. It was one light-day (173.1 AU) away from the Earth for the first time on 19 November 2026, and it will never again be closer.
far$label<-light_words(far$hours)
plot_ly(far,x=~hours,y=~name,type="bar",orientation="h",marker=list(color=~I(colour)),
text=~label,textposition="outside",cliponaxis=FALSE,customdata=~one(r),
hovertemplate="<b>%{y}</b>: %{customdata} AU, %{text}<extra></extra>") %>%
chart(paste("How long light takes to get there from the Sun,",when),
"NASA JPL Horizons: the distance of each from the Sun today.",
x_title="Light time from the Sun (a logarithmic scale)",
x_axis=list(type="log",tickvals=c(1/60,10/60,1,10,24),
ticktext=c("1 min","10 min","1 h","10 h","1 day"),range=log10(c(0.02,60))),
y_axis=list(categoryorder="array",categoryarray=far$name,title=""),
margin=list(t=60,b=110,l=110),note_y=-0.2)Gray bars are planets and dwarf planets, colored bars spacecraft, in the colors of their paths in question 4. From one mark of the scale to the next, the time grows tenfold. Voyager 1 is 5.8 times as far from the Sun as Neptune, after 49 years of travel. Yet the nearest star, Proxima Centauri, 4.24 light-years away, is about 1,550 times as far as Voyager 1.
neptune<-bodies["Neptune",]
pluto<-bodies["Pluto",]
eris<-bodies["Eris",]
# where an orbit goes round the Sun 2 times for every 3 of Neptune's (3:2), 1 for every 2 (2:1) or
# 2 for every 5 (5:2): by Kepler's third law, at the size of Neptune's orbit times the ratio of the
# times to the power 2/3
resonance<-c(`3:2`=neptune$A*(3/2)^(2/3),`2:1`=neptune$A*2^(2/3),`5:2`=neptune$A*(5/2)^(2/3))
near_32<-abs(kuiper$a-resonance[["3:2"]])<0.4
classical<-kuiper$a>42&kuiper$a<resonance[["2:1"]]
# orbits larger than 50 AU, and those of them that are nearly round: their furthest point less than
# 1.5 times as far from the Sun as their closest (a shape, e, below 0.2)
beyond_50<-kuiper$a>50
round_50<-beyond_50&kuiper$e<0.2
pluto_perihelion<-jd_date(pluto$Tp)
inside_neptune<-pluto$QR<neptune$QRThousands of icy bodies, gathered where Neptune’s rhythm lets them be. JPL’s database knows the orbits of 8,444 objects beyond Neptune’s. 773 of them, 9%, have orbits within 0.4 AU of 39.4 AU in size, where a body goes round the Sun twice while Neptune goes round three times (the 3:2 resonance). Pluto is one of them, and so they are called plutinos: its orbit comes closer to the Sun than Neptune’s (its last perihelion was in 1989), but the rhythm keeps the two from ever meeting. That many bodies would share Pluto’s rhythm, and gather at the 2:1 resonance (47.7 AU) too, was predicted when only a few were known (Malhotra 1995). 3,741 more, the classical belt, have orbits between 42 AU and the 2:1 resonance. Further out the crowd changes: 27% of the orbits are larger than 50 AU, but only 87 of these 2,266 are nearly round. The rest are long and stretched, most of them thought to belong to bodies that Neptune threw outward (the scattered disc): the belt of nearly round orbits seems to end near 50 AU (Trujillo and Brown 2001). Today Pluto is 35.7 AU from the Sun, and Eris, the most massive dwarf planet known, 95.4 AU.
dwarfs<-bodies[bodies$kind=="dwarf"&bodies$name!="Ceres",]
points<-data.frame(x=au(kuiper$x),y=au(kuiper$y),z=au(kuiper$z),
hover=paste0("<b>",kuiper$name,"</b><br>",one(kuiper$r)," AU from the Sun"))
plot_ly() %>%
add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip") %>%
add_trace(data=orbit_lines(dwarfs),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the dwarf planets",hoverinfo="skip",
line=list(color=dark_gray,width=2,dash="dash")) %>%
add_trace(data=points,x=~x,y=~y,z=~z,type="scatter3d",mode="markers",
name=paste0("Beyond Neptune: ",number(nrow(kuiper))),customdata=~hover,
hovertemplate="%{customdata}<extra></extra>",
marker=list(color=green,size=1.6,line=list(width=0)),inherit=FALSE) %>%
add_sun() %>%
add_bodies(bodies[c("Jupiter","Saturn","Uranus","Neptune",dwarfs$name),],
"Planets and dwarf planets",55) %>%
chart(paste("Beyond Neptune on",when),paste(horizons_source,sbdb_source),
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(55)) %>%
finish_3d(c(`The Kuiper belt`=55,`Out to Eris`=100))breaks<-seq(30,80,by=0.5)
counts<-table(cut(kuiper$a,breaks,right=FALSE))
bars<-data.frame(a=breaks[-length(breaks)]+0.25,objects=as.vector(counts))
marks<-lapply(names(resonance),function(k)
list(type="line",x0=resonance[[k]],x1=resonance[[k]],y0=0,y1=1,yref="paper",
line=list(color=dark_gray,width=1.5,dash="dot")))
labels<-lapply(names(resonance),function(k)
list(x=resonance[[k]],y=1,yref="paper",text=k,showarrow=FALSE,
xanchor="left",yanchor="top",xshift=4,font=list(size=12,color=dark_gray)))
plot_ly(bars,x=~a,y=~objects,type="bar",marker=list(color=green),
hovertemplate="%{x:.1f} AU: %{y} objects<extra></extra>") %>%
chart("Objects beyond Neptune by the size of their orbit, and Neptune's rhythms",
"NASA JPL Small-Body Database.",
"Objects (every half AU)","Half the longest width of the orbit, AU",
x_axis=list(range=c(30,80),showgrid=FALSE),shapes=marks,annotations=labels,bargap=0.05,
margin=list(t=70,b=100),note_y=-0.25)Each bar counts the orbits of one size, measured by half their longest width, and the dotted lines mark Neptune’s rhythms. The tall spike at 39.4 AU is the plutinos; the broad hump from 42 AU is the classical belt, which ends at the 2:1 resonance; and further out, a smaller spike sits at 55.4 AU, where a body goes round the Sun twice while Neptune goes round five times (the 5:2 resonance).
# the distance of a spacecraft from the Sun on a date, from its path
distance_on<-function(name,date) {
result<-approx(paths[[name]]$date,paths[[name]]$r,xout=as.Date(date))$y
return(result)
}
# how fast each moves away from the Sun now, in AU a year: over the last year of its path
speed<-vapply(probes$name,function(k) {
p<-paths[[k]]
back<-which.min(abs(p$date-(today-365)))
(p$r[nrow(p)]-p$r[back])/as.numeric(p$date[nrow(p)]-p$date[back])*365.25
},0)
events<-data.frame(name=c("Voyager 1","Voyager 2","Pioneer 11","Pioneer 10"),
date=as.Date(c("2012-08-25","2018-11-15","1995-11-24","2003-01-23")),
what=c("left the heliosphere","left the heliosphere","last signal",
"last signal"))
events$r<-mapply(distance_on,events$name,events$date)
furthest<-probes[order(-probes$r),]Five spacecraft are on paths that will take them out of the solar system for good (NASA 2025b). Voyager 1 is the furthest, 172.5 AU from the Sun, and moves away by 3.6 AU a year; then come Voyager 2 (144.6 AU), Pioneer 10 (142.4 AU), Pioneer 11 (118.3 AU) and New Horizons, launched in 2006 to Pluto, at 66.2 AU. Voyager 1 left the heliosphere for interstellar space in August 2012, 121.6 AU from the Sun (Gurnett et al. 2013), and Voyager 2 in November 2018, at about 119 AU (Stone et al. 2019). The two Pioneers are silent: Pioneer 11 sent its last data in November 1995, 44 AU from the Sun, and Pioneer 10 its last signal in January 2003, at 82 AU (NASA 2025a, 2025b); their places today are computed from the paths they were on.
outer<-planets[planets$name%in%c("Jupiter","Saturn","Uranus","Neptune"),]
p<-plot_ly() %>%
add_trace(data=orbit_lines(outer),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of Jupiter to Neptune",line=list(color=orbit_gray,width=2),
hoverinfo="skip")
# where each spacecraft is today, with its name on the side away from the Sun
ends<-do.call(rbind,lapply(probes$name,function(k) cbind(name=k,paths[[k]][nrow(paths[[k]]),])))
ends$side<-label_sides(ends,180)
for(k in probes$name) {
path<-paths[[k]]
line<-data.frame(x=au(path$x),y=au(path$y),z=au(path$z),
hover=paste0("<b>",k,"</b><br>",date_words(path$date),": ",one(path$r),
" AU from the Sun"))
p<-add_trace(p,data=line,x=~x,y=~y,z=~z,type="scatter3d",mode="lines",name=k,legendgroup=k,
line=list(color=probe_colour[[k]],width=4),customdata=~hover,
hovertemplate="%{customdata}<extra></extra>",inherit=FALSE)
p<-add_trace(p,data=line[nrow(line),],x=~x,y=~y,z=~z,type="scatter3d",mode="markers+text",
text=k,textposition=ends$side[ends$name==k],textfont=list(size=11,color=ink),
legendgroup=k,showlegend=FALSE,marker=list(color=probe_colour[[k]],size=5),
customdata=~hover,hovertemplate="%{customdata}<extra></extra>",inherit=FALSE)
}
p %>%
add_sun(legend=FALSE) %>%
chart(paste("Five spacecraft leaving the solar system, from launch to",when),
"NASA JPL Horizons: the path of each spacecraft, Sun-centred, on the ecliptic.",
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(180)) %>%
finish_3d(c(`Today`=180,`The planets`=35))p<-plot_ly()
for(k in probes$name)
p<-add_trace(p,data=paths[[k]],x=~date,y=~round(r,1),type="scatter",mode="lines",name=k,
line=list(color=probe_colour[[k]],width=2),
hovertemplate=paste0(k,": %{y} AU<extra></extra>"))
p<-add_trace(p,data=events,x=~date,y=~round(r,1),type="scatter",mode="markers",
name="Left the heliosphere, or last signal",text=~paste(name,what),
marker=list(color=ink,size=8,symbol="circle-open",line=list(width=2)),
hovertemplate="%{text}: %{y} AU<extra></extra>")
# the names at the ends of the lines; two that would be closer than 7% of the height are moved
# apart, each by half of what is missing
end_labels<-probes[order(probes$r),c("name","r")]
gap<-0.07*max(end_labels$r)
for(k in seq_len(nrow(end_labels))[-1]) {
missing<-gap-(end_labels$r[k]-end_labels$r[k-1])
if(missing>0)
end_labels$r[c(k-1,k)]<-end_labels$r[c(k-1,k)]+c(-1,1)*missing/2
}
labels<-lapply(seq_len(nrow(end_labels)),function(k)
list(x=today,y=end_labels$r[k],text=end_labels$name[k],showarrow=FALSE,xanchor="left",
xshift=6,font=list(size=11,color=ink)))
chart(p,"Distance from the Sun","NASA JPL Horizons: the path of each spacecraft.",
"AU from the Sun","",x_axis=list(showgrid=FALSE,range=c(as.Date("1971-01-01"),today+365)),
annotations=labels,hovermode="x unified",legend=legend_top,
margin=list(t=110,b=80,r=100),note_y=-0.12)Each line bends upward where its spacecraft passed close to a planet, whose gravity threw it outward faster: Jupiter for all five, then Saturn for Pioneer 11 and the two Voyagers, and Uranus and Neptune for Voyager 2. Since their last pass, they have been coasting along almost straight lines.
halley<-bodies["Halley's comet",]
# the time that a body takes to go round the Sun, in years: Kepler's third law
period_years<-function(b) {
result<-b$A^1.5
return(result)
}
# the orbit of today puts Halley's next perihelion on a date; its path in Horizons, which takes in
# the pulls of the planets, gives the real one (hour by hour, within 15 days of that date), and the
# days of its last perihelion and of its furthest point (a period and half a period earlier)
halley_path<-function(middle,days,step) {
window<-format(middle+c(-days,days))
path<-horizons_table(download_kept(horizons("DES=1P;CAP","VECTORS",window[1],window[2],step),
paste0("horizons_halley_",paste(window,collapse="_"),
".json")))
result<-data.frame(time=as.POSIXct((path$JDTDB-2440587.5)*86400,origin="1970-01-01",tz="UTC"),
r=sqrt(path$X^2+path$Y^2+path$Z^2))
return(result)
}
orbit_next<-jd_date(halley$Tp)
period_days<-round(period_years(halley)*365.25)
around<-halley_path(orbit_next,15,"1 h")
halley_next<-as.Date(around$time[which.min(around$r)])
around<-halley_path(orbit_next-period_days,60,"1 d")
halley_last<-as.Date(around$time[which.min(around$r)])
around<-halley_path(orbit_next-round(period_days/2),90,"1 d")
halley_aphelion<-as.Date(around$time[which.max(around$r)])
halley_far<-max(around$r)
comet67p<-bodies["Comet 67P",]
hale_bopp<-bodies["Comet Hale–Bopp",]
visitors<-bodies[bodies$kind=="visitor",]
# the speed of a visitor far from the Sun, in km/s: from the size of its open orbit (A, negative),
# the speed of the Earth on its orbit times the square root of 1 over the size
visitors$speed<-29.7847/sqrt(-visitors$A)
visitors$perihelion<-jd_date(visitors$Tp)
atlas<-visitors["3I/ATLAS",]Comets on closed orbits come back; the three visitors from other stars never will. Halley’s comet is 35.0 AU from the Sun. It passed the far end of its orbit on 9 December 2023, 35.1 AU out, and is on its way back: it will be closest to the Sun on 28 July 2061, 75 years after its last visit, in February 1986. Comet 67P, which ESA’s Rosetta spacecraft visited, goes round in 6.4 years, and Hale–Bopp, the bright comet of 1997, now 51.4 AU out, in about 2,400. The three visitors from other stars, ʻOumuamua (found in October 2017), Borisov (August 2019) and 3I/ATLAS (July 2025), came on open orbits (Meech et al. 2017; Guzik et al. 2020; MPC 2025). Far from the Sun, before its gravity sped them up and after it slowed them down again, they move at 26, 32 and 58 km/s: too fast for the Sun to hold them. 3I/ATLAS was closest to the Sun on 29 October 2025 and is already 13.9 AU away.
comets<-bodies[bodies$kind=="comet",]
reach<-60
p<-plot_ly() %>%
add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip") %>%
add_trace(data=orbit_lines(comets,reach),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Comets of the Sun",legendgroup="comets",showlegend=FALSE,
line=list(color=blue,width=3),hoverinfo="skip") %>%
add_trace(data=orbit_lines(visitors,reach),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Visitors from other stars",legendgroup="visitors",showlegend=FALSE,
line=list(color=orange,width=3),hoverinfo="skip")
p %>%
add_sun(legend=FALSE) %>%
add_bodies(comets,"Comets of the Sun",reach,colour=blue,others=visitors,group="comets") %>%
add_bodies(visitors,"Visitors from other stars",reach,colour=orange,others=comets,
group="visitors") %>%
chart(paste("Comets and visitors from other stars on",when),
paste(horizons_source,"Orbits drawn out to",reach,"AU from the Sun."),
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(reach)) %>%
finish_3d(c(`Out to Jupiter`=6,`Out to Neptune`=32,`Out to 60 AU`=reach))The orbits are drawn out to 60 AU: Hale–Bopp’s goes on to about 362 AU, and the visitors’ paths go on for ever. A comet on a closed orbit comes back; a visitor passes once, and leaves.
The solar system is mostly empty, and it reaches much further than the planets.
What this does not show. The orbits are those of today: the planets pull on each other, and on every small body, so each orbit changes slowly, and a comet’s next perihelion can come a few days earlier or later than its orbit of today says: for Halley’s comet, the orbit of today says 1 August 2061, its path, which takes in the pulls of the planets, 28 July 2061. The Sun, the planets and the dots of the small bodies are not drawn to scale: at the scale of the orbits even the Sun would be smaller than a pixel. The asteroids shown are only the brightest of the main belt and of the Trojans: hundreds of thousands more are known. The objects beyond Neptune are those that JPL’s database knows, which is where telescopes have looked, not all that are there. And the solar system goes on far beyond the furthest of them: the Oort cloud, from which long-period comets are thought to come, has never been seen.
Rendered with R 4.6.2 · plotly · jsonlite
---
title: "Where Everything Is Today: The Solar System in 3D"
description: "The Sun, the planets, thousands of asteroids and objects beyond Neptune, comets, three visitors from other stars and the five spacecraft that are leaving the solar system, each placed where it is today from NASA JPL's Horizons system and Small-Body Database, in 3D charts made with plotly: how far light has to travel, what lies beyond Neptune, where the spacecraft are going, and which comets will come back."
author: ""
---
```{r setup, include=FALSE}
directory<-""
if(rstudioapi::isAvailable())
directory<-paste0(dirname(rstudioapi::getActiveDocumentContext()$path),"/")
source(paste0(directory,"R/code_options.R"))
```
## What is this?
Everything in the solar system moves, each body on its own orbit around the Sun. This story places the planets, the asteroids, the comets and the spacecraft that are leaving the solar system where they are today, and asks five questions:
1. **Where is everything today?**
2. **How far is far?**
3. **What lies beyond Neptune?**
4. **Where are the spacecraft going?**
5. **Which comets come back, and which never will?**
The data are NASA's, from its Jet Propulsion Laboratory (JPL): the orbits of the planets, the dwarf planets and the comets, and the paths of the spacecraft, from its **Horizons** system, which computes them from the JPL ephemerides ([Park et al. 2021](https://doi.org/10.3847/1538-3881/abd414)); and the orbits of thousands of asteroids and of every known object beyond Neptune from its **Small-Body Database**. They are downloaded when the page is rendered. The charts can be turned with the mouse and zoomed, and every body shows its name when the pointer is over it. The page follows [The Crowded Sky](ILLUSTRATION_SATELLITES.html), which does the same for the satellites around the Earth.
**The words of this page:**
- an **AU** (astronomical unit) is about the average distance from the Earth to the Sun: 149,597,870.7 km. Light covers it in 8 minutes and 19 seconds;
- an **orbit** is the path of a body around the Sun: an ellipse, a stretched circle with the Sun at one of its two foci. **Perihelion** is its point closest to the Sun, **aphelion** its point furthest away. An orbit can also be open (a **hyperbola**): then the body passes the Sun once and leaves for ever;
- the **ecliptic** is the plane of the Earth's orbit. The charts are drawn on it, seen from its north side, where the planets go round the Sun anticlockwise; most orbits lie close to it;
- **asteroids** are small rocky bodies. Most of them orbit in the **main belt**, between Mars and Jupiter; **Jupiter's Trojans** share Jupiter's orbit, in two crowds, one ahead of the planet and one behind it;
- the **Kuiper belt** is a ring of icy bodies beyond Neptune. **Dwarf planets**, such as Pluto and Eris, are round like planets but share their orbits with many other bodies;
- **comets** are lumps of ice and dust on stretched orbits; near the Sun, their ice turns to gas and they grow a tail;
- the **heliosphere** is the bubble that the wind of the Sun blows into the gas between the stars; its edge, the **heliopause**, is where interstellar space begins.
---
## Packages
```{r packages}
# install.packages(c("plotly","jsonlite"))
library(plotly)
```
## The data
An orbit is given by six numbers: its size, its shape, its tilt to the ecliptic, how it is turned around the Sun and within its own plane, and where the body is on it at a given moment. Horizons gives these numbers for each planet, dwarf planet and comet as they are today (its **osculating** orbit: the orbit that the body would keep if the planets stopped pulling on it), and the page draws the orbit and places the body from them. For the spacecraft, Horizons gives the path itself, from launch to today. The Small-Body Database gives the orbits of the asteroids and of the objects beyond Neptune at an earlier moment, and Kepler's equation moves each one along its orbit to today.
```{r download}
# the copies of the answers kept on this computer: an answer of Horizons is kept under the date of
# the page and downloaded at most once a day; the orbits of the small bodies change little and are
# downloaded again after 30 days. A service that does not answer is asked again, up to three more
# times, 10 seconds apart; if it still does not answer, an older copy is used if there is one
kept<-tools::R_user_dir("illustration",which="cache")
dir.create(kept,recursive=TRUE,showWarnings=FALSE)
download_kept<-function(url,name,hours=Inf,tries=4) {
file<-file.path(kept,name)
if(file.exists(file)&&difftime(Sys.time(),file.mtime(file),units="hours")<hours)
return(file)
temporary<-tempfile()
for(k in seq_len(tries)) {
done<-tryCatch(download.file(url,temporary,quiet=TRUE,mode="wb")==0,
error=function(e) FALSE,warning=function(w) FALSE)
if(done) {
file.copy(temporary,file,overwrite=TRUE)
# at most one question a second to the services
Sys.sleep(1)
return(file)
}
if(k<tries)
Sys.sleep(10)
}
if(file.exists(file))
return(file)
stop("Could not download ",url)
}
# a name as a part of a file name: "Comet Hale–Bopp" becomes "comet_hale_bopp"
slug<-function(x) {
result<-gsub("^_|_$","",gsub("[^a-z0-9]+","_",tolower(iconv(x,to="ASCII//TRANSLIT"))))
return(result)
}
# a question to Horizons: the orbit (ELEMENTS) or the positions (VECTORS) of a body, seen from the
# center of the Sun, on the plane of the ecliptic, in AU and days
horizons<-function(command,type,start,stop,step) {
values<-c(COMMAND=command,OBJ_DATA="NO",MAKE_EPHEM="YES",EPHEM_TYPE=type,CENTER="500@10",
START_TIME=start,STOP_TIME=stop,STEP_SIZE=step,REF_PLANE="ECLIPTIC",
OUT_UNITS="AU-D",CSV_FORMAT="YES",VEC_TABLE="1")
query<-paste0(names(values),"=",vapply(paste0("'",values,"'"),URLencode,"",reserved=TRUE),
collapse="&")
result<-paste0("https://ssd.jpl.nasa.gov/api/horizons.api?format=json&",query)
return(result)
}
# the table of an answer of Horizons, between its lines $$SOE and $$EOE, with its column names
horizons_table<-function(file) {
text<-jsonlite::fromJSON(file)$result
lines<-strsplit(text,"\n")[[1]]
first<-which(lines=="$$SOE")
last<-which(lines=="$$EOE")
if(!length(first))
stop("Horizons gave no table: ",substr(text,1,300))
header<-trimws(strsplit(lines[first-2],",")[[1]])
rows<-read.csv(text=paste(lines[(first+1):(last-1)],collapse="\n"),header=FALSE,
strip.white=TRUE)[,seq_along(header)]
names(rows)<-header
result<-rows[,header!=""]
return(result)
}
# a question to the Small-Body Database: the orbits of a class of small bodies, with a condition
sbdb<-function(class,condition=NULL) {
query<-c(fields="full_name,a,e,i,om,w,ma,epoch,H",`sb-class`=class)
if(!is.null(condition))
query<-c(query,`sb-cdata`=condition)
url<-paste0("https://ssd-api.jpl.nasa.gov/sbdb_query.api?",
paste0(names(query),"=",vapply(query,URLencode,"",reserved=TRUE),collapse="&"))
answer<-jsonlite::fromJSON(download_kept(url,paste0("sbdb_",tolower(class),".json"),
hours=24*30))
result<-as.data.frame(answer$data,stringsAsFactors=FALSE)
names(result)<-answer$fields
for(v in c("a","e","i","om","w","ma","epoch","H"))
result[[v]]<-as.numeric(result[[v]])
result$name<-trimws(result$full_name)
# a body whose orbit is too poorly known to place it on it (no mean anomaly) is left out
result<-result[complete.cases(result[,c("a","e","i","om","w","ma","epoch")]),]
return(result)
}
```
```{r orbits}
# the day of the page, at 0:00 UTC
today<-as.Date(format(Sys.time(),"%Y-%m-%d",tz="UTC"))
today_jd<-as.numeric(today)+2440587.5 # its Julian date
d2r<-pi/180
# a point of an orbit, in AU from the Sun: x towards the March equinox, y 90° further along the
# ecliptic, z towards the north of the ecliptic. q: the distance at perihelion, e: the shape (0 a
# circle, below 1 an ellipse, above 1 a hyperbola), the angles in radians, and nu the angle from
# the perihelion, seen from the Sun (the true anomaly)
orbit_point<-function(q,e,tilt,node,perihelion,nu) {
r<-q*(1+e)/(1+e*cos(nu))
u<-perihelion+nu
result<-data.frame(x=r*(cos(node)*cos(u)-sin(node)*sin(u)*cos(tilt)),
y=r*(sin(node)*cos(u)+cos(node)*sin(u)*cos(tilt)),
z=r*sin(u)*sin(tilt))
return(result)
}
# the line of an orbit from Horizons' numbers, in 360 steps; an orbit that reaches further than
# `reach` AU from the Sun, as an open orbit always does, is drawn only where it is closer
orbit_line<-function(b,reach=Inf) {
far<-if(b$EC<1) b$QR*(1+b$EC)/(1-b$EC) else Inf
limit<-if(far<=reach) pi else acos((b$QR*(1+b$EC)/reach-1)/b$EC)
result<-orbit_point(b$QR,b$EC,b$IN*d2r,b$OM*d2r,b$W*d2r,seq(-limit,limit,length.out=361))
return(result)
}
# where small bodies are today, from the orbits of the Small-Body Database at an earlier moment
# (epoch): each moves on along its orbit by its mean motion, from Gauss's constant (the Sun's
# gravity: radians a day on an orbit of 1 AU), and Kepler's equation gives the place
gauss<-0.01720209895
place_today<-function(s) {
motion<-gauss/s$a^1.5
anomaly<-(s$ma*d2r+motion*(today_jd-s$epoch))%%(2*pi)
# Kepler's equation, solved by Newton's method, starting from pi for very stretched orbits
eccentric<-ifelse(s$e>0.8,pi,anomaly)
for(step in 1:50)
eccentric<-eccentric-(eccentric-s$e*sin(eccentric)-anomaly)/(1-s$e*cos(eccentric))
nu<-2*atan2(sqrt(1+s$e)*sin(eccentric/2),sqrt(1-s$e)*cos(eccentric/2))
result<-cbind(s,orbit_point(s$a*(1-s$e),s$e,s$i*d2r,s$om*d2r,s$w*d2r,nu))
result$r<-sqrt(result$x^2+result$y^2+result$z^2)
return(result)
}
```
```{r bodies}
# the planets, the dwarf planets, three comets and the three visitors from other stars that are
# known, with the names that Horizons knows them by
bodies<-data.frame(
name=c("Mercury","Venus","Earth","Mars","Jupiter","Saturn","Uranus","Neptune",
"Ceres","Pluto","Haumea","Makemake","Eris",
"Halley's comet","Comet 67P","Comet Hale–Bopp",
"1I/ʻOumuamua","2I/Borisov","3I/ATLAS"),
command=c("199","299","399","499","599","699","799","899",
"1;","999","136108;","136472;","136199;",
"DES=1P;CAP","DES=67P;CAP","C/1995 O1",
"A/2017 U1","C/2019 Q4","C/2025 N1"),
kind=c(rep("planet",8),rep("dwarf",5),rep("comet",3),rep("visitor",3)))
# their orbits as they are today: the shape (EC), the distance at perihelion (QR), the tilt (IN),
# the turns (OM, W), the date of perihelion (Tp, a Julian date), the angle from the perihelion
# today (TA) and the size (A, half the longest width; negative for an open orbit)
elements<-lapply(seq_len(nrow(bodies)),function(k)
horizons_table(download_kept(horizons(bodies$command[k],"ELEMENTS",format(today),
format(today+1),"1 d"),
paste0("horizons_",slug(bodies$name[k]),"_",today,".json")))[1,])
bodies<-cbind(bodies,do.call(rbind,elements)[,c("EC","QR","IN","OM","W","Tp","TA","A")])
bodies<-cbind(bodies,with(bodies,orbit_point(QR,EC,IN*d2r,OM*d2r,W*d2r,TA*d2r)))
bodies$r<-sqrt(bodies$x^2+bodies$y^2+bodies$z^2)
rownames(bodies)<-bodies$name
# the asteroids of the main belt whose absolute magnitude H is below 12, the brightest and so
# mostly the largest; Jupiter's Trojans with H below 13; and every object known beyond Neptune
main_belt<-place_today(sbdb("MBA",'{"AND":["H|LT|12"]}'))
trojans<-place_today(sbdb("TJN",'{"AND":["H|LT|13"]}'))
kuiper<-place_today(sbdb("TNO"))
# the five spacecraft that are leaving the solar system: their paths from a few days after launch to
# today, in 600 steps
probes<-data.frame(name=c("Pioneer 10","Pioneer 11","Voyager 2","Voyager 1","New Horizons"),
command=c("-23","-24","-32","-31","-98"),
start=as.Date(c("1972-03-05","1973-04-08","1977-08-23","1977-09-08",
"2006-01-21")))
paths<-lapply(seq_len(nrow(probes)),function(k) {
file<-download_kept(horizons(probes$command[k],"VECTORS",format(probes$start[k]),format(today),
"600"),
paste0("horizons_path_",slug(probes$name[k]),"_",today,".json"))
path<-horizons_table(file)
data.frame(date=as.Date(path$JDTDB-2440587.5),x=path$X,y=path$Y,z=path$Z)
})
names(paths)<-probes$name
for(k in names(paths))
paths[[k]]$r<-sqrt(paths[[k]]$x^2+paths[[k]]$y^2+paths[[k]]$z^2)
probes$r<-vapply(paths,function(p) p$r[nrow(p)],0)
```
```{r chart_style}
dark_gray<-"#6b6b6b" # also the color of the notes
orbit_gray<-"#b3b3b3"
planet_gray<-"#8f8f8f" # the bars of the planets
ink<-"#191919"
sun_yellow<-"#f2a600"
# the colors of the groups, told apart also by color-blind readers (each set checked)
blue<-"#257de0"
orange<-"#f47230"
green<-"#00b894"
probe_colour<-c(`Pioneer 10`=blue,`Pioneer 11`=orange,`Voyager 2`=green,`Voyager 1`="#6a4ce2",
`New Horizons`="#ee7fac")
# the source of a chart, as a note under it, and the common layout; note_shift moves the note down
# by a number of pixels, which stays the same however tall the plot is
chart<-function(p,title,source,y_title="",x_title="",y_axis=list(),x_axis=list(),
annotations=list(),margin=list(t=70,b=90),note_y=-0.16,note_shift=0,...) {
note<-list(text=paste("Source:",source),xref="paper",yref="paper",x=0,y=note_y,xanchor="left",
yanchor="top",yshift=note_shift,align="left",showarrow=FALSE,
font=list(size=11,color=dark_gray))
result<-layout(p,
title=list(text=title,x=0.02,xanchor="left",y=0.97,yanchor="top"),
margin=margin,
annotations=c(annotations,list(note)),
...)
if(nchar(paste0(y_title,x_title))>0||length(c(y_axis,x_axis))>0)
result<-layout(result,yaxis=modifyList(list(title=y_title),y_axis),
xaxis=modifyList(list(title=x_title),x_axis))
result<-config(result,displaylogo=FALSE)
return(result)
}
legend_top<-list(orientation="h",x=0,y=1.02,yanchor="bottom",itemsizing="constant")
horizons_source<-"NASA JPL Horizons: osculating orbits of today, Sun-centred, on the ecliptic."
sbdb_source<-"NASA JPL Small-Body Database, moved along their orbits to today."
# short labels of numbers and dates
number<-function(x) {
result<-format(round(x),big.mark=",",trim=TRUE,scientific=FALSE)
return(result)
}
one<-function(x) {
result<-format(round(x,1),nsmall=1,trim=TRUE)
return(result)
}
date_words<-function(x) {
result<-paste(as.integer(format(x,"%d")),month.name[as.integer(format(x,"%m"))],format(x,"%Y"))
return(result)
}
month_words<-function(x) {
result<-paste(month.name[as.integer(format(x,"%m"))],format(x,"%Y"))
return(result)
}
jd_date<-function(jd) {
result<-as.Date(jd-2440587.5)
return(result)
}
when<-date_words(today)
# 3D charts. Distances in hundredths of an AU, as whole numbers: plotly for R writes any other
# number with 17 digits (8.49 as 8.4900000000000002). The axes are hidden, all three as long as each
# other, out to r AU from the Sun, and the view is from above the ecliptic, a little to one side
au<-function(x) {
result<-round(100*x)
return(result)
}
eye<-c(x=0.45,y=-1.05,z=0.75)
space_scene<-function(r) {
axis<-list(range=c(-100*r,100*r),visible=FALSE)
result<-list(xaxis=axis,yaxis=axis,zaxis=axis,aspectmode="cube",dragmode="turntable",
camera=list(eye=as.list(eye)))
return(result)
}
# the directions to the right and upwards on the screen, as the charts are first seen from the eye
forward<-(-eye)/sqrt(sum(eye^2))
screen_right<-c(forward[["y"]],-forward[["x"]],0)/sqrt(forward[["x"]]^2+forward[["y"]]^2)
screen_up<-c(screen_right[2]*forward[["z"]],-screen_right[1]*forward[["z"]],
screen_right[1]*forward[["y"]]-screen_right[2]*forward[["x"]])
# the side of each body on which its name is written: away from the Sun as the chart is first
# seen; and two bodies close together on the screen (less than a quarter of the view apart) with
# their names on the same side get one name to the left and one to the right, the closest pairs
# first, each body once. view: the distance from the Sun in view, in AU
label_sides<-function(b,view) {
position<-as.matrix(b[,c("x","y","z")])/view
across<-as.vector(position%*%screen_right)
up<-as.vector(position%*%screen_up)
vertical<-ifelse(abs(up)<0.4*abs(across),"middle",ifelse(up>=0,"top","bottom"))
side<-ifelse(across>=0,"right","left")
pairs<-which(upper.tri(diag(length(side))),arr.ind=TRUE)
apart<-sqrt((across[pairs[,1]]-across[pairs[,2]])^2+(up[pairs[,1]]-up[pairs[,2]])^2)
moved<-rep(FALSE,length(side))
for(k in order(apart)) {
i<-pairs[k,1]
j<-pairs[k,2]
if(apart[k]<0.25&&!moved[i]&&!moved[j]&&vertical[i]==vertical[j]&&side[i]==side[j]) {
side[c(i,j)]<-if(across[i]<across[j]) c("left","right") else c("right","left")
moved[c(i,j)]<-TRUE
}
}
# a body near the left or right edge gets its name on the side towards the Sun, and above it if
# it was beside it, so that the name is not cut off on a narrow screen
edge<-abs(across)>0.6
vertical[edge&vertical=="middle"]<-"top"
side[edge]<-ifelse(across[edge]>0,"left","right")
result<-paste(vertical,side)
return(result)
}
# the orbits of several bodies as one line, with a gap after each orbit
orbit_lines<-function(b,reach=Inf) {
lines<-lapply(seq_len(nrow(b)),function(k) rbind(orbit_line(b[k,],reach),NA))
result<-do.call(rbind,lines)
result<-data.frame(x=au(result$x),y=au(result$y),z=au(result$z))
return(result)
}
# the Sun, and bodies as points with their names next to them; view: as in label_sides, others:
# bodies of the same chart added apart, whose names they must not cover, and group: the legend
# entry of their orbits, which then turn on and off with them
add_sun<-function(p,legend=TRUE) {
result<-add_trace(p,x=0,y=0,z=0,type="scatter3d",mode="markers",name="Sun",showlegend=legend,
marker=list(color=sun_yellow,size=8,line=list(color=ink,width=1)),
hovertemplate="<b>Sun</b><extra></extra>",inherit=FALSE)
return(result)
}
add_bodies<-function(p,b,name,view,colour=ink,size=4,others=NULL,group=NULL) {
sides<-label_sides(rbind(b[,c("x","y","z")],others[,c("x","y","z")]),view)[seq_len(nrow(b))]
result<-add_trace(p,data=data.frame(x=au(b$x),y=au(b$y),z=au(b$z),label=b$name,
hover=paste0("<b>",b$name,"</b><br>",one(b$r),
" AU from the Sun")),
x=~x,y=~y,z=~z,type="scatter3d",mode="markers+text",name=name,text=~label,
textposition=sides,textfont=list(size=11,color=ink),
customdata=~hover,hovertemplate="%{customdata}<extra></extra>",
marker=list(color=colour,size=size,line=list(color="#ffffff",width=1)),
legendgroup=group,inherit=FALSE)
return(result)
}
# a 3D chart is built once and its second copy of every number ("attrs") dropped. zooms: buttons
# that zoom in and out, a label and a distance from the Sun in AU for each. At every zoom a name
# is written only next to a body more than 6% of that distance from the Sun, so that the names of
# the bodies close to the Sun do not pile up on it; the chart opens at the zoom of its scene
finish_3d<-function(p,zooms=NULL) {
result<-plotly_build(p)
result$x$attrs<-NULL
if(is.null(zooms))
return(result)
named<-which(vapply(result$x$data,function(t) grepl("text",paste(t$mode,collapse="")),TRUE))
labels<-lapply(result$x$data[named],function(t) t$text)
far<-lapply(result$x$data[named],function(t) sqrt(t$x^2+t$y^2+t$z^2)/100)
zooms<-c(open=result$x$layout$scene$xaxis$range[2]/100,zooms)
shown<-lapply(zooms,function(view) Map(function(l,r) ifelse(r>0.06*view,l,""),labels,far))
for(k in seq_along(named))
result$x$data[[named[k]]]$text<-shown$open[[k]]
buttons<-lapply(names(zooms)[-1],function(z) {
range<-c(-100,100)*zooms[[z]]
list(label=z,method="update",
args=list(list(text=unname(shown[[z]])),
list(scene.xaxis.range=range,scene.yaxis.range=range,scene.zaxis.range=range),
as.list(named-1)))
})
result$x$layout$updatemenus<-list(list(type="buttons",direction="right",x=0,y=0,xanchor="left",
yanchor="top",showactive=FALSE,buttons=buttons))
return(result)
}
planets<-bodies[bodies$kind=="planet",]
```
---
## 1. Where is everything today?
```{r today_numbers}
earth<-bodies["Earth",]
jupiter<-bodies["Jupiter",]
# the angle of each Trojan ahead of Jupiter (+) or behind it (−), along the ecliptic, in degrees
longitude<-function(x,y) {
result<-atan2(y,x)/d2r
return(result)
}
trojans$ahead<-((longitude(trojans$x,trojans$y)-longitude(jupiter$x,jupiter$y)+180)%%360)-180
leading<-trojans$ahead>0
belt_range<-quantile(main_belt$a,c(0.05,0.95))
# the time that each planet takes to go round the Sun, in years: by Kepler's third law, the size
# of its orbit (half its longest width, in AU) to the power 1.5
planets$years<-planets$A^1.5
```
**Eight planets in nearly one plane, and two crowds of asteroids.** On `r when`, the Earth was `r format(round(earth$r,3),nsmall=3)` AU from the Sun. Between Mars and Jupiter, the `r number(nrow(main_belt))` brightest asteroids of the main belt orbit between `r one(belt_range[[1]])` and `r one(belt_range[[2]])` AU from the Sun (nine out of ten of them). Further out, Jupiter's `r number(nrow(trojans))` brightest Trojans travel along its orbit in two crowds: `r number(sum(leading))` about `r number(median(trojans$ahead[leading]))`° ahead of the planet, and `r number(sum(!leading))` about `r number(-median(trojans$ahead[!leading]))`° behind it, at the two points where the pulls of the Sun and of Jupiter hold them.
```{r today, fig.height = 7}
#| fig-alt: "3D chart of the solar system today, seen from above the plane of the planets: the Sun in the middle, the orbits of the inner planets as gray rings, a ring of thousands of blue points, the main asteroid belt, between Mars and Jupiter, and two clouds of orange points, Jupiter's Trojans, ahead of Jupiter and behind it on its orbit"
p<-plot_ly() %>%
add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip")
for(g in list(list(data=main_belt,colour=blue,name="Main belt"),
list(data=trojans,colour=orange,name="Jupiter's Trojans"))) {
points<-data.frame(x=au(g$data$x),y=au(g$data$y),z=au(g$data$z),
hover=paste0("<b>",g$data$name,"</b><br>",one(g$data$r)," AU from the Sun"))
p<-add_trace(p,data=points,x=~x,y=~y,z=~z,type="scatter3d",mode="markers",
name=paste0(g$name,": ",number(nrow(g$data))),customdata=~hover,
hovertemplate="%{customdata}<extra></extra>",
marker=list(color=g$colour,size=1.6,line=list(width=0)),inherit=FALSE)
}
p %>%
add_sun() %>%
add_bodies(planets,"Planets",6) %>%
chart(paste("The solar system on",when),paste(horizons_source,sbdb_source),
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(6)) %>%
finish_3d(c(`Inner planets`=1.8,`Out to Jupiter`=6,`Out to Neptune`=32))
```
Each gray ring is the orbit of a planet, and each planet stands where it is today. **Inner planets** zooms in on Mercury, Venus, the Earth and Mars; **Out to Neptune** shows the four giants, and how far apart they are: the main belt and everything inside it shrink to a small disc around the Sun. Seen from this side, they all go round the Sun anticlockwise: the Earth in a year, Jupiter in `r one(planets["Jupiter","years"])` years and Neptune in `r number(planets["Neptune","years"])`.
---
## 2. How far is far?
```{r far_numbers}
light_seconds<-499.004784 # seconds that light takes to cover 1 AU
light_day<-86400/light_seconds # AU that light covers in a day
# Voyager 1 and the Earth every day from 2026 to 2028: when is Voyager 1 one light-day away from us?
window<-c("2026-01-01","2028-12-31")
daily<-lapply(c(`Voyager 1`="-31",Earth="399"),function(command)
horizons_table(download_kept(horizons(command,"VECTORS",window[1],window[2],"1 d"),
paste0("horizons_daily_",gsub("[^0-9]","",command),"_",
paste(window,collapse="_"),".json"))))
apart<-sqrt((daily$`Voyager 1`$X-daily$Earth$X)^2+(daily$`Voyager 1`$Y-daily$Earth$Y)^2+
(daily$`Voyager 1`$Z-daily$Earth$Z)^2)
days<-jd_date(daily$Earth$JDTDB)
first_day<-days[which(apart>light_day)[1]]
for_good<-days[max(which(apart<=light_day))+1]
voyager1<-paths[["Voyager 1"]][nrow(paths[["Voyager 1"]]),]
voyager1_earth<-sqrt((voyager1$x-earth$x)^2+(voyager1$y-earth$y)^2+(voyager1$z-earth$z)^2)
# the sentence about it: before, on or after the first day, and whether it comes back within a
# light-day while the Earth goes round the Sun, now towards Voyager 1 and now away from it
light_day_words<-paste0("one light-day (",one(light_day)," AU)")
voyager_day<-paste(if(today<first_day) "It will be" else "It was",light_day_words,
"away from the Earth for the first time on",date_words(first_day))
voyager_day<-if(for_good>first_day)
paste0(voyager_day,", and as the Earth goes round the Sun, now towards it and now away, ",
if(today<for_good) "it will come" else "it came"," back within a light-day until ",
date_words(for_good-1),".") else
paste0(voyager_day,", and it will never again be closer.")
# light time from the Sun, in hours, to the planets, Pluto, Eris and the spacecraft
chosen<-bodies[bodies$kind=="planet"|bodies$name%in%c("Pluto","Eris"),]
far<-rbind(data.frame(name=chosen$name,r=chosen$r,colour=planet_gray),
data.frame(name=probes$name,r=probes$r,colour=probe_colour[probes$name]))
far$hours<-far$r*light_seconds/3600
far<-far[order(far$r),]
light_words<-function(hours) {
result<-ifelse(hours<1,paste(one(60*hours),"min"),paste(one(hours),"h"))
return(result)
}
proxima<-4.24*365.25*24 # light-hours to the nearest star, Proxima Centauri, 4.24 light-years
```
**Light takes `r one(light_seconds/60)` minutes to reach us from the Sun, and almost a day to reach Voyager 1.** Light from the Sun reaches Neptune in `r one(bodies["Neptune","r"]*light_seconds/3600)` hours and Eris, `r one(bodies["Eris","r"])` AU away today, in `r one(bodies["Eris","r"]*light_seconds/3600)` hours. Voyager 1, the furthest spacecraft, is `r one(voyager1$r)` AU from the Sun: `r one(voyager1$r*light_seconds/3600)` light-hours, or `r one(voyager1$r*0.1495978707)` billion km. Today it is `r one(voyager1_earth)` AU from the Earth, so its radio signals take `r one(voyager1_earth*light_seconds/3600)` hours to reach us. `r voyager_day`
```{r far, fig.height = 5.4}
#| fig-alt: "Bar chart of how long light takes to reach each planet, Pluto, Eris and five spacecraft from the Sun, on a logarithmic scale: minutes for the inner planets, hours for the outer ones, and almost a day for Voyager 1"
far$label<-light_words(far$hours)
plot_ly(far,x=~hours,y=~name,type="bar",orientation="h",marker=list(color=~I(colour)),
text=~label,textposition="outside",cliponaxis=FALSE,customdata=~one(r),
hovertemplate="<b>%{y}</b>: %{customdata} AU, %{text}<extra></extra>") %>%
chart(paste("How long light takes to get there from the Sun,",when),
"NASA JPL Horizons: the distance of each from the Sun today.",
x_title="Light time from the Sun (a logarithmic scale)",
x_axis=list(type="log",tickvals=c(1/60,10/60,1,10,24),
ticktext=c("1 min","10 min","1 h","10 h","1 day"),range=log10(c(0.02,60))),
y_axis=list(categoryorder="array",categoryarray=far$name,title=""),
margin=list(t=60,b=110,l=110),note_y=-0.2)
```
Gray bars are planets and dwarf planets, colored bars spacecraft, in the colors of their paths in question 4. From one mark of the scale to the next, the time grows tenfold. Voyager 1 is `r one(voyager1$r/bodies["Neptune","r"])` times as far from the Sun as Neptune, after `r number(as.numeric(today-as.Date("1977-09-05"))/365.25)` years of travel. Yet the nearest star, Proxima Centauri, 4.24 light-years away, is about `r number(round(proxima/(voyager1$r*light_seconds/3600),-1))` times as far as Voyager 1.
---
## 3. What lies beyond Neptune?
```{r kuiper_numbers}
neptune<-bodies["Neptune",]
pluto<-bodies["Pluto",]
eris<-bodies["Eris",]
# where an orbit goes round the Sun 2 times for every 3 of Neptune's (3:2), 1 for every 2 (2:1) or
# 2 for every 5 (5:2): by Kepler's third law, at the size of Neptune's orbit times the ratio of the
# times to the power 2/3
resonance<-c(`3:2`=neptune$A*(3/2)^(2/3),`2:1`=neptune$A*2^(2/3),`5:2`=neptune$A*(5/2)^(2/3))
near_32<-abs(kuiper$a-resonance[["3:2"]])<0.4
classical<-kuiper$a>42&kuiper$a<resonance[["2:1"]]
# orbits larger than 50 AU, and those of them that are nearly round: their furthest point less than
# 1.5 times as far from the Sun as their closest (a shape, e, below 0.2)
beyond_50<-kuiper$a>50
round_50<-beyond_50&kuiper$e<0.2
pluto_perihelion<-jd_date(pluto$Tp)
inside_neptune<-pluto$QR<neptune$QR
```
**Thousands of icy bodies, gathered where Neptune's rhythm lets them be.** JPL's database knows the orbits of `r number(nrow(kuiper))` objects beyond Neptune's. `r number(sum(near_32))` of them, `r round(100*mean(near_32))`%, have orbits within 0.4 AU of `r one(resonance[["3:2"]])` AU in size, where a body goes round the Sun twice while Neptune goes round three times (the **3:2 resonance**). Pluto is one of them, and so they are called **plutinos**: its orbit comes `r if(inside_neptune) "closer to the Sun than Neptune's" else "close to Neptune's"` (its last perihelion was in `r format(pluto_perihelion,"%Y")`), but the rhythm keeps the two from ever meeting. That many bodies would share Pluto's rhythm, and gather at the 2:1 resonance (`r one(resonance[["2:1"]])` AU) too, was predicted when only a few were known ([Malhotra 1995](https://doi.org/10.1086/117532)). `r number(sum(classical))` more, the **classical belt**, have orbits between 42 AU and the 2:1 resonance. Further out the crowd changes: `r round(100*mean(beyond_50))`% of the orbits are larger than 50 AU, but only `r number(sum(round_50))` of these `r number(sum(beyond_50))` are nearly round. The rest are long and stretched, most of them thought to belong to bodies that Neptune threw outward (the **scattered disc**): the belt of nearly round orbits seems to end near 50 AU ([Trujillo and Brown 2001](https://doi.org/10.1086/320917)). Today Pluto is `r one(pluto$r)` AU from the Sun, and Eris, the most massive dwarf planet known, `r one(eris$r)` AU.
```{r kuiper, fig.height = 7}
#| fig-alt: "3D chart of the Kuiper belt today: a wide, thick ring of thousands of green points around the orbits of the planets, with the orbits of the dwarf planets Pluto, Haumea, Makemake and Eris as gray lines, tilted to the plane of the planets"
dwarfs<-bodies[bodies$kind=="dwarf"&bodies$name!="Ceres",]
points<-data.frame(x=au(kuiper$x),y=au(kuiper$y),z=au(kuiper$z),
hover=paste0("<b>",kuiper$name,"</b><br>",one(kuiper$r)," AU from the Sun"))
plot_ly() %>%
add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip") %>%
add_trace(data=orbit_lines(dwarfs),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the dwarf planets",hoverinfo="skip",
line=list(color=dark_gray,width=2,dash="dash")) %>%
add_trace(data=points,x=~x,y=~y,z=~z,type="scatter3d",mode="markers",
name=paste0("Beyond Neptune: ",number(nrow(kuiper))),customdata=~hover,
hovertemplate="%{customdata}<extra></extra>",
marker=list(color=green,size=1.6,line=list(width=0)),inherit=FALSE) %>%
add_sun() %>%
add_bodies(bodies[c("Jupiter","Saturn","Uranus","Neptune",dwarfs$name),],
"Planets and dwarf planets",55) %>%
chart(paste("Beyond Neptune on",when),paste(horizons_source,sbdb_source),
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(55)) %>%
finish_3d(c(`The Kuiper belt`=55,`Out to Eris`=100))
```
```{r resonance, fig.height = 4.8}
#| fig-alt: "Bar chart of how many objects beyond Neptune have orbits of each size, from 30 to 80 AU: a tall peak at 39.4 AU, where Neptune's 3:2 resonance lies, a broad hump from 42 to 47.7 AU, Neptune's 2:1 resonance, and few beyond 50 AU"
breaks<-seq(30,80,by=0.5)
counts<-table(cut(kuiper$a,breaks,right=FALSE))
bars<-data.frame(a=breaks[-length(breaks)]+0.25,objects=as.vector(counts))
marks<-lapply(names(resonance),function(k)
list(type="line",x0=resonance[[k]],x1=resonance[[k]],y0=0,y1=1,yref="paper",
line=list(color=dark_gray,width=1.5,dash="dot")))
labels<-lapply(names(resonance),function(k)
list(x=resonance[[k]],y=1,yref="paper",text=k,showarrow=FALSE,
xanchor="left",yanchor="top",xshift=4,font=list(size=12,color=dark_gray)))
plot_ly(bars,x=~a,y=~objects,type="bar",marker=list(color=green),
hovertemplate="%{x:.1f} AU: %{y} objects<extra></extra>") %>%
chart("Objects beyond Neptune by the size of their orbit, and Neptune's rhythms",
"NASA JPL Small-Body Database.",
"Objects (every half AU)","Half the longest width of the orbit, AU",
x_axis=list(range=c(30,80),showgrid=FALSE),shapes=marks,annotations=labels,bargap=0.05,
margin=list(t=70,b=100),note_y=-0.25)
```
Each bar counts the orbits of one size, measured by half their longest width, and the dotted lines mark Neptune's rhythms. The tall spike at `r one(resonance[["3:2"]])` AU is the plutinos; the broad hump from 42 AU is the classical belt, which ends at the 2:1 resonance; and further out, a smaller spike sits at `r one(resonance[["5:2"]])` AU, where a body goes round the Sun twice while Neptune goes round five times (the 5:2 resonance).
---
## 4. Where are the spacecraft going?
```{r probe_numbers}
# the distance of a spacecraft from the Sun on a date, from its path
distance_on<-function(name,date) {
result<-approx(paths[[name]]$date,paths[[name]]$r,xout=as.Date(date))$y
return(result)
}
# how fast each moves away from the Sun now, in AU a year: over the last year of its path
speed<-vapply(probes$name,function(k) {
p<-paths[[k]]
back<-which.min(abs(p$date-(today-365)))
(p$r[nrow(p)]-p$r[back])/as.numeric(p$date[nrow(p)]-p$date[back])*365.25
},0)
events<-data.frame(name=c("Voyager 1","Voyager 2","Pioneer 11","Pioneer 10"),
date=as.Date(c("2012-08-25","2018-11-15","1995-11-24","2003-01-23")),
what=c("left the heliosphere","left the heliosphere","last signal",
"last signal"))
events$r<-mapply(distance_on,events$name,events$date)
furthest<-probes[order(-probes$r),]
```
**Five spacecraft are on paths that will take them out of the solar system for good** ([NASA 2025b](https://science.nasa.gov/mission/pioneer-11/)). Voyager 1 is the furthest, `r one(furthest$r[1])` AU from the Sun, and moves away by `r one(speed[["Voyager 1"]])` AU a year; then come `r paste(paste0(furthest$name[2:4]," (",one(furthest$r[2:4])," AU)"),collapse=", ")` and New Horizons, launched in 2006 to Pluto, at `r one(probes$r[probes$name=="New Horizons"])` AU. Voyager 1 left the heliosphere for interstellar space in August 2012, `r one(events$r[1])` AU from the Sun ([Gurnett et al. 2013](https://doi.org/10.1126/science.1241681)), and Voyager 2 in November 2018, at about `r number(events$r[2])` AU ([Stone et al. 2019](https://doi.org/10.1038/s41550-019-0928-3)). The two Pioneers are silent: Pioneer 11 sent its last data in November 1995, `r number(events$r[3])` AU from the Sun, and Pioneer 10 its last signal in January 2003, at `r number(events$r[4])` AU ([NASA 2025a](https://science.nasa.gov/mission/pioneer-10/), [2025b](https://science.nasa.gov/mission/pioneer-11/)); their places today are computed from the paths they were on.
```{r probes, fig.height = 7}
#| fig-alt: "3D chart of the paths of five spacecraft from launch to today, seen from above the plane of the planets: from the small rings of the planets' orbits in the middle, Voyager 1 climbs steeply out of the plane, Voyager 2 dives below it, and the two Pioneers and New Horizons stay close to it, going in different directions"
outer<-planets[planets$name%in%c("Jupiter","Saturn","Uranus","Neptune"),]
p<-plot_ly() %>%
add_trace(data=orbit_lines(outer),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of Jupiter to Neptune",line=list(color=orbit_gray,width=2),
hoverinfo="skip")
# where each spacecraft is today, with its name on the side away from the Sun
ends<-do.call(rbind,lapply(probes$name,function(k) cbind(name=k,paths[[k]][nrow(paths[[k]]),])))
ends$side<-label_sides(ends,180)
for(k in probes$name) {
path<-paths[[k]]
line<-data.frame(x=au(path$x),y=au(path$y),z=au(path$z),
hover=paste0("<b>",k,"</b><br>",date_words(path$date),": ",one(path$r),
" AU from the Sun"))
p<-add_trace(p,data=line,x=~x,y=~y,z=~z,type="scatter3d",mode="lines",name=k,legendgroup=k,
line=list(color=probe_colour[[k]],width=4),customdata=~hover,
hovertemplate="%{customdata}<extra></extra>",inherit=FALSE)
p<-add_trace(p,data=line[nrow(line),],x=~x,y=~y,z=~z,type="scatter3d",mode="markers+text",
text=k,textposition=ends$side[ends$name==k],textfont=list(size=11,color=ink),
legendgroup=k,showlegend=FALSE,marker=list(color=probe_colour[[k]],size=5),
customdata=~hover,hovertemplate="%{customdata}<extra></extra>",inherit=FALSE)
}
p %>%
add_sun(legend=FALSE) %>%
chart(paste("Five spacecraft leaving the solar system, from launch to",when),
"NASA JPL Horizons: the path of each spacecraft, Sun-centred, on the ecliptic.",
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(180)) %>%
finish_3d(c(`Today`=180,`The planets`=35))
```
```{r distance, fig.height = 5}
#| fig-alt: "Line chart of the distance of five spacecraft from the Sun since 1972: each line climbs steadily after its last close pass by a planet; Voyager 1 is the highest, at about 170 AU today, then Voyager 2 and Pioneer 10, Pioneer 11, and New Horizons, the lowest"
p<-plot_ly()
for(k in probes$name)
p<-add_trace(p,data=paths[[k]],x=~date,y=~round(r,1),type="scatter",mode="lines",name=k,
line=list(color=probe_colour[[k]],width=2),
hovertemplate=paste0(k,": %{y} AU<extra></extra>"))
p<-add_trace(p,data=events,x=~date,y=~round(r,1),type="scatter",mode="markers",
name="Left the heliosphere, or last signal",text=~paste(name,what),
marker=list(color=ink,size=8,symbol="circle-open",line=list(width=2)),
hovertemplate="%{text}: %{y} AU<extra></extra>")
# the names at the ends of the lines; two that would be closer than 7% of the height are moved
# apart, each by half of what is missing
end_labels<-probes[order(probes$r),c("name","r")]
gap<-0.07*max(end_labels$r)
for(k in seq_len(nrow(end_labels))[-1]) {
missing<-gap-(end_labels$r[k]-end_labels$r[k-1])
if(missing>0)
end_labels$r[c(k-1,k)]<-end_labels$r[c(k-1,k)]+c(-1,1)*missing/2
}
labels<-lapply(seq_len(nrow(end_labels)),function(k)
list(x=today,y=end_labels$r[k],text=end_labels$name[k],showarrow=FALSE,xanchor="left",
xshift=6,font=list(size=11,color=ink)))
chart(p,"Distance from the Sun","NASA JPL Horizons: the path of each spacecraft.",
"AU from the Sun","",x_axis=list(showgrid=FALSE,range=c(as.Date("1971-01-01"),today+365)),
annotations=labels,hovermode="x unified",legend=legend_top,
margin=list(t=110,b=80,r=100),note_y=-0.12)
```
Each line bends upward where its spacecraft passed close to a planet, whose gravity threw it outward faster: Jupiter for all five, then Saturn for Pioneer 11 and the two Voyagers, and Uranus and Neptune for Voyager 2. Since their last pass, they have been coasting along almost straight lines.
---
## 5. Which comets come back, and which never will?
```{r comet_numbers}
halley<-bodies["Halley's comet",]
# the time that a body takes to go round the Sun, in years: Kepler's third law
period_years<-function(b) {
result<-b$A^1.5
return(result)
}
# the orbit of today puts Halley's next perihelion on a date; its path in Horizons, which takes in
# the pulls of the planets, gives the real one (hour by hour, within 15 days of that date), and the
# days of its last perihelion and of its furthest point (a period and half a period earlier)
halley_path<-function(middle,days,step) {
window<-format(middle+c(-days,days))
path<-horizons_table(download_kept(horizons("DES=1P;CAP","VECTORS",window[1],window[2],step),
paste0("horizons_halley_",paste(window,collapse="_"),
".json")))
result<-data.frame(time=as.POSIXct((path$JDTDB-2440587.5)*86400,origin="1970-01-01",tz="UTC"),
r=sqrt(path$X^2+path$Y^2+path$Z^2))
return(result)
}
orbit_next<-jd_date(halley$Tp)
period_days<-round(period_years(halley)*365.25)
around<-halley_path(orbit_next,15,"1 h")
halley_next<-as.Date(around$time[which.min(around$r)])
around<-halley_path(orbit_next-period_days,60,"1 d")
halley_last<-as.Date(around$time[which.min(around$r)])
around<-halley_path(orbit_next-round(period_days/2),90,"1 d")
halley_aphelion<-as.Date(around$time[which.max(around$r)])
halley_far<-max(around$r)
comet67p<-bodies["Comet 67P",]
hale_bopp<-bodies["Comet Hale–Bopp",]
visitors<-bodies[bodies$kind=="visitor",]
# the speed of a visitor far from the Sun, in km/s: from the size of its open orbit (A, negative),
# the speed of the Earth on its orbit times the square root of 1 over the size
visitors$speed<-29.7847/sqrt(-visitors$A)
visitors$perihelion<-jd_date(visitors$Tp)
atlas<-visitors["3I/ATLAS",]
```
**Comets on closed orbits come back; the three visitors from other stars never will.** Halley's comet is `r one(halley$r)` AU from the Sun. It passed the far end of its orbit on `r date_words(halley_aphelion)`, `r one(halley_far)` AU out, and is on its way back: it will be closest to the Sun on `r date_words(halley_next)`, `r number(as.numeric(halley_next-halley_last)/365.25)` years after its last visit, in `r month_words(halley_last)`. Comet 67P, which ESA's Rosetta spacecraft visited, goes round in `r one(period_years(comet67p))` years, and Hale–Bopp, the bright comet of 1997, now `r one(hale_bopp$r)` AU out, in about `r number(round(period_years(hale_bopp),-2))`. The three visitors from other stars, ʻOumuamua (found in October 2017), Borisov (August 2019) and 3I/ATLAS (July 2025), came on open orbits ([Meech et al. 2017](https://doi.org/10.1038/nature25020); [Guzik et al. 2020](https://doi.org/10.1038/s41550-019-0931-8); [MPC 2025](https://minorplanetcenter.net/mpec/K25/K25N12.html)). Far from the Sun, before its gravity sped them up and after it slowed them down again, they move at `r number(visitors$speed[1])`, `r number(visitors$speed[2])` and `r number(visitors$speed[3])` km/s: too fast for the Sun to hold them. 3I/ATLAS was closest to the Sun on `r date_words(atlas$perihelion)` and is already `r one(atlas$r)` AU away.
```{r comets, fig.height = 7}
#| fig-alt: "3D chart of the orbits of three comets and the paths of three visitors from other stars among the orbits of the planets: the comets' long ellipses in blue, Halley's reaching beyond Neptune, and the visitors' open curves in orange, each passing the Sun once"
comets<-bodies[bodies$kind=="comet",]
reach<-60
p<-plot_ly() %>%
add_trace(data=orbit_lines(planets),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Orbits of the planets",line=list(color=orbit_gray,width=2),hoverinfo="skip") %>%
add_trace(data=orbit_lines(comets,reach),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Comets of the Sun",legendgroup="comets",showlegend=FALSE,
line=list(color=blue,width=3),hoverinfo="skip") %>%
add_trace(data=orbit_lines(visitors,reach),x=~x,y=~y,z=~z,type="scatter3d",mode="lines",
name="Visitors from other stars",legendgroup="visitors",showlegend=FALSE,
line=list(color=orange,width=3),hoverinfo="skip")
p %>%
add_sun(legend=FALSE) %>%
add_bodies(comets,"Comets of the Sun",reach,colour=blue,others=visitors,group="comets") %>%
add_bodies(visitors,"Visitors from other stars",reach,colour=orange,others=comets,
group="visitors") %>%
chart(paste("Comets and visitors from other stars on",when),
paste(horizons_source,"Orbits drawn out to",reach,"AU from the Sun."),
margin=list(t=100,b=80,l=0,r=0),note_y=0,note_shift=-40,legend=legend_top,
scene=space_scene(reach)) %>%
finish_3d(c(`Out to Jupiter`=6,`Out to Neptune`=32,`Out to 60 AU`=reach))
```
The orbits are drawn out to `r reach` AU: Hale–Bopp's goes on to about `r number(hale_bopp$QR*(1+hale_bopp$EC)/(1-hale_bopp$EC))` AU, and the visitors' paths go on for ever. A comet on a closed orbit comes back; a visitor passes once, and leaves.
---
## So, what does it mean?
**The solar system is mostly empty, and it reaches much further than the planets.**
1. **The planets** orbit in nearly one plane, with the main belt of asteroids between Mars and Jupiter and Jupiter's `r number(nrow(trojans))` Trojans in two crowds on its orbit.
2. **Distances**: light from the Sun reaches the Earth in `r one(light_seconds/60)` minutes, Neptune in `r one(bodies["Neptune",]$r*light_seconds/3600)` hours, and Voyager 1 in `r one(voyager1$r*light_seconds/3600)` hours.
3. **Beyond Neptune**, `r number(nrow(kuiper))` known bodies gather where Neptune's rhythm protects them, and thin out beyond 50 AU.
4. **Five spacecraft** are leaving; the two Voyagers have already crossed into interstellar space.
5. **Comets** on closed orbits come back, Halley's in `r format(halley_next,"%Y")`; the three visitors from other stars pass once.
**What this does not show.** The orbits are those of today: the planets pull on each other, and on every small body, so each orbit changes slowly, and a comet's next perihelion can come a few days earlier or later than its orbit of today says: for Halley's comet, the orbit of today says `r date_words(orbit_next)`, its path, which takes in the pulls of the planets, `r date_words(halley_next)`. The Sun, the planets and the dots of the small bodies are not drawn to scale: at the scale of the orbits even the Sun would be smaller than a pixel. The asteroids shown are only the brightest of the main belt and of the Trojans: hundreds of thousands more are known. The objects beyond Neptune are those that JPL's database knows, which is where telescopes have looked, not all that are there. And the solar system goes on far beyond the furthest of them: the Oort cloud, from which long-period comets are thought to come, has never been seen.
---
## Sources
- Gurnett, D.A., Kurth, W.S., Burlaga, L.F. and Ness, N.F. (2013), [In situ observations of interstellar plasma with Voyager 1](https://doi.org/10.1126/science.1241681), *Science* 341, 1489–1492.
- Guzik, P. and others (2020), [Initial characterization of interstellar comet 2I/Borisov](https://doi.org/10.1038/s41550-019-0931-8), *Nature Astronomy* 4, 53–57.
- Malhotra, R. (1995), [The origin of Pluto's orbit: implications for the solar system beyond Neptune](https://doi.org/10.1086/117532), *The Astronomical Journal* 110, 420.
- Meech, K.J. and others (2017), [A brief visit from a red and extremely elongated interstellar asteroid](https://doi.org/10.1038/nature25020), *Nature* 552, 378–381.
- Minor Planet Center (2025), [MPEC 2025-N12: 3I/ATLAS = C/2025 N1 (ATLAS)](https://minorplanetcenter.net/mpec/K25/K25N12.html): discovered on 1 July 2025, on a hyperbolic orbit.
- NASA (2025a), [Pioneer 10](https://science.nasa.gov/mission/pioneer-10/): its last signal, 23 January 2003.
- NASA (2025b), [Pioneer 11](https://science.nasa.gov/mission/pioneer-11/): its last data, 24 November 1995, and the five spacecraft leaving the solar system.
- NASA JPL, [Horizons System](https://ssd.jpl.nasa.gov/horizons/) and its [API](https://ssd-api.jpl.nasa.gov/doc/horizons.html): the orbits and the paths.
- NASA JPL, [Small-Body Database Query](https://ssd.jpl.nasa.gov/tools/sbdb_query.html) and its [API](https://ssd-api.jpl.nasa.gov/doc/sbdb_query.html): the orbits of the asteroids and of the objects beyond Neptune.
- Park, R.S., Folkner, W.M., Williams, J.G. and Boggs, D.H. (2021), [The JPL planetary and lunar ephemerides DE440 and DE441](https://doi.org/10.3847/1538-3881/abd414), *The Astronomical Journal* 161, 105.
- Stone, E.C., Cummings, A.C., Heikkila, B.C. and Lal, N. (2019), [Cosmic ray measurements from Voyager 2 as it crossed into interstellar space](https://doi.org/10.1038/s41550-019-0928-3), *Nature Astronomy* 3, 1013–1018.
- Trujillo, C.A. and Brown, M.E. (2001), [The radial distribution of the Kuiper belt](https://doi.org/10.1086/320917), *The Astrophysical Journal* 554, L95–L98.
*Rendered with R `r getRversion()` · plotly · jsonlite*