如何在乳胶(例如,tikz / pgf)中绘制以下三个不等式的三维图形?

如何在乳胶(例如,tikz / pgf)中绘制以下三个不等式的三维图形?

如何在 latex ( tikz/pgf ) 中绘制以下三个不等式的 3D 图形?

z <= x + y + 1,

z <= 4x,

z <= 5y。


我的尝试:

\documentclass[12pt,leqno]{amsart}
\usepackage{pgfplots}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
            \begin{axis}
            \addplot3 [
            domain=-5:20,
            domain y = -3:10,
            samples = 20,
            samples y = 8,
            surf] {x+y+1};
            \addplot3[domain=-5:20,
            domain y = -3:10,
            samples = 20,
            samples y = 8,
            surf, opacity=0.25]{4*x};
            \addplot3[domain=-5:20,
            domain y = -3:10,
            samples = 20,
            samples y = 8,
            surf, opacity=0.25]{5*y};
            \end{axis}
            \end{tikzpicture}
            \end{document}

上述 Latex 代码产生上图: 在此处输入图片描述

但是上图不太清晰,三个半平面的交线不清楚。

任何有助于绘制具有清晰交叉点的清晰图像。

对于给定的 3 个不等式的 3D 图形,有任何帮助吗?

谢谢

编辑:

上述三个不等式的二维投影为:

在此处输入图片描述

@Juan Castaño 的回答证实了这一点。

答案1

用这个画并不难tikz(而且在我看来,在这种情况下看起来比用这个更好pgfplots)。主要问题是数学问题:找到所有的交点和线。然后你必须分割平面并排列每个部分以获得正确的可见性。

像这样:

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\tikzset
{%
  plane 1/.style={thick,blue,fill=cyan!20,fill opacity=0.9},            % z=x+y+1
  plane 2/.style={thick,green!40!black,fill=green!20,fill opacity=0.9}, % z=4x
  plane 3/.style={thick,brown,fill=yellow!20,fill opacity=0.9},         % z=5y
  inter/.style  ={thick,red},                                           % intersection lines
}

