在直線中間繪製垂直線

在直線中間繪製垂直線

我想在線中間畫一條垂直線。我計算了M代表中間的座標。因為我知道原始線的斜率,所以我想嘗試從中繪製垂直線M座標以特定長度的 tan(-1/m) 角度繪製垂直線。也許我誤解了這個例子http://www.texample.net/tikz/examples/refraction/角度,但我猜第二個參數指的是長度(\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

一種方法是使用 halfway 修飾符

\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針對使用者的。

相關內容