我正在尝试在 tikz 中创建以下图片:
我设法绘制了它,但上部没有倾斜:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz, pgfplots}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\tikzset{>={Classical TikZ Rightarrow[width=2mm,length=2mm]}}
\newcommand{\newCommandName}{text to insert}
\newcommand\li{10}
\newcommand\ra{1.5}
\newcommand\net{3.5}
\newcommand\ortl{5}
\newcommand\midarr{1}
\begin{document}
\begin{figure}[h!]\centering
\begin{tikzpicture}[scale=0.6]
% The base line:
\draw (0,0)--(\li,0);
%The circles:
\draw (\ra, \ra) circle (\ra);
\draw (\li - \ra, \ra) circle (\ra);
%Circle radie:
\draw[<->] (\ra, \ra) -- node[above] {$\frac{k}{2}$} (0, \ra);
\draw[<->] (\li - \ra, \ra) -- node[above] {$\frac{k}{2}$} (\li, \ra);
%Inner Orthogonal lines:
\draw[dashed] (\ra,0)--(\ra,\net);
\draw[dashed] (\li - \ra,0)--(\li-\ra,\net);
% l-k line
\draw[<->] (\ra,\net) -- node[above] {$l-k$} (\li-\ra,\net);
%Outer Orthogonal lines:
\draw[dashed] (0,0)--(0,\ortl);
\draw[dashed] (\li,0)--(\li,\ortl);
% l line
\draw[<->] (0,\ortl) -- node[above] {$l$} (\li,\ortl);
% Arrow in the middle:
\draw[-{Latex[length=2.5mm]}, line width=1] (\li *0.5-\midarr,\ra)--(\li*0.5 + \midarr,\ra);
% Block under the graph:
\draw[draw=black] (\ra-0.5,0) rectangle ++(0.5,-1);
\end{tikzpicture}
\end{figure}
\end{document}
有没有办法旋转图片的上部,或者我是否必须再次绘制它,这次从一开始就倾斜?
答案1
大部分代码都包含在其中,scope
然后旋转到所需的角度。在范围之后绘制矩形(图中为红色)和水平基线:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz, pgfplots}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows.meta}
\tikzset{>={Classical TikZ Rightarrow[width=2mm,length=2mm]}}
\newcommand{\newCommandName}{text to insert}
\newcommand\li{10}
\newcommand\ra{1.5}
\newcommand\net{3.5}
\newcommand\ortl{5}
\newcommand\midarr{1}
\begin{document}
\begin{figure}[h!]\centering
\begin{tikzpicture}[scale=0.6]
\begin{scope}[rotate=-5]
% The base line:
\draw (0,0) -- ++ (0.5,0) coordinate (aux1) -- (\li,0);
%The circles:
\draw (\ra, \ra) circle (\ra);
\draw (\li - \ra, \ra) circle (\ra);
%Circle radie:
\draw[<->] (\ra, \ra) -- node[above] {$\frac{k}{2}$} (0, \ra);
\draw[<->] (\li - \ra, \ra) -- node[above] {$\frac{k}{2}$} (\li, \ra);
%Inner Orthogonal lines:
\draw[dashed] (\ra,0)--(\ra,\net);
\draw[dashed] (\li - \ra,0)--(\li-\ra,\net);
% l-k line
\draw[<->] (\ra,\net) -- node[above] {$l-k$} (\li-\ra,\net);
%Outer Orthogonal lines:
\draw[dashed] (0,0)--(0,\ortl);
\draw[dashed] (\li,0)--(\li,\ortl);
% l line
\draw[<->] (0,\ortl) -- node[above] {$l$} (\li,\ortl);
% Arrow in the middle:
\draw[-{Latex[length=2.5mm]}, line width=1] (\li *0.5-\midarr,\ra)--(\li*0.5 + \midarr,\ra);
\end{scope}
% Block under the graph:
\draw (-5:\li) -- ++ (-\li,0) coordinate (aux2);
\draw[draw=red] (aux1) rectangle (aux2);
\end{tikzpicture}
\end{figure}
\end{document}