考虑以下 MEW。我不明白为什么 i2 标签的位置会逐步变化而不是连续变化。使用 178-180,我得到
175-177 得到
第一个太低,第二个又太高……这是我的错误还是系统的缺陷?
\documentclass{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{calc,patterns,angles,quotes,intersections}
\begin{document}
\noindent\hrulefill
\begin{center}
\begin{tikzpicture}[scale=0.5,
dot/.style 2 args={circle,inner sep=1pt,fill,label={#2},name=#1},
dot2/.style 2 args={circle,inner sep=.6pt,draw=black, fill=white,label={#2},name=#1},
dot3/.style 2 args={circle,inner sep=.8pt,draw=black, fill=white,label={#2},name=#1},
extended line/.style={shorten >=-#1,shorten <=-#1},
extended line/.default=1cm]
\draw[help lines,step=1] (-1,-1) grid (10,6);
\draw [->] (-1,0) -- (10,0) node [below left] {$x$};
\draw [->] (0,-1) -- (0,6) node [below left] {$y$};
\node [dot={p1}{[below=1.5mm]$p_1$}] at (3,1) {};
\node [dot={p2}{[above right]$p_2$}] at (8,0) {};
\node [dot={p3}{[above=1mm]$p_3$}] at (3.5,2.5) {};
\node [dot={p4}{[above right]$p_4$}] at (6,3) {};
\coordinate (i1) at (intersection of p1--p2 and p3--p4);
\coordinate (i2) at (intersection of p1--p3 and p2--p4);
\draw [extended line=0.3cm] (p2) -- (i1) ;
\draw [extended line=0.3cm] (p2) -- (i2) ;
\draw [extended line=0.3cm] (p4) -- (i1) ;
\draw [extended line=0.3cm] (p1) -- (i2) ;
\draw [thick] (p1) -- (p2);
\draw [thick] (p2) -- (p4);
\draw [thick] (p3) -- (p4);
\draw [thick] (p3) -- (p1);
\draw [very thick,extended line=0.3cm] (i1) -- (i2) ;
\coordinate (i3) at (intersection of p2--p3 and i1--i2);
\coordinate (o) at (intersection of p2--p3 and p1--p4);
\coordinate (i4) at (intersection of i1--o and p2--p4);
\coordinate (i5) at (intersection of i2--o and p1--p2);
\coordinate (i6) at (intersection of i1--o and p1--p3);
\coordinate (i7) at (intersection of i2--o and p3--p4);
\draw [very thin,extended line=0.3cm] (p1) -- (p4) ;
\draw [very thin,extended line=0.3cm] (p2) -- (i3) ;
\draw [very thin,extended line=0.3cm] (i1) -- (i4) ;
\draw [very thin,extended line=0.3cm] (i2) -- (i5) ;
\node[dot2,label={}] at (o) {};
\node[dot2,label={}] at (i4) {};
\node[dot2,label={}] at (i5) {};
\node[dot2,label={}] at (i6) {};
\node[dot2,label={}] at (i7) {};
\node[dot3,label={[above]$i_1$}] at (i1) {};
\node[dot3,label={[label distance=0mm]176.0:$i_2$}] at (i2) {}; % <<<=====
\end{tikzpicture}
\end{center}
\noindent\hrulefill
\end{document}
答案1
您所遇到的行为已在TikZ & PGF 手册,具体见 3.1.4b 版第 247 页。相关引述:
- 〈angle〉 用于确定主节点边界上的位置。(...)
- 然后,计算标签节点的锚点。锚点的确定方式是使 将
label node
“背对” 的边界main node
。(...)对于这些“主”角之间的角度,比如 30° 或 110°,使用组合锚点,比如south west
30° 或south east
110° 。但是,对于接近主角的角度(与主角最多相差 2°),将使用主角的锚点。因此,2° 边界点的标签将具有锚点west
,而 3° 的标签将具有锚点,从而导致锚点“跳跃”。您可以使用键或间接键(比如 )south west
“手动”设置锚点。anchor
left
因此,为了实现精确定位,可以使用评论中给出的建议(如\path (i2) ++(160:1.5em) node{$i_2$} ;
),也可以使用选项应用最后一句引用的内容anchor
,如下所示
\node[label={[label distance=0mm, anchor=0] 180:$i_2$}] at (i2) {};
或者
\node[label={[label distance=0mm, anchor=357] 177:$i_2$}] at (i2) {};
这里,177
对应于手册中上述引述的 〈angle〉 ,并且相对于 创建的空节点\node (...) at (i2) {};
(默认值为above
,即90
),而 则anchor=357
与 选项创建的节点有关label
。我让它们之间保持 180° 的差异,以便它们彼此面对。以下是输出:
\node[label={[label distance=0mm, anchor=345] 165:$i_2$}] at (i2) {};
为了更好地理解定位,我建议尝试这样的事情:
\node[name=aaa, draw,
label={[draw, label distance=0mm, anchor=345] 165:$i_2$}]
at (i2) {};
\fill[red] (aaa.165) circle (1pt);
这样,将角度映射到$i_2$
标签的函数是连续的(模数浮点表示的有限精度),但正如评论中所提到的,可以通过使用circle
两个节点的形状使函数更加规则:
\node[name=aaa, circle, draw,
label={[circle, draw, label distance=0mm, anchor=345] 165:$i_2$}]
at (i2) {};
\fill[red] (aaa.165) circle (1pt);
注意: 的label distance
方向由主节点选项中的 〈angle〉 决定,而不是选项anchor
中指示的方向label
。出于某种我不知道的原因,似乎两个感兴趣的锚点之间的距离是双倍的用以下选项表示的label distance
:
\node[name=aaa, circle, draw,
label={[name=bbb, circle, draw, label distance=8mm, anchor=310] 270:$i_2$}]
at (i2) {};
\fill[red] (aaa.270) circle (1pt);
\fill[blue] (bbb.310) circle (1pt);
\draw[orange!35, <->] (aaa.270) -- node[right] {$d$} +(0,-16mm);
答案2
评论太长了。
更高版本可以看到连续变化label distance
。
\documentclass{article}
\usepackage{tkz-euclide}
\usetkzobj{all}
\usetikzlibrary{calc,patterns,angles,quotes,intersections}
\begin{document}
\begin{tikzpicture}[
dot3/.style 2 args={circle,inner sep=.8pt,fill=black,label={#2},name=#1},]
\coordinate (i2) at (0,0);
\draw[thin,gray] (i2) -- ++(178:105mm);
\draw[thin,gray] (i2) -- ++(179:105mm);
\draw[thin,gray] (i2) -- ++(180:105mm);
\node[dot3,label={[label distance=0mm]178.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=0mm]179.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=0mm]180.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=50mm,blue]178.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=50mm,blue]179.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=50mm,blue]180.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=100mm,red]178.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=100mm,red]179.0:$i_2$}] at (i2) {}; % <<<=====
\node[dot3,label={[label distance=100mm,red]180.0:$i_2$}] at (i2) {}; % <<<=====
\end{tikzpicture}
\end{document}