等高線上にグラデーション矢印を描くにはどうすればいいですか

等高線上にグラデーション矢印を描くにはどうすればいいですか

pgfplots を使用して、関数 f(x,y) の等高線を描画します。これは、f(x,y)=C などの線で、C は選択した数値です。

以下の例を参照してください:

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}

\begin{document}

\begin{center}
    \begin{tikzpicture}[scale=0.85]
    \begin{axis}[   xmin=-4,xmax=12, ymin=-4,ymax=4,x=1cm,y=1cm,at={(-4cm,-4cm)}]]
    \addplot +[no markers,
    raw gnuplot,
    thick,dashed,
    empty line = jump, % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
    ] gnuplot {
        set contour base;
        set cntrparam levels discrete -2,-1.1,-1.4;
        unset surface;
        set view map;
        set isosamples 500;
        set samples 500;
        splot -2/sqrt((x-7.5)^2+y^2)-3/sqrt((x-0.5)^2+y^2);
    };
    \end{axis}
    \end{tikzpicture}
\end{center}
\end{document}

等高線 任意のポイントに勾配ベクトルを描くことはできますが、等高線曲線上のさまざまな場所に勾配ベクトルを配置する方法がわかりません。

ここに画像の説明を入力してください

破線の青い曲線上のさまざまな点の位置を取得するにはどうすればよいでしょうか?

答え1

等高線プロットの座標にアクセスできるという事実を利用できます。これらは複数の切断されたセグメントであるため、指定するposだけでは不十分です。代わりに、pos segmentpgfplots マニュアル v1.16 の 358 ページで説明されている も使用する必要があります。ただし、どのセグメントにどのインデックスがあるかは事前には明らかではありません。問題を簡素化するために、この時点で等高線の接線に直交するグラデーション矢印を追加するスタイルを追加しました。

\documentclass{article}

\usepackage{pgfplots}
\pgfplotsset{compat=newest}
\begin{document}

\begin{center}
 \begin{tikzpicture}[gradient arrow/.style={
 insert path={coordinate[pos=#1,sloped,
     above=\pgfkeysvalueof{/tikz/ga/above}]  (aux-1)
    coordinate[pos=#1,sloped,
     above=\pgfkeysvalueof{/tikz/ga/above}+\pgfkeysvalueof{/tikz/ga/length}] (aux-2)
    (aux-1) edge[/tikz/ga/arrow] 
    (aux-2)}},ga/.cd,
    above/.initial=3pt,
    length/.initial=12pt,
    arrow/.style={-stealth,black,solid,thick}]
  \begin{axis}[scale=0.85,xmin=-4,xmax=12, ymin=-4,ymax=4,x=1cm,y=1cm,at={(-4cm,-4cm)}]]
   \addplot +[no markers,name=contour,
    raw gnuplot,
    thick,dashed,
    empty line = jump, % not strictly necessary, as this is the default behaviour in the development version of PGFPlots
    ] gnuplot {
        set contour base;
        set cntrparam levels discrete -2,-1.1,-1.4;
        unset surface;
        set view map;
        set isosamples 500;
        set samples 500;
        splot -2/sqrt((x-7.5)^2+y^2)-3/sqrt((x-0.5)^2+y^2);
    } 
    [pos segment=1]
    [gradient arrow/.list={0.2,0.8}]
    [pos segment=3,/tikz/ga/arrow/.append style={red},/tikz/ga/length=10pt]
    [gradient arrow/.list={0.2,0.8}];
  \end{axis}
 \end{tikzpicture}
\end{center}
\end{document}

ここに画像の説明を入力してください

関連情報