Skip to content

Instantly share code, notes, and snippets.

@mcnees
Created October 26, 2017 21:22
Show Gist options
  • Save mcnees/0f27ab3b1a87df75620870e962094cd2 to your computer and use it in GitHub Desktop.
Save mcnees/0f27ab3b1a87df75620870e962094cd2 to your computer and use it in GitHub Desktop.
Draw a spacetime diagram showing an accelerating rocket with constant proper length.
\documentclass[border=10pt]{standalone}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{mathrsfs}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{decorations.markings}
\usepackage{tikz-3dplot}
\usepackage{pgfplots}
\usepackage{colortbl}
\usepackage{xcolor}
%--------------------------------------------------------------
% Define a few colors
%--------------------------------------------------------------
\definecolor{plum}{rgb}{0.36078, 0.20784, 0.4}
\definecolor{chameleon}{rgb}{0.30588, 0.60392, 0.023529}
\definecolor{cornflower}{rgb}{0.12549, 0.29020, 0.52941}
\definecolor{scarlet}{rgb}{0.8, 0, 0}
\definecolor{brick}{rgb}{0.64314, 0, 0}
\definecolor{sunrise}{rgb}{0.80784, 0.36078, 0}
\definecolor{lightblue}{rgb}{0.15,0.35,0.75}
\begin{document}
\begin{tikzpicture}[scale=1,domain=-1:16]
\tikzstyle{axisarrow} = [-{Latex[inset=0pt,length=7pt]}]
%--------------------------------------------------------------
% We place the origin so each point on the rocket is always
% some constant proper distance from the event (0,0);
%--------------------------------------------------------------
%--------------------------------------------------------------
% Set some constants we need.
%--------------------------------------------------------------
% Use units where c=1
\pgfmathsetmacro\clight{1};
% Set the acceleration of the back of the rocket in units of ls/s^2.
\pgfmathsetmacro\alphaB{0.25};
% Set the (constant) proper length of the rocket, from back to front
\pgfmathsetmacro\Length{8};
%--------------------------------------------------------------
% Compute some constants we need.
%--------------------------------------------------------------
% Compute the acceleration at the front of the rocket, based on
% the acceleration at the back \alphaB and the constant proper
% length L.
\pgfmathsetmacro\alphaF{\alphaB*\clight^2/(\clight^2 + \alphaB*\Length)};
% Compute the acceleration at the midpoint of the rocket, based on
% the acceleration at the back \alphaB and the constant proper
% length L.
\pgfmathsetmacro\alphaM{\alphaB*\clight^2/(\clight^2 + \alphaB*\Length/2)};
%--------------------------------------------------------------
% How much proper time to plot for each part of the rocket.
%--------------------------------------------------------------
% Plot for this amount of proper time according to an observer
% in the back of the rocket.
\pgfmathsetmacro\tBmax{8};
% The amount of proper time experienced by someone in the front
% of the rocket, simultaneous with the back of the rocket at
% \tBax.
\pgfmathsetmacro\tFmax{\tBmax*\alphaB/\alphaF};
% The amount of proper time experienced by someone at the midpoint
% of the rocket, simultaneous with the back of the rocket at
% \tBax.
\pgfmathsetmacro\tMmax{\tBmax*\alphaB/\alphaM};
%--------------------------------------------------------------
% Draw things
%--------------------------------------------------------------
% Draw the background grid.
\draw [cornflower!30,step=0.2,thin] (-1,-2) grid (16,12);
\draw [cornflower!60,step=1.0,thin] (-1,-2) grid (16,12);
% Clip everything that falls outside the grid
\clip(-1,-2) rectangle (16,12);
% Draw Axes
\draw[thick,axisarrow] (0,-2) -- (0,12);
\node[inner sep=0pt] at (0.5,11.7) {$t (s)$};
\draw[thick,axisarrow] (-1,0) -- (16,0);
\node[inner sep=0pt] at (15.5,-0.4) {$x (\ell s)$};
% Light ray from the event (0,0) traveling in the positive
% x-direction. The worldlines of all points of the rocket
% asymptote to this line.
\draw[chameleon,thick] (0,0) -- (12,12);
% Draw lines of simultaneity through N events happening every 1
% second, according to a clock at the back of the rocket.
\foreach \tB in {1,2,...,4}
{
\draw[orange, dashed, thick] (0,0) -- (16,{16*tanh(\alphaB*\tB/\clight)});
}
%--------------------------------------------------------------
% Back of the rocket
%--------------------------------------------------------------
% Plot the wordline of the back of the rocket, as a function of
% its proper time.
\draw[domain=0:\tBmax,smooth,variable=\tB,scarlet,thick] plot ({(\clight^2/\alphaB)*cosh(\tB*\alphaB/\clight)},{(\clight/\alphaB)*sinh(\tB*\alphaB/\clight)});
% Add a node at events spaced 1 second of proper time apart
% along the back of the rocket's worldline.
\foreach \tB in {0,1,2,...,\tBmax}
{
\node[circle,draw=scarlet!70,fill=scarlet!20,inner sep=2pt] at ({(\clight^2/\alphaB)*cosh(\alphaB*\tB/\clight)},{(\clight/\alphaB)*sinh(\alphaB*\tB/\clight)}) {};
}
%--------------------------------------------------------------
% Middle of the rocket
%--------------------------------------------------------------
% Plot the wordline of the midpoint of the rocket, as a function of
% its proper time.
\draw[domain=0:\tMmax,smooth,variable=\tM,cornflower,thick] plot ({(\clight^2/\alphaM)*cosh(\tM*\alphaM/\clight)},{(\clight/\alphaM)*sinh(\tM*\alphaM/\clight)});
% Add a node at events spaced 1 second of proper time apart
% along the midpoint of the rocket's worldline.
\foreach \tM in {0,1,2,...,\tMmax}
{
\node[circle,draw=cornflower!70,fill=cornflower!20,inner sep=2pt] at ({(\clight^2/\alphaM)*cosh(\alphaM*\tM/\clight)},{(\clight/\alphaM)*sinh(\alphaM*\tM/\clight)}) {};
}
%--------------------------------------------------------------
% Front of the rocket
%--------------------------------------------------------------
% Plot the wordline of the front of the rocket, as a function of
% its proper time.
\draw[domain=0:\tFmax,smooth,variable=\tF,plum,thick] plot ({(\clight^2/\alphaF)*cosh(\tF*\alphaF/\clight)},{(\clight/\alphaF)*sinh(\tF*\alphaF/\clight)});
% Add a node at events spaced 1 second of proper time apart
% along the front of the rocket's worldline.
\foreach \tF in {0,1,2,...,\tFmax}
{
\node[circle,draw=plum!70,fill=plum!20,inner sep=2pt] at ({(\clight^2/\alphaF)*cosh(\alphaF*\tF/\clight)},{(\clight/\alphaF)*sinh(\alphaF*\tF/\clight)}) {};
}
%--------------------------------------------------------------
% Add some labels for each worldline.
%--------------------------------------------------------------
\node [] at ({\clight^2/\alphaB},-0.5) {$x_{B}$};
\node [] at ({\clight^2/\alphaM},-0.5) {$x_{M}$};
\node [] at ({\clight^2/\alphaF},-0.5) {$x_{F}$};
\end{tikzpicture}
\end{document}
@mcnees
Copy link
Author

mcnees commented Oct 26, 2017

screen shot 2017-10-26 at 4 23 20 pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment