![如何用 tikz 畫圓: \draw[black, line width = 0.50mm]plot[smooth,domain=0:2] (\x, {sqrt(1-(x-1)^2)});](https://rvso.com/image/410379/%E5%A6%82%E4%BD%95%E7%94%A8%20tikz%20%E7%95%AB%E5%9C%93%EF%BC%9A%20%5Cdraw%5Bblack%2C%20line%20width%20%3D%200.50mm%5Dplot%5Bsmooth%2Cdomain%3D0%3A2%5D%20(%5Cx%2C%20%7Bsqrt(1-(x-1)%5E2)%7D)%3B.png)
如何在 tikz 中使用以下程式碼繪製一個圓圈:
\documentclass{article}
\usepackage{tikz,pgfplots}
%\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{intersections}
\pgfdeclarelayer{bg} % declare background
\pgfsetlayers{bg,main} % order of layers (main = standard layer)
\pgfplotsset{compat=1.13}
\usepackage{amsmath}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\draw[black, line width = 0.50mm] plot[smooth,domain=0:2] (\x, {sqrt(1-(x-1)^2)});
\end{tikzpicture}
\end{document}
答案1
呃,那是半個圓。你的目標到底是什麼?
pgfplots
繪製函數比在基本中容易得多tikz
\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\begin{tikzpicture}
\begin{axis}[
axis equal
]
\addplot [smooth,domain=0:2,samples=101] {sqrt(1-(\x-1)^2)};
\addplot [smooth,domain=0:2,samples=101] {-sqrt(1-(\x-1)^2)};
\end{axis}
\end{tikzpicture}
\end{document}
答案2
您希望圓可能是光滑的,因此可能想要一次繪製圓。這可以透過使用從 0 運行到 2 然後再返回的函數來實現,
(\x<2 ? \x : 4-\x)
然後你需要用 來決定你是在上分支還是下分支sign(2-\x)
,這樣plot指令就變成了
\draw[black, line width = 0.50mm]
plot[smooth cycle,domain=0:4,samples=101]
({(\x<2 ? \x : 4-\x)}, {sign(2-\x)*sqrt(1-((\x<2 ? \x : 4-\x)-1)^2)});
這比標準的圓形路徑要付出更多的努力。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[nodes={text width=2.5cm,align=center}]
\begin{scope}[local bounding box=A]
\draw[black, line width = 0.50mm]
plot[smooth cycle,domain=0:4,samples=101]
({(\x<2 ? \x : 4-\x)}, {sign(2-\x)*sqrt(1-((\x<2 ? \x : 4-\x)-1)^2)});
\end{scope}
\path (A.south) node[below] {engineering a function};
%
\begin{scope}[xshift=3cm,local bounding box=B,
declare function={xcheat(\x)=(\x<2 ? \x : 4-\x);}]
\draw[black, line width = 0.50mm]
plot[smooth cycle,domain=0:4,samples=101]
({xcheat(\x)}, {sign(2-\x)*sqrt(1-(xcheat(\x)-1)^2)});
\end{scope}
\path (B.south) node[below] {engineering and declaring a function};
%
\begin{scope}[xshift=6cm,local bounding box=C]
\draw[black, line width = 0.50mm] (1,0) circle[radius=1cm];
\end{scope}
\path (C.south) node[below] {use normal circle};
\end{tikzpicture}
\end{document}