\begin{document}
\begin{tikzpicture}
[%
  x={(-0.4cm,-0.2cm)},y={(0.8cm,-0.3cm)},z={(0cm,0.4cm)},%
  line cap=round,line join=round%
]
% z=x+y+1
\coordinate (A1) at (0,0,1);
\coordinate (A2) at (4,0,5);
\coordinate (A3) at (4,4,9);
\coordinate (A4) at (0,4,5);
% z=4x
\coordinate (O)  at (0,0,0);
\coordinate (B2) at (4,0,16);
\coordinate (B3) at (4,4,16);
\coordinate (B4) at (0,4,0);
% z=5y
\coordinate (C2) at (4,0,0);
\coordinate (C3) at (4,4,20);
\coordinate (C4) at (0,4,20);
% intersection points
\coordinate (P)  at (4,3.2,16);
\coordinate (Q)  at (4,1.25,6.25);
\coordinate (R)  at (5/11,4/11,20/11);
\coordinate (S)  at (5/3,4,20/3);
\coordinate (T)  at (0,0.25,1.25);
\coordinate (U)  at (1/3,0,4/3);
% projection points
\coordinate (V)  at (4,4,0);
\coordinate (W)  at (5/11,4/11,0);
\coordinate (X)  at (4,1.25,0);
\coordinate (Y)  at (5/3,4,0);
% axes and dashed lines
\draw[dashed] (4,0,0) -- (B2);
\draw[dashed] (0,4,0) -- (C4);
\draw[thick,-latex] (O) -- (5,0,0)  node [left]  {$x$};
\draw[thick,-latex] (O) -- (0,5,0)  node [right] {$y$};
\draw[thick,-latex] (O) -- (0,0,15) node [above] {$z$};
% planes and intersection lines
\draw[plane 1] (A1) -- (U)  -- (R)  -- (T)  -- cycle;
\draw[plane 3] (O)  -- (P)  -- (C3) -- (C4) -- cycle;
\draw[plane 1] (T)  -- (A4) -- (S)  -- (R)  -- cycle;
\draw[plane 2] (O)  -- (B2) -- (B3) -- (B4) -- cycle;
\draw[plane 1] (U)  -- (A2) -- (Q)  -- (R)  -- cycle;
\draw[plane 3] (O)  -- (C2) -- (C3) -- (P)  -- cycle;
\draw[inter]   (O)  -- (P);
\draw[plane 1] (Q)  -- (R)  -- (S)  -- (A3) -- cycle;
\draw[inter]   (Q)  -- (R)  -- (S);
% projection
\draw[fill=gray!20] (W) -- (Y)  -- (V) -- (X)  -- cycle;
\draw[fill=gray!30] (O) -- (B4) -- (Y) -- (W)  -- cycle;
\draw[fill=gray!40] (O) -- (W)  -- (X) -- (C2) -- cycle;
% more dashed lines
\draw[dashed] (V) -- (C3);
\draw[dashed] (W) -- (R);
\draw[dashed] (X) -- (Q);
\draw[dashed] (Y) -- (S);
% labels
\node[blue]           at (A4) [right] {$z=x+y+1$};
\node[green!40!black] at (B2) [above] {$z=4x$};
\node[brown]          at (C4) [above] {$z=5y$};
\fill[red] (R) circle (1pt) node [below right] {$\left(\frac{5}{11},\frac{4}{11},\frac{20}{11}\right)$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑1:这是 2D 投影。它本质上与上面的代码相同(标记为“投影”),但删除了平面、线和每个点的第三个坐标。

\documentclass[border=2mm]{standalone}
\usepackage{tikz}

\tikzset
{%
  plane 1/.style={fill=cyan!20  ,fill opacity=0.9}, % z=x+y+1
  plane 2/.style={fill=green!20 ,fill opacity=0.9}, % z=4x
  plane 3/.style={fill=yellow!20,fill opacity=0.9}, % z=5y
}

\begin{document}
\begin{tikzpicture}[thick,line cap=round,line join=round]
% z=4x
\coordinate (O)  at (0,0);
\coordinate (B4) at (0,4);
% z=5y
\coordinate (C2) at (4,0);
% projection points
\coordinate (V)  at (4,4);
\coordinate (W)  at (5/11,4/11);
\coordinate (X)  at (4,1.25);
\coordinate (Y)  at (5/3,4);
% axes
\draw[thick,-latex] (O) -- (5,0) node [right] {$x$};
\draw[thick,-latex] (O) -- (0,5) node [above] {$y$};
% projection
\draw[plane 1] (W) -- (Y)  -- (V) -- (X)  -- cycle;
\draw[plane 2] (O) -- (B4) -- (Y) -- (W)  -- cycle;
\draw[plane 3] (O) -- (W)  -- (X) -- (C2) -- cycle;
% labels
\node at (2.5,2.5) {$z=x+y+1$};
\node at (0.7,3.5) {$z=4x$};
\node at (3  ,0.5) {$z=5y$};
\fill[red] (W) circle (1pt) node [above right] {$\left(\frac{5}{11},\frac{4}{11},\frac{20}{11}\right)$};
\end{tikzpicture}
\end{document}

在此处输入图片描述

编辑2:根据 OP 的评论,我使用子标题将两张图片连接起来。根据文档的几何形状,可能需要更改比例或宽度。

抱歉,代码重复了:

\documentclass{article}
\usepackage   {caption}
\usepackage   {lipsum}    % dummy text
\usepackage   {showframe} % just for the example
\usepackage   {tikz}

\tikzset
{%
  plane 1/.style={thick,blue,fill=cyan!20,fill opacity=0.9},            % z=x+y+1
  plane 2/.style={thick,green!40!black,fill=green!20,fill opacity=0.9}, % z=4x
  plane 3/.style={thick,brown,fill=yellow!20,fill opacity=0.9},         % z=5y
  inter/.style  ={thick,red},                                           % intersection lines
}

\begin{document}
\lipsum[1]

\begin{figure}[h]\centering
\begin{minipage}[b]{0.54\textwidth}\centering % b = bottom alignment
\begin{tikzpicture}
[%
  scale=0.6, % <-- added
  x={(-0.4cm,-0.2cm)},y={(0.8cm,-0.3cm)},z={(0cm,0.4cm)},%
  line cap=round,line join=round%
]
% z=x+y+1
\coordinate (A1) at (0,0,1);
\coordinate (A2) at (4,0,5);
\coordinate (A3) at (4,4,9);
\coordinate (A4) at (0,4,5);
% z=4x
\coordinate (O)  at (0,0,0);
\coordinate (B2) at (4,0,16);
\coordinate (B3) at (4,4,16);
\coordinate (B4) at (0,4,0);
% z=5y
\coordinate (C2) at (4,0,0);
\coordinate (C3) at (4,4,20);
\coordinate (C4) at (0,4,20);
% intersection points
\coordinate (P)  at (4,3.2,16);
\coordinate (Q)  at (4,1.25,6.25);
\coordinate (R)  at (5/11,4/11,20/11);
\coordinate (S)  at (5/3,4,20/3);
\coordinate (T)  at (0,0.25,1.25);
\coordinate (U)  at (1/3,0,4/3);
% projection points
\coordinate (V)  at (4,4,0);
\coordinate (W)  at (5/11,4/11,0);
\coordinate (X)  at (4,1.25,0);
\coordinate (Y)  at (5/3,4,0);
% axes and dashed lines
\draw[dashed] (4,0,0) -- (B2);
\draw[dashed] (0,4,0) -- (C4);
\draw[thick,-latex] (O) -- (5,0,0)  node [left]  {$x$};
\draw[thick,-latex] (O) -- (0,5,0)  node [right] {$y$};
\draw[thick,-latex] (O) -- (0,0,15) node [above] {$z$};
% planes and intersection lines
\draw[plane 1] (A1) -- (U)  -- (R)  -- (T)  -- cycle;
\draw[plane 3] (O)  -- (P)  -- (C3) -- (C4) -- cycle;
\draw[plane 1] (T)  -- (A4) -- (S)  -- (R)  -- cycle;
\draw[plane 2] (O)  -- (B2) -- (B3) -- (B4) -- cycle;
\draw[plane 1] (U)  -- (A2) -- (Q)  -- (R)  -- cycle;
\draw[plane 3] (O)  -- (C2) -- (C3) -- (P)  -- cycle;
\draw[inter]   (O)  -- (P);
\draw[plane 1] (Q)  -- (R)  -- (S)  -- (A3) -- cycle;
\draw[inter]   (Q)  -- (R)  -- (S);
% projection
\draw[fill=gray!20] (W) -- (Y)  -- (V) -- (X)  -- cycle;
\draw[fill=gray!30] (O) -- (B4) -- (Y) -- (W)  -- cycle;
\draw[fill=gray!40] (O) -- (W)  -- (X) -- (C2) -- cycle;
% more dashed lines
\draw[dashed] (V) -- (C3);
\draw[dashed] (W) -- (R);
\draw[dashed] (X) -- (Q);
\draw[dashed] (Y) -- (S);
% labels
\node[blue]           at (A4) [right] {$z=x+y+1$};
\node[green!40!black] at (B2) [above] {$z=4x$};
\node[brown]          at (C4) [above] {$z=5y$};
\fill[red] (R) circle (1pt) node [below right] {$\left(\frac{5}{11},\frac{4}{11},\frac{20}{11}\right)$};
\end{tikzpicture}
\caption{Subpicture 1}\label{fig:figA}
\end{minipage}
\begin{minipage}[b]{0.44\textwidth}\centering % b = bottom alignment
\begin{tikzpicture}
[%
  scale=0.8, % <-- added
  thick,line cap=round,line join=round
]
% z=4x
\coordinate (O)  at (0,0);
\coordinate (B4) at (0,4);
% z=5y
\coordinate (C2) at (4,0);
% projection points
\coordinate (V)  at (4,4);
\coordinate (W)  at (5/11,4/11);
\coordinate (X)  at (4,1.25);
\coordinate (Y)  at (5/3,4);
% axes
\draw[thick,-latex] (O) -- (5,0) node [right] {$x$};
\draw[thick,-latex] (O) -- (0,5) node [above] {$y$};
% projection
\draw[plane 1] (W) -- (Y)  -- (V) -- (X)  -- cycle;
\draw[plane 2] (O) -- (B4) -- (Y) -- (W)  -- cycle;
\draw[plane 3] (O) -- (W)  -- (X) -- (C2) -- cycle;
% labels
\node at (2.6,2.5) {$z=x+y+1$}; % <-- changed
\node at (0.7,3.5) {$z=4x$};
\node at (3  ,0.3) {$z=5y$};    % <-- changed
\fill[red] (W) circle (1pt) node [above right] {$\left(\frac{5}{11},\frac{4}{11},\frac{20}{11}\right)$};
\end{tikzpicture}
\caption{Subpicture 1}\label{fig:figB}
\end{minipage}
\end{figure}

\lipsum[2]
\end{document}

在此处输入图片描述

答案2

对于给定的 3 个不等式的 2D 和 3D 图形有任何帮助吗?

最直接的方法是将 z = 0 的 3 个不等式绘制在二维中。不幸的是,我之前从未使用过该软件包,所以我不得不将代码细节留给专家。

然而 ..

0 <= x+y+1, 0 <= 4x, 0 <= 5y。

2D投影如下(即z=0-平面):

...你确定该图符合这 3 个不等式吗?

  • x >= 0
  • y >= 0
  • x + y >= -1

相关内容