
で定義された曲線を\draw
パスに沿ったランダムな変化と組み合わせたいと思います。
これまでのところ、tex.SEで次のような興味深い議論を見つけました。tikz/pgf でブラウン運動を描く方法、Beamer フレームで tikz を使用して「rand」関数によって生成されたブラウン運動の軌道を修正する方法、そして(Kpymに感謝します、私はこれを監督しました)手描きの線をシミュレートするしかし、期待通りには動作しません。
tikz-decorations を使用すると効果が期待できますが、比較的直線的な曲線の場合のみです。
次の MWE はこの結果を示します。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\begin{document}
\begin{tikzpicture}[x=5mm,y=5mm,decoration={random steps,segment length=3mm,amplitude=1mm}]
\draw[thick,green] (0, 1) -- (14.5, 1);
\draw[thick,red,decorate,rounded corners] (0,-0.5) -- (14.5,-0.5);
\draw[thick,blue,decorate,rounded corners] (0, 0.5) -- (1,0.5) -- (1.5,-4) -- (2,-3.5) -- (3.5,-2) -- (14.5, 0);
\end{tikzpicture}
\end{document}
3 番目 (青) の\draw
コマンドでは、私が取得しようとしている結果は生成されません。赤い線でも、x 方向の約 75% のところで「ヒックアップ」が発生します。
tikz マニュアルによると、その理由は次のとおりです。各ステップの終了時には、区間[−d,d]から均一に抽出された2つの値によってx方向とy方向の両方で摂動が加えられます。ここで、dは振幅の値です。これは、y 値のみを変更することで目的の出力が得られる曲線オプションと競合します。プロットは時間における値の変化を記述するため、負の x 方向に向かない可能性があります。
装飾を x 値のみ操作し、y 値は操作しないように制限する方法はありますかrandom steps
? 代替案としては、ブラウン運動のように離散的な間隔でランダムな歪みによって曲線を重ねるという方法があります...
結果が何らかの形で安定することを期待して(ランダムシフトの考えと矛盾しますが - 笑)、シードを制御する必要は実際にはありません...
答え1
これは、y 方向にランダム ステップを設定できますか? という質問に対する回答です。答えは「はい」です。必要なのは、ランダム ステップの定義をコピーし、シフトをx
0 に設定することだけです。
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}
\pgfdeclaredecoration{random y steps}{start}
{%
\state{start}[width=+0pt,next state=step,persistent precomputation=\pgfdecoratepathhascornerstrue]{}%
\state{step}[auto end on length=1.5\pgfdecorationsegmentlength,
auto corner on length=1.5\pgfdecorationsegmentlength,
width=+\pgfdecorationsegmentlength]
{
\pgfpathlineto{
\pgfpointadd
{\pgfpoint{\pgfdecorationsegmentlength}{0pt}}
{\pgfpoint{0pt}{rand*\pgfdecorationsegmentamplitude}}
}
}%
\state{final}
{}%
}%
\begin{document}
\begin{tikzpicture}[x=5mm,y=5mm,decoration={random y steps,segment length=3mm,amplitude=1mm}]
\draw[thick,green] (0, 1) -- (14.5, 1);
\draw[thick,red,decorate,rounded corners] (0,-0.5) -- (14.5,-0.5);
\draw[thick,blue,decorate,rounded corners] (0, 0.5) -- (1,0.5) -- (1.5,-4) -- (2,-3.5) -- (3.5,-2) -- (14.5, 0);
\end{tikzpicture}
\end{document}
もちろん、滑らかなランダム曲線を描くこともできます。この時点では、これは 2 つのステップで実行する必要があります。
\path[decorate] <path>;
\draw[<options>] plot[variable=\x,samples at={1,...,\arabic{randymark}},smooth] (randymark\x);
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\newcounter{randymark}
\pgfdeclaredecoration{mark random y steps}{start}
{%
\state{start}[width=+0pt,next state=step,%
persistent precomputation={\pgfdecoratepathhascornerstrue%
\setcounter{randymark}{0}}]{
\stepcounter{randymark}
\pgfcoordinate{randymark\arabic{randymark}}{\pgfpoint{0pt}{0pt}}
}%
\state{step}[auto end on length=1.5\pgfdecorationsegmentlength,
auto corner on length=1.5\pgfdecorationsegmentlength,
width=+\pgfdecorationsegmentlength]
{ \stepcounter{randymark}
\pgfcoordinate{randymark\arabic{randymark}}{\pgfpoint{\pgfdecorationsegmentlength}{rand*\pgfdecorationsegmentamplitude}}
}%
\state{final}
{
\stepcounter{randymark}
\pgfcoordinate{randymark\arabic{randymark}}{\pgfpointdecoratedpathlast}}%
}%
\begin{document}
\begin{tikzpicture}[x=5mm,y=5mm,decoration={mark random y steps,segment length=3mm,amplitude=1mm}]
\path[decorate] (0,-0.5) -- (14.5,-0.5);
\draw[red,thick] plot[variable=\x,samples at={1,...,\arabic{randymark}},smooth]
(randymark\x);
\path[decorate] (0, 0.5) -- (1,0.5) -- (1.5,-4) -- (2,-3.5) -- (3.5,-2) -- (14.5, 0);
\draw[blue,thick] plot[variable=\x,samples at={1,...,\arabic{randymark}},smooth]
(randymark\x);
\path[decorate] (4,4) circle(3cm);
\draw[orange,thick] plot[variable=\x,samples at={1,...,\arabic{randymark}},smooth]
(randymark\x);
\end{tikzpicture}
\end{document}
これはパスに滑らかなランダム曲線を描く最初の投稿ではないことに注意してください。以前にも、次のような投稿がいくつかあります。これです、これです、の答えこの質問そして答えはこの質問。