線の真ん中に垂直に描く

線の真ん中に垂直に描く

M線の真ん中に垂直線を引こうと思います。真ん中を表す座標を計算しました。元の線の傾きがわかっているので、そのM座標から特定の長さのtan(-1/m)角度で垂直線を引こうと思います。例を誤解したのかもしれません。http://www.texample.net/tikz/examples/refraction/角度ですが、2 番目のパラメータは長さ ( \draw (C3M) -- (-59:8.2cm);) を参照していると思います。ただし、私のアプローチでは、このパラメータは主に使用される角度に影響します。おそらく、この動作の原因は環境にあるのでしょうかaxis?

\documentclass{minimal} 
\usepackage{tikz,pgfplots}
\pgfplotsset{compat=1.11}
\usetikzlibrary{intersections}
\begin{document} 
\begin{tikzpicture}
\begin{axis}[
scale only axis, % The height and width argument only apply to the actual axis
    height=5cm,
    axis x line=middle, axis y line=middle, xlabel={$x_1$},
    xlabel style={anchor=north}, ylabel={$x_2$},ylabel style={anchor=south east},
    xmin=0, xmax=7.5, ymin=0, ymax=11.5,no marks
    ]
    \addplot[fill=yellow!50,draw=none]coordinates{(0,0)(4,0)(4,3)(2,6)(0,6)};
    \addplot[black]coordinates{(0,6)(2,6)};
    \addplot[black]{0};
    \addplot[black]coordinates{(0,0)(0,6)};
    \addplot[black]coordinates{(4,0)(4,3)};
    \addplot[black]coordinates{(4,3)(2,6)};
    \path (6,0)--coordinate(C3M) node[right]{$3x_1+2x_2\leq 18$} (0,9);   
    \path (4,0)--coordinate(C1M) node[right]{$x_1\leq 4$} (4,3);
    \path (0,6)--coordinate(C2M) node[above]{$x_2 \leq 6$} (2,6);
    \draw (C3M) -- (-59:8.2cm);
    \draw (C3M) arc (0:-59:2) ;
    \end{axis}
\end{tikzpicture}
\end{document}

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

最終的には次のようになります:

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

答え1

一つの方法は途中修飾語を使うことだ

\documentclass{standalone}
\usepackage{pgfplots}
\usetikzlibrary{calc}
\pgfplotsset{compat=newest}
\begin{document} 
\begin{tikzpicture}
\begin{axis}[scale only axis, axis height=5cm,
    axis x line=middle, axis y line=middle, xlabel={$x_1$},
    xlabel style={anchor=north}, ylabel={$x_2$},ylabel style={anchor=south east},
    xmin=0, xmax=7.5, ymin=0, ymax=11.5,no marks
    ]

\addplot[draw=black,fill=yellow!50] coordinates{(0,0) (0,6) (2,6) (4,3) (4,0)} \closedcycle;
\draw[-latex] ($(2,6)!0.5!(4,3)$) coordinate (m) -- ($(m)!3mm!-90:(4,3)$) 
                                                  node[anchor=30]{$3x_1+2x_2\leq 18$} ;
\end{axis}
\end{tikzpicture}
\end{document}

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

また、minimalクラスの使用は避けてください。これは LaTeX 開発者向けです。実際の最小限のクラスはarticleユーザー向けです。

関連情報