使用 tikz 绘制覆盖空间

使用 tikz 绘制覆盖空间

我想在 tikz 中设计如下的绘图:(这是我想要的输出)

在此处输入图片描述

目前我有以下代码(显然效率不高......)

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{graphicx}


\begin{document}
\begin{figure}[h]
\centering
\resizebox{\columnwidth}{!}{
\tikzset{every picture/.style={line width=0.75pt}}
\begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
\draw [line width=1.5]    (43,287.33) -- (144.5,287.33) ;
%\draw    (169.5,287.33) -- (231,287.33) ;
%\draw [shift={(233,287.33)}, rotate = 180] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
\draw    (115,275.33) .. controls (137.28,157.52) and (283.53,120.08) .. (333.03,118.37) ;
\draw [shift={(334.5,118.33)}, rotate = 538.81] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
%\draw  [line width=1.5]  (274,257.33) .. controls (284,252.33) and (373.17,228.33) .. (403.17,247.33) .. controls (433.17,266.33) and (412,321.33) .. (393.17,322.33) .. controls (374.33,323.33) and (340.33,322.33) .. (306.17,322.33) .. controls (272,322.33) and (243.4,304.08) .. (245.17,290.33) .. controls (246.94,276.58) and (250.76,276.46) .. (256.5,270.55) .. controls (262.23,264.65) and (269,259.83) .. (274,257.33) -- cycle ;
%\draw    (285,277.33) .. controls (323.17,264.33) and (315.17,280.33) .. (332.17,274.33) .. controls (349.17,268.33) and (346.17,283.33) .. (372.17,274.33) ;
\draw    (165,288.33) -- (333.03,288.33) ;
\draw [shift={(334.5,288.33)}, rotate = 180] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
\draw  [line width=1.5]  (412,254.33) .. controls (421.5,256.2) and (507.5,225.2) .. (537.5,244.2) .. controls (567.5,263.2) and (560.5,317.2) .. (536.17,319.33) .. controls (511.83,321.47) and (483.33,319.33) .. (449.17,319.33) .. controls (415,319.33) and (380.83,323.07) .. (380.5,289.2) .. controls (380.17,255.33) and (386.76,263.11) .. (392.5,257.2) .. controls (398.24,251.29) and (408.5,252.47) .. (417,254.33) -- cycle ;
\draw    (417.5,284.2) .. controls (457.5,254.2) and (486.5,254.2) .. (525,273.2) ;
\draw  [line width=1.5]  (412.5,51.2) .. controls (421,53.07) and (486.5,32.2) .. (562.5,58.2) .. controls (638.5,84.2) and (581.5,145.2) .. (567.5,157.2) .. controls (553.5,169.2) and (433.5,151.2) .. (399.5,161.2) .. controls (365.5,171.2) and (344.33,149.2) .. (344,115.33) .. controls (343.67,81.47) and (346.76,90.11) .. (352.5,84.2) .. controls (358.24,78.29) and (404,49.33) .. (412.5,51.2) -- cycle ;
\draw    (382.5,132.2) .. controls (397.5,112.2) and (418.31,94.7) .. (445.5,93.2) .. controls (472.69,91.7) and (516.25,100.7) .. (535.5,110.2) ;
\draw    (480.5,171.2) -- (480.5,235.33) ;
\draw [shift={(480.5,237.33)}, rotate = 269.57] [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=0.75]    (10.93,-3.29) .. controls (6.95,-1.4) and (3.31,-0.3) .. (0,0) .. controls (3.31,0.3) and (6.95,1.4) .. (10.93,3.29)   ;
% Text Node
\draw (45,290.73) node [anchor=north west][inner sep=0.75pt]    {$0$};
% Text Node
\draw (135.5,290.73) node [anchor=north west][inner sep=0.75pt]    {$1$};
% Text Node
\draw (91,266.73) node [anchor=north west][inner sep=0.75pt]    {$I$};
% Text Node
\draw (250,266.73) node [anchor=north west][inner sep=0.75pt]    {$f$};
% Text Node
\draw (410.17,288.73) node [anchor=north west][inner sep=0.75pt]    {$r$};
% Text Node
\draw (580.17,271.73) node [anchor=north west][inner sep=0.75pt]    {$SO(3)$};
% Text Node
\draw (365.17,130) node [anchor=north west][inner sep=0.75pt]    {$\tilde f(0) = q$};
% Text Node
\draw (500.17,110.73) node [anchor=north west][inner sep=0.75pt]    {$\tilde f(1) = -q$};
% Text Node
\draw (490,192.73) node [anchor=north west][inner sep=0.75pt]    {$p$};
% Text Node
\draw (620,110.73) node [anchor=north west][inner sep=0.75pt]    {$SU(2)$};
% Text Node
\draw (159,141.6) node [anchor=north west][inner sep=0.75pt]    {$\tilde f$};
\end{tikzpicture}}
\end{figure}
\end{document}

这给了我以下输出:

在此处输入图片描述

但我追求的是更具美感的:例如,这个答案,圆圈和路径看起来“更酷”,但我无法将其模仿到我的代码中。对于那些不想点击链接的人,我所说的圆圈是:

在此处输入图片描述

编辑

我在网上找到的一个非常酷的输出(或多或少是我想要的 - 只是有一些细微的差别)是这样的:

在此处输入图片描述

但我不知道如何创建它。

答案1

图书馆

我选择矩阵是因为它会自动为你提供围绕某个子图的节点。不过,这并不能保证椭圆具有相同的大小(这也可以解决)。

最好在背景层上或红色路径及其标签之前绘制该椭圆(尽管这需要您自己确定大小)。
这也是我选择使用 ed 标签的原因,\vphantom以便矩阵内的红线垂直居中。另一种解决方案是使用overlay标签并inner ysep为矩阵节点使用自定义填充。

