我想画圆来创造 3D 效果。我不知道如何旋转图像。代码如下:
`\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fadings}
\begin{document}
\newcommand{\distin}{0.3}
\newcommand{\opacity}{0.3}
\newcommand{\xShift}{1.1}
\newcommand{\yShift}{1.1}
\begin{figure}[htb!]
\centering
\begin{tikzpicture}
\foreach \i in {0,...,10}{
\foreach \j in {0,...,7}{
\draw [fill=black, opacity=\opacity, draw=black]
(\distin*\i,\distin*\j) circle (1mm);
}
}
\end{tikzpicture}
\end{figure}
\end{document}
目前代码生成以下图像:
但我想要这样的东西:
我怎样才能做到这一点?'
答案1
像这样 ?
\documentclass[a4paper]{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathreplacing}
\usetikzlibrary{fadings}
\begin{document}
\newcommand{\distin}{0.2}
\newcommand{\opacity}{1}
\newcommand{\xShift}{1.1}
\newcommand{\yShift}{1.1}
\begin{figure}[htb!]
\centering
\begin{tikzpicture}[scale=3]
\foreach \i [count=\c]in {10,...,0}{
\foreach \j [evaluate =\j as \decrement using \j-\c*.5] in {7,...,0}{
\draw [fill=blue!50,draw=blue, opacity=\opacity, draw=black]
(\distin*.4*\i,\distin*\decrement) circle (1mm);
}
}
\end{tikzpicture}
\end{figure}
\end{document}
答案2
tikz-3dplot
允许您以 3D 形式绘制事物并调整视图。您可以通过调整来更改视图\tdplotsetmaincoords{70}{20}
。
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}
\begin{document}
\newcommand{\distin}{0.3}
\newcommand{\opacity}{0.3}
\newcommand{\xShift}{1.1}
\newcommand{\yShift}{1.1}
\begin{figure}[htb!]
\centering
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords]
\foreach \i in {10,9,...,0}{
\begin{scope}[canvas is xz plane at y=\distin*\i]
\foreach \j in {0,...,7}{
\draw [fill=black, opacity=\opacity, draw=black]
(0,\distin*\j) circle (1mm);
}
\end{scope}
}
\end{tikzpicture}
\end{figure}
\end{document}
如果想要有未投影在相应平面上的圆,请使用dplot_screen_coords
而不是相应的平面。
\documentclass[a4paper]{article}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\begin{document}
\newcommand{\distin}{0.3}
\newcommand{\opacity}{0.3}
\begin{figure}[htb!]
\centering
\tdplotsetmaincoords{70}{20}
\begin{tikzpicture}[tdplot_main_coords,scale=3]
\foreach \i in {10,9,...,0}{
\foreach \j in {0,...,7}{
\draw [fill=black, opacity=\opacity, draw=black]
(0,\distin*\i,\distin*\j) [tdplot_screen_coords] circle (1mm);
}
}
\end{tikzpicture}
\end{figure}
\end{document}
下面的动画稍微解释了一下视角的含义。
\documentclass[tikz,border=3.14mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d}
\begin{document}
\newcommand{\distin}{0.3}
\newcommand{\opacity}{0.3}
\foreach \X in {-70,-65,...,70}
{\tdplotsetmaincoords{70+15*sin(\X)}{\X}
\begin{tikzpicture}
\path[use as bounding box] (-4,-0.5) rectangle (4,4);
\begin{scope}[tdplot_main_coords]
\foreach \i in {10,9,...,0}{
\begin{scope}[canvas is xz plane at y=\distin*\i]
\foreach \j in {0,...,7}{
\draw [fill=black, opacity=\opacity, draw=black]
(0,\distin*\j) circle (1mm);
}
\end{scope}
}
\end{scope}
\end{tikzpicture}}
\end{document}