3

I want to draw a vertical in the middle of line. I calculated the coordinate M which represents the middle. Since I know the slope of the original line I want to try to draw the vertical from that M coordinate with tan(-1/m) angle with a specific length. Maybe i misunderstood the example http://www.texample.net/tikz/examples/refraction/ of angles but I guess the second parameter refers to the length (\draw (C3M) -- (-59:8.2cm);). But in my approach this parameter primary effects the angle used. Is maybe the axis environment responsible for this behavior?

\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}

enter image description here

I wanna end up with something like this:

enter image description here

5

One way is to use partway modifiers

\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}

enter image description here

And avoid using minimal class. It is meant for LaTeX developers. The actual minimal class is article for users.

  • 3mm from m in the direction of (4,3) that have been rotated by -90 degree. – Tarass Feb 11 '18 at 15:18
  • That means perpendicular to (m)--(4,3). – Tarass Feb 11 '18 at 15:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.