我创建了一张随机电荷分布的图片,它现在看起来像这样
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections, decorations,circuits.ee.IEC, calc, decorations.markings, patterns}
\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}
\begin{tikzpicture}
\definecolor{mygray}{gray}{0.8}
\draw [fill=mygray, decoration={random steps, segment length =.5cm, amplitude=.5cm}, decorate , rounded corners=.3cm] (-.5,0) -- (-.25, 3) -- (1,2) -- (1.2,-.5) -- (-.5,0);
\draw[->] (-.5,0) -- (4,0);
\draw[->] (0,-.5) -- (0,4);
\draw[->] (0,0) -- (45:4) node[right]{$\vec r$};
\end{tikzpicture}
\end{document}
我现在的问题是:我怎样才能得到一个随机的 3D 形状?谨致问候
编辑:添加了包以提供一个最小的示例,对此深表歉意。
答案1
这是可以创建“圆形”斑点的东西,你可以通过几个参数来影响它的外观。不知为何,它有时会产生尺寸太大错误,但这并没有破坏它。
代码
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\pgfmathtruncatemacro{\mynumsides}{20}
\pgfmathsetmacro{\myradius}{2}
\pgfmathsetmacro{\myradiusdeviation}{0.9}
\pgfmathsetmacro{\myangledeviation}{10}
\pgfmathsetmacro{\myrandomlength}{0.2}
\pgfmathsetmacro{\myrandomamplitude}{0.1}
\newcommand{\mycolor}{red!80!yellow}
\pgfmathsetmacro{\myopacity}{0.4}
\pgfmathsetmacro{\myroundedcorners}{0.1}
\begin{tikzpicture}
\draw[->] (-.5,0) -- (4,0);
\draw[->] (0,-.5) -- (0,4);
\draw[->] (0,0) -- (45:4) node[right]{$\vec r$};
\pgfmathtruncatemacro{\maxindex}{\mynumsides-1}
\pgfmathsetmacro{\angle}{360/\mynumsides}
\fill[decoration={random steps,segment length=\myrandomlength cm,amplitude=\myrandomamplitude cm},decorate,ball color=\mycolor,opacity=\myopacity,rounded corners=\myroundedcorners cm,shift={(\myradius,\myradius)}] (rand*\myangledeviation:\myradius+rand*\myradiusdeviation)
\foreach \x in {1,...,\maxindex}
{ -- (\x*\angle+rand*\myangledeviation:\myradius+rand*\myradiusdeviation)
}
-- cycle;
\end{tikzpicture}
\end{document}
输出
交替输出
\pgfmathtruncatemacro{\mynumsides}{20}
\pgfmathsetmacro{\myradius}{2}
\pgfmathsetmacro{\myradiusdeviation}{0.1}
\pgfmathsetmacro{\myangledeviation}{2}
\pgfmathsetmacro{\myrandomlength}{0.1}
\pgfmathsetmacro{\myrandomamplitude}{0.05}
\newcommand{\mycolor}{blue}
\pgfmathsetmacro{\myopacity}{0.4}
\pgfmathsetmacro{\myroundedcorners}{0.02}