如何绘制与坐标系成一定角度的平行线?

如何绘制与坐标系成一定角度的平行线?

如何绘制与坐标系成一定角度的平行线?在下图中,您可以看到三条平行线(紫色和虚线)。这已经完成了,但或多或​​少是蛮力,但我确信只需使用局部坐标系就可以复制或重复这些线。我找不到方法,如果能得到任何帮助,我将不胜感激。

在此处输入图片描述

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,fit}
\usetikzlibrary{intersections,positioning,calc}

\begin{document}

\begin{tikzpicture}

    % grid and axes
    \draw[very thin,color=gray] (-0.1,-0.1) grid (7,7);    
    \draw[->,name path=xaxis] (-0.2,0) -- (8,0) node[right] {$x_{11}$};
    \draw[->,name path=yaxis] (0,-0.2) -- (0,8) node[above] {$x_{12}$};

    % lines  
    \draw[color=red,ultra thick,name path=line1,domain=-0.5:5.5] plot (2,\x) node[above right] {$x_{11} = 2$};
    \draw[color=blue,ultra thick,name path=line2,domain=1.5:6.5] plot (\x,{6 -  \x}) node[below right] {$x_{11} + x_{12} = 6$};
    \draw[color=green!90!black,ultra thick,name path=line3,domain=-0.5:7.5] plot (\x,3) node[above right] {$x_{12} = 3$};
   
   
   % Parallel lines
    \draw[dotted,color=purple!90!red,ultra thick,name path=line4,domain=-.5:1.5] plot (3*\x,-2*\x) node[above right] {};
    \draw[dotted,color=purple!90!red,ultra thick,name path=line5,domain=-.4:1.6] plot (1+3*\x,2-2*\x) node[above right] {};
    \draw[dotted,color=purple!90!red,ultra thick,name path=line6,domain=-.7:1.3] plot (3+3*\x,3-2*\x) node[above right] {};

    % calculate intersection points
    \node[name intersections={of=line1 and line3}] (a) at (intersection-1) {};
    \node[name intersections={of=line2 and line3}] (b) at (intersection-1) {};
    \node[name intersections={of=line1 and xaxis}] (d) at (intersection-1) {};
    \node[name intersections={of=line2 and xaxis}] (c) at (intersection-1) {};

    % polytope    
    \filldraw[thick,fill=green!80!black,fill opacity=0.4] (a.center) -- (b.center) -- (c.center) -- (d.center)  -- cycle;


     % vectors
    \draw[color=red,ultra thick,->] (2,2) -- (2.7,2) node[above] {$(1,0)$};
    \draw[color=blue,ultra thick,->] (4.5,1.5) -- (5.5,2.5) node[right] {$(1,1)$};
    \draw[color=green!90!black,ultra thick,->] (5,3) -- (5,4.2) node[above] {$(0,1)$};
    \draw[ultra thick,color=purple!90!red,->] (0,0) -- (-1,-1.5) node[below] {$(-2,-3)$};
    
    \draw[dashed, thick,color=purple!90!red,<->] (2.33,-3) -- (3.67,-1) node[above] {$min$};
    \path (2.33,-3) node [text=purple!90!red,below] {max};


\end{tikzpicture}

\end{document}

答案1

平行线

只需选择任意起点,然后按照foreach命令行事。我让你根据自己的目的和意愿进行调整。

