答案1
我不知道您是否需要某种可以计算并绘制解决方案的东西。如果是这样的话,LaTeX 可能不是最好的选择。
如果您只想绘制(已经获得的解决方案)这种方法可以完成大部分任务。
我定义了一些宏,用于在 x、y 或 z 常数处绘制线条及其标签。这些宏使用(缩放的)重心坐标,这样更简单。我之所以包含该siunitx
包,是因为在某些问题(例如您的一些示例)中,您可能没有整数。在这种情况下,您可能需要更改所有的\pgfmathtruncatemacro
for \pgfmathsetmacro
。
代码:
\documentclass[tikz,border=2mm]{standalone}
\usepackage{siunitx}
\sisetup{round-mode=places,round-precision=2,round-pad=false}
\NewDocumentCommand{\xconst}{O{red}mmmm} % #1 = color (red), #2 = x value, #3 = coordinates name, #4,#5 = nodes format
{
\pgfmathtruncatemacro\x{#2}
\pgfmathtruncatemacro\yz{\xyz-\x}
\pgfmathsetmacro\xs{\x/\xyz} % x scaled
\draw[#1] (barycentric cs:X=\xs,Y=0,Z=1-\xs) coordinate (#31) node[left ,#4] {$(\num{\x},0,\num{\yz})$} --
(barycentric cs:X=\xs,Y=1-\xs,Z=0) coordinate (#32) node[below,#5] {$(\num{\x},\num{\yz},0)$};
}
\NewDocumentCommand{\yconst}{O{red}mmmm} % #1 = color (red), #2 = y value, #3 = coordinates name, #4,#5 = nodes format
{
\pgfmathtruncatemacro\y{#2}
\pgfmathtruncatemacro\xz{\xyz-\y}
\pgfmathsetmacro\ys{\y/\xyz} % y scaled
\draw[#1] (barycentric cs:X=0,Y=\ys,Z=1-\ys) coordinate (#31) node[right,#4] {$(0,\num{\y},\num{\xz})$} --
(barycentric cs:X=1-\ys,Y=\ys,Z=0) coordinate (#32) node[below,#5] {$(\num{\xz},\num{\y},0)$};
}
\NewDocumentCommand{\zconst}{O{red}mmmm} % #1 = color (red), #2 = z value, #3 = coordinates name, #4,#5 = nodes format
{
\pgfmathtruncatemacro\z{#2}
\pgfmathtruncatemacro\xy{\xyz-\z}
\pgfmathsetmacro\zs{\z/\xyz} % z scaled
\draw[#1] (barycentric cs:X=0,Y=1-\zs,Z=\zs) coordinate (#31) node[right,#4] {$(0,\num{\xy},\num{\z})$} --
(barycentric cs:X=1-\zs,Y=0,Z=\zs) coordinate (#32) node[left ,#5] {$(\num{\xy},0,\num{\z})$};
}
\begin{document}
\begin{tikzpicture}[line cap=round,line join=round]
\def\r{4}; % tiangle side
\pgfmathsetmacro\xyz{300}; % great coalition payoff
% triangle coordinates
\coordinate (X) at (210:\r);
\coordinate (Y) at (330:\r);
\coordinate (Z) at (90:\r);
% lines
\xconst{12} {X} {}{left,rotate=90} % x >= 12
\yconst{7} {Y} {}{left,rotate=90} % x >= 7
\zconst{10} {Z} {yshift=-1mm}{yshift=-1mm} % z >= 10
\zconst{172}{XY}{yshift=-1mm}{yshift=-1mm} % x + y >= 128 ==> z <= 172
\yconst{115}{XZ}{yshift=1mm} {left,rotate=90} % x + z >= 185 ==> y <= 115
\xconst{282}{YZ}{yshift=2mm} {left,rotate=90,yshift=-1mm} % y + z >= 18 ==> x <= 282
% core
\fill[red,fill opacity=0.3] (X1) -- (X2) -- (YZ2) -- (YZ1) -- cycle;
\fill[red,fill opacity=0.3] (Y1) -- (Y2) -- (XZ2) -- (XZ1) -- cycle;
\fill[red,fill opacity=0.3] (Z1) -- (Z2) -- (XY2) -- (XY1) -- cycle;
% triangle
\draw[thick] (X) node[below left] {$(\xyz,0,0)$} --
(Y) node[below right] {$(0,\xyz,0)$} --
(Z) node[above] {$(0,0,\xyz)$} -- cycle;
\end{tikzpicture}
\end{document}