Skip to content

Instantly share code, notes, and snippets.

@jamesamiller
Created March 19, 2021 20:48
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jamesamiller/7e1047ba6488909e390e95c0fcb3f39b to your computer and use it in GitHub Desktop.
A battle between Klingons and the Federation. Special relativity spacetime diagram.
\documentclass[crop=true, border=10pt]{standalone}
\usepackage{comment}
\begin{comment}
:Title: Klingons and Enterprise III
:Author: J A Miller, UAH Physics & Astronomy, millerja@uah.edu
2020/07/07
Spacetime diagram of an Enterprise - Klingon battle. The third of a few variations.
GitHub Gist:
https://gist.github.com/jamesamiller/7e1047ba6488909e390e95c0fcb3f39b
References:
https://www1.phys.vt.edu/~takeuchi/relativity/practice/problem08.html
Basic plot style from
https://gist.github.com/mcnees/45b9f53ad371c38ba6f3759df5880fb1
---------------------------------------------------------------------
Problem to accompany figure
---------------------------------------------------------------------
See the above Takeuchi reference.
---------------------------------------------------------------------
Figure caption
---------------------------------------------------------------------
\caption{
Spacetime diagram of an Enterprise - Klingon battle. \textit{Blue arrows:} The unprimed frame of the stars and the Enterprise. \textit{Red arrows:} The primed frame of the Klingon ship, and the worldline of the ship front (the back of the ship is the $t^\prime$ axis). \textit{Purple arrows:} The worldlines of the Enterprise front and back. \textit{Dashed lines:} lines of simultaneity. For Exercise \ref{exer-klingonII}.
}
---------------------------------------------------------------------
Solution to problem
---------------------------------------------------------------------
See reference.
\end{comment}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,calc,intersections}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usepackage{xcolor}
\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}
% ----------------------- parameter specifications ------------------------
% the speed of the primed frame
\newcommand*\vp{0.6}
% proper length of both ships
\newcommand*\length{4.0}
% location of front of Enterprise
\newcommand*\xfe{4}
% graph boundaries
\newcommand*{\xa}{-1} % lower left corner
\newcommand*{\ya}{-1}
\newcommand*{\xb}{12} % upper right corner
\newcommand*{\yb}{14}
% x and y scales
\newcommand*{\xscale}{1cm}
\newcommand*{\yscale}{1cm}
% some calculations now ...
% back of enterprise
\pgfmathsetmacro{\xbe}{\xfe+\length}
% gamma and eta factors for the primed frame
\pgfmathsetmacro{\gamp}{1/sqrt(1-\vp*\vp)}
\pgfmathsetmacro{\etap}{\vp*\gamp}
% front of Klingon at t=0
\pgfmathsetmacro{\xfk}{\length/\gamp}
% ------------------------ other functions ------------------------------
% Extract coordinate
% https://tex.stackexchange.com/questions/477075/coordinates-unit-in-pt-although-default-is-cm-in-tikz
% Example:
% \ExtractCoordinate{x};
% \node[above] at (\XCoor,\YCoor) {node};
% Note: the coordinates are extracted with dimensions of points
\newdimen\XCoor
\newdimen\YCoor
\newcommand*{\ExtractCoordinate}[1]{\path (#1); \pgfgetlastxy{\XCoor}{\YCoor};}
% ------------------------ begin figure ------------------------------
\begin{document}
\begin{tikzpicture}[
scale=1,
domain=\xa:\xb,
x=\xscale,y=\yscale,
axisarrow/.style=-{Latex[inset=0pt,length=10pt]},
minor gridlines/.style={cornflower!30,step=0.2,thin},
major gridlines/.style={cornflower!60,step=1.0,thin},
axes/.style={cornflower,thick,axisarrow}, % unprimed axes
primed axes/.style={scarlet,thick,axisarrow}, % primed axes
primed major gridlines/.style={scarlet!60,thin},
double primed axes/.style={chameleon,thick,axisarrow}, % double primed axes
double primed major gridlines/.style={chameleon!60,thin},
LOS/.style={cornflower,thick,dashed}, % line of simultaneity in unprimed frame
LOS primed/.style={scarlet,thick,dashed}, % line of simultaneity in primed frame
LOS double primed/.style={chameleon,thick,dashed}, % line of simultaneity in primed frame
light ray/.style={chameleon,thick,axisarrow},
textnode/.style={inner sep=0pt}, % for a text only node
dot/.style={circle,draw=scarlet!70,fill=scarlet!20,inner sep=1.5pt}
]
% In case we need to increase the font size because of a large diagram
\tikzset{every node/.style={scale=1.2}};
% some coordinates
\coordinate (O) at (0,0);
% Draw the grid for the unprimed frame
%\draw [minor gridlines] (\xa,\ya) grid (\xb,\yb);
\draw [major gridlines] (\xa,\ya) grid (\xb,\yb);
% Draw unprimed axes
\draw[axes,name path=taxis] (0,\ya) -- (0,\yb);
\node[textnode] at (0.25,\yb-0.5) {$t$};
\draw[axes,name path=xaxis] (\xa,0) -- (\xb,0);
\node[textnode] at (\xb-0.5,-0.25) {$x$};
% Draw the primed axes
\draw[primed axes,name path=tpaxis] (O) -- (\vp*\yb,\yb) node (tp) {}; % also the Klingon back
\node[textnode] at ($(tp)+(0,-0.5)$) {$t^\prime$};
\draw[primed axes,name path=xpaxis] (O) -- (\xb,\vp*\xb) node (xp) {};
\node[textnode] at ($(xp)+(-0.2,-0.4)$) {$x^\prime$};
% Worldlines for Enterprise
\draw[thick,plum,axisarrow,name path=efront] (\xfe,0) -- (\xfe,\yb);
\draw[thick,plum,axisarrow,name path=eback] (\xbe,0) -- (\xbe,\yb);
% Draw the worldlines of the front of the Klingons
\draw[primed axes,name path=kfront] (\xfk,0) -- (\vp*\yb+\xfk,\yb) node(tpf) {};
% Now we create a bunch of points...
% Point I, H, G, J
\coordinate (I) at (\xbe,{(\xbe-\xfk)/\vp});
\coordinate (G) at (\xfe,{(\xbe-\xfk)/\vp});
\draw[LOS,name path={IG}] (I) -- (G);
\path [name intersections={of=IG and tpaxis,by=H}];
\path [name intersections={of=efront and tpaxis,by=J}];
% Light ray from I
\draw[light ray,name path={light}] (I) -- ($(I)+(-6,6)$);
% Point A
\path [name intersections={of=light and efront,by=A}];
% Points D, C, E
\path [name intersections={of=light and tpaxis,by=D}];
\path let \p1=(D) in coordinate (C) at ( \xfe, \y1 );
\path let \p1=(D) in coordinate (E) at ( \xbe, \y1 );
\draw[LOS,name path={EC}] (E) -- (C);
% LOS through D
\ExtractCoordinate{D}
\pgfmathsetmacro{\tpD}{\gamp*(\YCoor - \vp*\XCoor)/(1cm/1pt)};
\draw[LOS primed, domain=0:\xbe, variable=\x, name path={BF}] plot(\x,\vp*\x+\tpD/\gamp);
\path [name intersections={of=BF and efront,by=F}];
\path [name intersections={of=BF and eback,by=B}];
% LOS through I
\ExtractCoordinate{I}
\pgfmathsetmacro{\tpI}{\gamp*(\YCoor - \vp*\XCoor)/(1cm/1pt)};
\draw[LOS primed, domain=0:\xbe, variable=\x, name path={IL}] plot(\x,\vp*\x+\tpI/\gamp);
\path [name intersections={of=IL and tpaxis,by=L}];
\path [name intersections={of=IL and efront,by=K}];
% LOS through L
\path let \p1=(L) in coordinate (P) at ( {\xbe}, {\y1} );
\draw[LOS, name path={PL}] (L) -- (P);
\path [name intersections={of=PL and efront,by=M}];
\path [name intersections={of=PL and kfront,by=N}];
\path [name intersections={of=efront and kfront,by=Q}];
% label the points
\node[dot,label={right:I}] at (I) {};
\node[dot,label={left:G}] at (G) {};
\node[dot,label={below right:H}] at (H) {};
\node[dot,label={left:J}] at (J) {};
\node[dot,label={left:A}] at (A) {};
\node[dot,label={below:D}] at (D) {};
\node[dot,label={left:C}] at (C) {};
\node[dot,label={right:E}] at (E) {};
\node[dot,label={left:F}] at (F) {};
\node[dot,label={right:B}] at (B) {};
\node[dot,label={left:L}] at (L) {};
\node[dot,label={right:K}] at (K) {};
\node[dot,label={above right:P}] at (P) {};
\node[dot,label={below right:M}] at (M) {};
\node[dot,label={below right:N}] at (N) {};
\node[dot,label={right:Q}] at (Q) {};
% shading, if desired
\draw[fill=plum!40,opacity=0.2] (\xfe,0) -- (\xbe,0) -- (\xbe,\yb) -- (\xfe,\yb) -- (\xfe,0);
\draw[fill=scarlet!40,opacity=0.2] (0,0) -- (\xfk,0) -- (\vp*\yb+\xfk,\yb) -- (\vp*\yb,\yb) -- (0,0);
% couple of labels, manually set
\node[inner sep=0pt,text width=2cm,align=center] at (8,-0.5) {Enterprise back};
\node[inner sep=0pt,text width=2cm,align=center] at (4.9,-0.5) {Enterprise front};
\node[inner sep=0pt,text width=2cm,align=center] at (2.7,-0.5) {Klingon front};
\node[inner sep=0pt,text width=2cm,align=center] at (0.7,-0.5) {Klingon back};
\end{tikzpicture}
\end{document}
@jamesamiller
Copy link
Author

fig-klingonIII

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