我想在右侧绘制一个矩形和圆弧的组合,以产生这样的效果:
我所能产生的只是这个 MWE:
\documentclass[12pt]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\begin{tikzpicture}[scale=1,>=latex,x=1cm,y=0.8cm]
\draw[-, thin] (0, 0) -- (4.6, 0) arc[start angle=0, end
angle=60, radius=6.6] -- (1.2,5.7) -- (0, 5.7) -- cycle;
\draw[<->] (-0.2,0) -- (-0.2,5.7) node[left, midway] {\footnotesize $40$};
\draw[<->] (0,-0.5) -- (2,-0.5) node[below, midway] {\footnotesize $8$};
\end{tikzpicture}
\end{document}
我更喜欢使用/draw
Tikz。
答案1
您可以plot
使用选项smooth
来获得具有正确比例长度的平滑曲线。您还可以调整tension
曲线的。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\colorlet{fillcolor}{cyan!30}
\tikzset{bararrow/.style={{Bar[width=4mm]<}-{>Bar[width=4mm]}}}
\begin{document}
\begin{tikzpicture}[xscale=.25, >=latex, font=\small]
\draw[thick, smooth, cyan, fill=fillcolor](0,0)-- plot coordinates {(8,0)(10,1)(10.5,2)(10.5,3)(10,4)(9,5)(8,6)(6.5,7)(5,8)}-|cycle;
\foreach \x[count=\y] in {10,10.5,10.5,10,9,8,6.5}
\draw[<->](0,\y)--node[fill=fillcolor]{\x}(\x,\y);
\draw[bararrow, yshift=-3mm](0,0)--node[fill=white]{8}(8,0);
\draw[bararrow, yshift=3mm](0,8)--node[fill=white]{5}(5,8);
\draw[bararrow, xshift=-12mm](0,0)--node[fill=white]{40}(0,8);
\end{tikzpicture}
\end{document}
答案2
代码
\documentclass[12pt, tikz]{standalone}
\usetikzlibrary{arrows.meta, calc, intersections, quotes}
\tikzset{
dim line distance/.initial=.2cm,
dim line style/.style={<->},
dim line delim/.style={-, shorten <=2\pgflinewidth, shorten >=-7\pgflinewidth},
dim line text/.style={midway, auto=left, font=\footnotesize},
pics/dim line/.style args={#1--#2}{code={
\draw[dim line style]
($(#1)!\pgfkeysvalueof{/tikz/dim line distance}!90:(#2)$) coordinate (@1)
to node[dim line text,style/.expand once=\tikzpictextoptions]{$\tikzpictext$}
($(#2)!\pgfkeysvalueof{/tikz/dim line distance}!-90:(#1)$)coordinate (@2);
\draw[dim line delim] (#1) to (@1);
\draw[dim line delim] (#2) to (@2);}}}
\begin{document}
\begin{tikzpicture}[> = Latex, x = .2cm, y = 0.1cm]
\draw[draw=blue,fill=blue!50, name path=area]
(0, 0) coordinate (bl)
-- (right:8) coordinate (br)
to[out=70, in=-60] +(-3, 40) coordinate (tr)
-| coordinate (tl) cycle;
\pic ["40"] {dim line=bl--tl}
pic [ "8"] {dim line=br--bl}
pic [ "5"] {dim line=tl--tr};
\foreach \level in {1, ..., 7} {
\path[overlay, help lines, name path=hor\level]
(10pt, \level/8*40) -- +(right:10);
\draw[name intersections={of=area and hor\level, by=is-\level},
<->, nodes={fill=blue!50, node font=\footnotesize},
/pgf/number format/.cd, fixed zerofill, precision=1]
let \p 0 = ($(is-\level) - (0,0)$),
\p B = ($(br) - (bl) $), % redundant
\n 0 = {scalar(\x0/\x B*8)} in % scalar removes units
(0, \level/8*40) -- node {$\pgfmathprintnumber{\n0}$} (is-\level);
}
\end{tikzpicture}
\end{document}