\documentclass[border=10pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{matrix,fit}
\usetikzlibrary{intersections,positioning,calc}

\begin{document}

\begin{tikzpicture}

    % grid and axes
    \draw[very thin,color=gray] (-0.1,-0.1) grid (7,7);    
    \draw[->,name path=xaxis] (-0.2,0) -- (8,0) node[right] {$x_{11}$};
    \draw[->,name path=yaxis] (0,-0.2) -- (0,8) node[above] {$x_{12}$};

    % lines  
    \draw[color=red,ultra thick,name path=line1,domain=-0.5:5.5] plot (2,\x) node[above right] {$x_{11} = 2$};
    \draw[color=blue,ultra thick,name path=line2,domain=1.5:6.5] plot (\x,{6 -  \x}) node[below right] {$x_{11} + x_{12} = 6$};
    \draw[color=green!90!black,ultra thick,name path=line3,domain=-0.5:7.5] plot (\x,3) node[above right] {$x_{12} = 3$};
   
   
   % Parallel lines
%    \draw[dotted,color=purple!90!red,ultra thick,name path=line4,domain=-.5:1.5] plot (3*\x,-2*\x) node[above right] {};
%    \draw[dotted,color=purple!90!red,ultra thick,name path=line5,domain=-.4:1.6] plot (1+3*\x,2-2*\x) node[above right] {};
%    \draw[dotted,color=purple!90!red,ultra thick,name path=line6,domain=-.7:1.3] plot (3+3*\x,3-2*\x) node[above right] {};
    
    % New parallel lines    
    \foreach \i in {1,...,5}
        \draw [dashed,cap=round,thick,purple] ($(-2,1)+(60:\i)$) --++ (-30:8);
        
        
    % calculate intersection points
    \node[name intersections={of=line1 and line3}] (a) at (intersection-1) {};
    \node[name intersections={of=line2 and line3}] (b) at (intersection-1) {};
    \node[name intersections={of=line1 and xaxis}] (d) at (intersection-1) {};
    \node[name intersections={of=line2 and xaxis}] (c) at (intersection-1) {};

    % polytope    
    \filldraw[thick,fill=green!80!black,fill opacity=0.4] (a.center) -- (b.center) -- (c.center) -- (d.center)  -- cycle;


     % vectors
    \draw[color=red,ultra thick,->] (2,2) -- (2.7,2) node[above] {$(1,0)$};
    \draw[color=blue,ultra thick,->] (4.5,1.5) -- (5.5,2.5) node[right] {$(1,1)$};
    \draw[color=green!90!black,ultra thick,->] (5,3) -- (5,4.2) node[above] {$(0,1)$};
    \draw[ultra thick,color=purple!90!red,->] (0,0) -- (-1,-1.5) node[below] {$(-2,-3)$};
    
%    \draw[dashed, thick,color=purple!90!red,<->] (2.33,-3) -- (3.67,-1) node[above] {$min$};
%    \path (2.33,-3) node [text=purple!90!red,below] {max};


\end{tikzpicture}

\end{document}

答案2

使用tzplot包裹:

在此处输入图片描述

\documentclass[tikz]{standalone}
    
\usepackage{tzplot}

\begin{document}

\begin{tikzpicture}[ultra thick,>=to]
% grid and axes (same as in question)
\tzhelplines(-.1,-.1)(7,7)
\tzaxes[thin](-.2,-.2)(8,8){$x_{11}$}{$x_{12}$}
\tzline[draw=none]"xaxis"(0,0)(8,0)
% lines (same as in question)
\tzvfnat[red]"line1"{2}[-.5:5.5]{$x_{11}=2$}[ar]
\tzfn[blue]"line2"{6-\x}[1.5:6.5]{$x_{11}+x_{12}=6$}[br]
\tzhfnat[green]"line3"{3}[-.5:7.6]{$x_{12}=3$}[ar]
% intersections (same as in question)
\tzXpoint{line1}{line3}(a)
\tzXpoint{line2}{line3}(b)
\tzXpoint{line1}{xaxis}(d)
\tzXpoint{line2}{xaxis}(c)
% polytope (same as in question)
\tzpolygon*[fill=green,thick](a)(b)(c)(d);
% vectors (same as in question)
\tzline[red,->](2,2)(2.7,2){$(1,0)$}[a]
\tzline[blue,->](4.5,1.5)(5.5,2.5){$(1,1)$}[r]
\tzline[green,->](5,3)(5,4.2){$(0,1)$}[a]
\tzline[purple,->](0,0)(-1,-1.5){$(-2,-3)$}[b]
\tzline[purple,dashed,thick,<->](2.33,-3){$max$}[at start,b](3.67,-1){$min$}[a]
% dotted line
\tzLFn[purple,dotted](0,0){-2/3}[-1.5:4.5]
% <shift> lines (copy from dotted line)
\tzLFn[purple,dotted]<1,2>(0,0){-2/3}[-1.2:4.7]
\tzLFn[purple,dotted]<3,3>(0,0){-2/3}[-2.1:3.9]
\end{tikzpicture}

\end{document}

相关内容