答案1
通过使用calc
和intersections
库,您可以实现这种事情。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{calc,intersections,patterns}
\begin{document}
\begin{tikzpicture}
\def\g{2} \def\h{3} \def\j{5} \def\c{4}
\def\r{2.3} %ratio for vertical lines
\coordinate (E) at (0,0);
\coordinate (G) at (\g,0);
\coordinate (H) at (\h,0);
\coordinate (J) at (\j,0);
\coordinate (C) at (\g,\c);
\draw[->] (-.5,0) -- (3.5*\g,0) node[right] {$x$};
\draw[->] (0,-.5) -- (0,\r*\c) coordinate (ct) node[above]{$ct$};
\draw[name path=EC,->] (E) -- ($(E)!\r!(C)$) node[above]{$ct'$} node[sloped,above,pos=0.3]{\tiny \textit{trajectory of back end of train}};
\draw[name path=GF] (G) --++ ($(E)!\r!(C)$) node[sloped,below,pos=0.1]{\tiny \textit{trajectory}} node[sloped,below,pos=0.4]{\tiny \textit{of front end of train}};
\coordinate (aux1) at (ct-|H);
\draw[name path=HF] (H) -- (aux1) node[pos=0.9,rotate=90,above,text width=2cm,align=center]{\baselineskip=0.2pt \tiny \textit{trajectory of\\tunnel entrance}\par};
\coordinate (aux2) at (ct-|J);
\draw[name path=JD] (J) -- (aux2) node[pos=0.2,yshift=-15pt,rotate=90,below,text width=2cm,align=center]{\baselineskip=0.2pt \tiny \textit{trajectory of\\tunnel exit}\par};
\path [name intersections={of=GF and HF,by=F}];
\path [name intersections={of=EC and HF,by=A}];
\path [name intersections={of=GF and JD,by=D}];
\draw[dashed] (C) -- (D) -- (A) --++ ($(D)-(C)$) coordinate (B);
\draw[->] (E) -- ($(E)!2.3!(F)$) node[right]{$x'$};
\foreach \p in {A,B,C,D,E,F,G,H,J} \fill (\p) circle(1pt);
\node[below left] at (E) {E};
\node[below] at (G) {G};
\foreach \p in {A,B,C,D,F,H,J} \node[below right] at (\p) {\p};
% Train and tunnel
\draw (-.5,-2) -- (3.5*\g,-2);
\fill[pattern=north east lines] (-.5,-2) rectangle (3.5*\g,-2.1);
\draw (0,-1.8) --++ (\g,0) --++ (.2,.5) --++ (-\g,0) --cycle;
\path (0,-1.8) --++ (\g,.5) node[midway](train){\textit{train}};
\draw (0.2*\g,-1.9) circle (.1) (0.8*\g,-1.9) circle (.1);
\draw[dashed] (H) --++ (0,-1) (J) --++ (0,-1);
\draw (\h,-2) rectangle (\j,-1) node[midway](tunnel){\textit{tunnel}};
\path (train) -- (tunnel) node[pos=0.55]{$\Rightarrow$};
\end{tikzpicture}
\end{document}