最后的边缘(标有F) 使用节点作为参考,如果你问我,这有点作弊,但它确实有效。

形状superellipse有点多(它是一个曲线闭合图,它的边框使用的库对于 TeX 来说有点重),如果确实需要的话,intersections最好使用普通形状或用四条贝塞尔曲线构造它。ellipse

最简单的方法就是rectangle使用rounded corners


我注意到我的superellipse形状中有一个错误,当在节点创建和引用之间应用任何转换时,它不会返回正确的边框。这里可以避免。

代码

\documentclass[tikz,border=2pt,convert]{standalone}
\usepackage{mathtools}
\usetikzlibrary{
  arrows.meta,
  bbox,
  decorations.pathmorphing,
  ext.shapes.superellipse,
  positioning,
  quotes,
}
\tikzset{
  shorten/.style={shorten <={#1},shorten >={#1}},
  math node/.style={execute at begin node=$, execute at end node=$}}
\begin{document}
\begin{tikzpicture}[
  @label/.style n args={4}{"#4{#1}" {#2, inner sep=+.1em},
                           "\vphantom{#1}" {#3, inner sep=+.1em}},
  l/.style={@label={#1}{above}{below}{\mathclap}},
  l'/.style={@label={#1}{below left}{above left}{}},
  >={Triangle[scale=1.33, angle=45:1pt 3]},
  dot/.style={shape=circle, fill=black, draw=none, minimum size=+3pt,
              inner sep=+0pt, outer sep=+0pt, node contents=},
  mat/.style={
    every outer matrix/.append style={shape=superellipse, inner ysep=+0pt},
    draw=black, fill=green!10},
  mat line/.style={draw=red},
  snakes/.style={
    decorate, decoration={snake, segment length=#1, amplitude=+1pt}},
  every label/.append style=math node,every edge quotes/.append style=math node,
  dot line/.style={dash pattern=on \pgflinewidth off 1.5\pgflinewidth},
]
\matrix[mat, "SU(2)" right] (upper set) {
  \node (us-q) at (-5mm,0) [dot, l=q];
  \node (us--q) at (5mm,0) [dot, l=-q];
  \draw[mat line, snakes=3.333mm] (us-q) -- (us--q);
\\};
\matrix[mat, "SO(3)" right, below=1.5cm of upper set] (lower set) {
  \node (ls-R) [dot, l'=R];
  \draw[mat line] (ls-R)
    to[bezier bounding box, out=30, in=-30, min distance=10mm] (ls-R);
\\};

\path[dot line, out=90, in=-90] (ls-R) edge (us-q) edge[out=45] (us--q);
\path[|->, shorten=1mm] (upper set) edge["P" name=P] (lower set);

\path[shift=(P), xshift=-5cm, |-|] (0,0) edge["I"' name=I] ++(right:1.5cm);
\path[->, shorten=1mm] (I)
  edge[out=60, in=185, "\tilde f"] (upper set)
  edge[out=45, in=160, "f"]        (lower set);
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

答案2

在你等待 Tikz 帮助时,这里有一个尝试元帖子

在此处输入图片描述

如果您点击上面的链接,您可以阅读有关 MP 的更多信息。

\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
% define the required paths
path base, se, upper_set, lower_set, f, f', p;
base = (left--right) scaled 40 shifted 160 left;
se = superellipse(40 right, 20 up, 40 left, 20 down, .78);
upper_set = se shifted 60 up;
lower_set = se shifted 60 down;

interim bboxmargin := 10;
f = point 3/4 of base shifted 6 up {dir 45} .. {dir -30} center lower_set cutafter bbox lower_set;
f' = point 5/8 of base shifted 6 up {dir 45} .. {dir 0} center upper_set cutafter bbox upper_set;
p = center upper_set .. center lower_set cutbefore bbox upper_set cutafter bbox lower_set;

% fill and draw the main shapes
fill upper_set withcolor 1/16(15, 16, 13);
fill lower_set withcolor 1/16(15, 16, 13);
draw upper_set;
draw lower_set;
draw base; 
draw (up--down) scaled 4 shifted point 0 of base;
draw (up--down) scaled 4 shifted point 1 of base;
drawarrow f;
drawarrow f';
drawarrow p;  
draw (left--right) scaled 4 shifted point 0 of p;

% now decorate the sets
z1 = center lower_set shifted 10 left;
z2 = center lower_set shifted 24 right;
z3 = center upper_set shifted 24 left;
z4 = center upper_set shifted 24 right;

draw z1 {dir -30} .. z2 .. {dir 210} z1 withcolor 3/4 red;
draw z3 {dir 30} .. 1/3[z3,z4] {dir 30} .. 2/3[z3, z4] {dir 30} .. z4 {dir 30} 
    withcolor 3/4 red;

draw z3 {down} .. {down} z1 dashed withdots scaled 1/4;
draw z4 {down} .. 5/8[z4, z2] - (8,6) .. {down} z1 dashed withdots scaled 1/4;

dotlabel.llft("$R$", z1);
dotlabel.top("$q$", z3); 
dotlabel.top("$-q$", z4);

% finally add the remaining labels
label.ulft("$\tilde{f}$", point 1/2 of f');
label.urt("$f$", point 1/2 of f);
label.bot("$I$", point 1/2 of base);
label.rt ("$P$", point 1/2 of p);
label.rt ("$SU(2)$", point 0 of upper_set);
label.rt ("$SO(3)$", point 0 of lower_set);

endfig;
\end{mplibcode}
\end{document}

您需要使用lualatex引擎来编译它。

相关内容