为了提供进一步的说明(为您节省一些阅读时间),我们尝试以参数方式定义第二个图表,以便截断两个平面部分,只留下可用于图表的部分。希望这有帮助!谢谢
对这个问题所采用的技术感兴趣:如何绘制两个相交的圆柱体?。
具体来说,由于我仍在学习 Asymptote,我想使用 pgfplots 方法绘制三个圆柱体的相交表面。我通过摆弄代码得到了三个相交圆柱体的图表,但在创建它们的相交表面时却遇到了困难。
这是我所拥有的相交圆柱体的图表,供参考(当然,这要归功于它的灵感。) - 请参阅底部的 MWE #1:
这就是我目前所得到的(如果我能解决一个部分,那么我就能解决剩下的部分) - 参见 MWE #2:
我想要的是这种形状的东西,除了对应的是三个圆柱体而不是两个圆柱体——归功于斯图尔特:
最大能量损失 #1
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=3]
\begin{axis}[%
axis equal,
enlargelimits = true,
samples = 45, samples y = 45,
axis lines = none, ticks = none,
cyl/.style = {%
surf,
black!30!,
variable = \u,
variable y = \v,
z buffer = sort,
faceted color=black!70!,
},
%view/h = 125, view/v = 25
]
\addplot3[% (-) Z-SEMIAXIS
cyl,
domain = -3:3,
y domain = 0:360,
] ({cos(v)}, {sin(v)}, {min(u,abs(cos(v)),abs(sin(v)))});
\addplot3[% (-) X-SEMIAXIS
cyl,
domain = -3:3,
y domain = 0:360,
] ({min(u,-abs(cos(v)),-abs(sin(v)))}, {cos(v)}, {sin(v)});
\addplot3[% (+) Y-SEMIAXIS
cyl,
domain = 0:360,
y domain = -3:3,
] ({cos(u)}, {max(v,abs(cos(u)),abs(sin(u)))}, {sin(u)});
\addplot3[% (+) X-SEMIAXIS
cyl,
domain = -3:3,
y domain = 0:360,
] ({max(u,abs(cos(v)),abs(sin(v)))}, {cos(v)}, {sin(v)});
\addplot3[% (+) X-SEMIAXIS
cyl,
domain = -3:3,
y domain = 0:360,
] ({cos(v)}, {sin(v)}, {max(u,abs(cos(v)),abs(sin(v)))});
\addplot3[% (-) Y-SEMIAXIS
cyl,
domain = 0:360,
y domain = -3:3,
] ({cos(u)}, {min(-abs(cos(u)),-abs(sin(u)),v)}, {sin(u)});
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
最大能量损失 #2
\documentclass{article}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{center}
\begin{tikzpicture}[scale=2]
\begin{axis}[%
axis equal,
enlargelimits = true,
samples = 45, samples y = 45,
axis lines = none, ticks = none,
cyl/.style = {%
surf,
black!30!,
variable = \u,
variable y = \v,
z buffer = sort,
faceted color=black!70!,
},
%view/h = 125, view/v = 25
]
\addplot3[% (-) Z-SEMIAXIS
cyl,
domain = -3:3,
y domain = 0:360,
restrict z to domain=-2:2,
] ({max(abs(u),cos(v))}, {sin(v)}, {u});
\end{axis}
\end{tikzpicture}
\end{center}
\end{document}
由@hpekristiansen 编辑:
在此处找到:https://abel.math.harvard.edu/archive/21a_summer_06/handouts/3cylinder.pdf
答案1
\documentclass[tikz, border=1cm]{standalone}
\usepackage{pgfplots}
\pgfplotsset{compat=1.18}
\begin{document}
\begin{tikzpicture}[line join=round]
\begin{axis}[
view={20}{40},
axis equal,
axis lines=none,
colormap/blackwhite,
cylinder/.style={
surf,
domain=-1:1,
samples=41,
variable=\u, variable y=\v,
z buffer=sort,
ultra thin,
},
]
\addplot3[
cylinder, red!40,
y domain=0:270, %adjust domain to show front petals dependent on `view`
samples y=61,
x filter/.expression={
(u>0)?
((cos(v)^2+u^2<1)&&(sin(v)^2+u^2<1)?u:(min( sqrt(1-cos(v)^2), sqrt(1-sin(v)^2)))):
((cos(v)^2+u^2<1)&&(sin(v)^2+u^2<1)?u:(max(-sqrt(1-cos(v)^2),-sqrt(1-sin(v)^2))))
},
] (u, {cos(v)}, {sin(v)});
\addplot3[
cylinder, green!40,
y domain=-90:90, %adjust domain to show front petals dependent on `view`
samples y=41,
y filter/.expression={
(u>0)?
((cos(v)^2+u^2<1)&&(sin(v)^2+u^2<1)?u:(min( sqrt(1-cos(v)^2), sqrt(1-sin(v)^2)))):
((cos(v)^2+u^2<1)&&(sin(v)^2+u^2<1)?u:(max(-sqrt(1-cos(v)^2),-sqrt(1-sin(v)^2))))
},
] ({sin(v)}, u, {cos(v)});
\addplot3[
cylinder, blue!40,
y domain=180:360, %adjust domain to show front petals dependent on `view`
samples y=41,
z filter/.expression={
(u>0)?
((cos(v)^2+u^2<1)&&(sin(v)^2+u^2<1)?u:(min( sqrt(1-cos(v)^2), sqrt(1-sin(v)^2)))):
((cos(v)^2+u^2<1)&&(sin(v)^2+u^2<1)?u:(max(-sqrt(1-cos(v)^2),-sqrt(1-sin(v)^2))))
},
] ({cos(v)}, {sin(v)}, u);
\end{axis}
\end{tikzpicture}
\end{document}
答案2
一种可能性是分别构建每个“半面”,并根据视点逐层添加。面的参数化形式为 (cos(u)、sin(u)、max(cos(u)、abs(sin(u))、v)),其中 -90<=u<=90 且 0<=v<=1.1(对于与 Oz 轴平行的圆柱体)。
将循环排列坐标以获得另外两个圆柱体。
评论。 顺序很重要,我只知道如何从观察者的角度考虑并检查输出来手工完成。
我在两个圆柱的交点下方插入;在这种情况下,第三个坐标更简单——mxax(cos(u), v)——因为只有两个相交的表面。但它表明三个相交圆柱的情况是一种自然的概括。
代码
\documentclass[11pt, margin=10pt]{standalone}
\usepackage{pgfplots}
\usepgfplotslibrary{colorbrewer}
\pgfplotsset{compat=1.17}
\usetikzlibrary[pgfplots.colormaps]
\begin{document}
\pgfplotsset{%
cylinder piece/.style args={u domain=#1, cmap=#2}{%
opacity = 1,
surf,
colormap/#2,
shader=interp,
z buffer = sort,
samples = 33, % 1 mod 4
variable = \u,
variable y = \v,
domain = #1,
y domain = 0:1.1,
}
}
\iffalse % 2 intersectiong cylinders
\begin{tikzpicture}
\begin{axis}[axis equal,
axis lines=none,
view={130}{28}]
% z cylinder x<0
\addplot3[cylinder piece={u domain={-90:90}, cmap=summer}]
({-cos(u)}, {sin(u)}, {-min(cos(u), v)});
\addplot3[cylinder piece={u domain={-90:90}, cmap=summer}]
({-cos(u)}, {sin(u)}, {min(cos(u), v)});
% x cylinder z<0
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({-min(sin(u), v)}, {cos(u)}, {-sin(u)});
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({min(sin(u), v)}, {cos(u)}, {-sin(u)});
% x cylinder z>0
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({-min(sin(u), v)}, {cos(u)}, {sin(u)});
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({min(sin(u), v)}, {cos(u)}, {sin(u)});
% z cylinder x>0
\addplot3[cylinder piece={u domain={-90:90}, cmap=summer}]
({cos(u)}, {sin(u)}, {-min(cos(u), v)});
\addplot3[cylinder piece={u domain={-90:90}, cmap=summer}]
({cos(u)}, {sin(u)}, {min(cos(u), v)});
\end{axis}
\end{tikzpicture}
\fi
% \iffalse % 3 intersecting cylinders
\begin{tikzpicture}
\begin{axis}[axis equal,
axis lines=none,
view={130}{20}]
% y cylinder, x < 0
\addplot3[cylinder piece={u domain={-90:90}, cmap=winter}]
({-cos(u)}, {-min(min(cos(u), abs(sin(u))), v)}, {sin(u)});
\addplot3[cylinder piece={u domain={-90:90}, cmap=winter}]
({-cos(u)}, {min(min(cos(u), abs(sin(u))), v)}, {sin(u)});
% z cylinder, x < 0
\addplot3[cylinder piece={u domain={-90:90}, cmap=summer}]
({-cos(u)}, {sin(u)}, {-min(min(cos(u), abs(sin(u))), v)});
\addplot3[cylinder piece={u domain={-90:90}, cmap=summer}]
({-cos(u)}, {sin(u)}, {min(min(cos(u), abs(sin(u))), v)});
% x cylinder z < 0
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({-min(sin(u), abs(cos(u)), v)}, {cos(u)}, {-sin(u)});
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({min(sin(u), abs(cos(u)), v)}, {cos(u)}, {-sin(u)});
% x cylinder z > 0
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({-min(sin(u), abs(cos(u)), v)}, {cos(u)}, {sin(u)});
\addplot3[cylinder piece={u domain={0:180}, cmap=autumn}]
({min(sin(u), abs(cos(u)), v)}, {cos(u)}, {sin(u)});
% z cylinder, x > 0
\addplot3[cylinder piece={u domain={-90:0}, cmap=summer}]
({cos(u)}, {sin(u)}, {-min(min(cos(u), abs(sin(u))), v)});
\addplot3[cylinder piece={u domain={-90:0}, cmap=summer}]
({cos(u)}, {sin(u)}, {min(min(cos(u), abs(sin(u))), v)});
% y cylinder, x > 0
\addplot3[cylinder piece={u domain={-90:90}, cmap=winter}]
({cos(u)}, {-min(min(cos(u), abs(sin(u))), v)}, {sin(u)});
\addplot3[cylinder piece={u domain={-90:90}, cmap=winter}]
({cos(u)}, {min(min(cos(u), abs(sin(u))), v)}, {sin(u)});
% half z cylinder, x > 0
\addplot3[cylinder piece={u domain={0:90}, cmap=summer}]
({cos(u)}, {sin(u)}, {-min(min(cos(u), abs(sin(u))), v)});
\addplot3[cylinder piece={u domain={0:90}, cmap=summer}]
({cos(u)}, {sin(u)}, {min(min(cos(u), abs(sin(u))), v)});
\end{axis}
\end{tikzpicture}
% \fi
\end{document}