以下代码沿等边三角形的周长放置六个节点:
\begin{tikzpicture}[every node/.style={draw}]
\node (l1) at (0,0) [circle] {};
\node (l2) at (2,0) [circle] {};
\node (l3) at (4,0) [circle] {};
\node (m1) at (1, 1.732) [circle] {};
\node (m2) at (3, 1.732) [circle] {};
\node (h1) at (2, 3.464) [circle] {};
\end{tikzpicture}
我怎样才能以类似于以下的方式用椭圆形围绕三角形的每个“腿”:
答案1
calc
使用该库绘制一些旋转的椭圆的一种可能性:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc,shapes}
\begin{document}
\begin{tikzpicture}[every node/.style={draw}]
\node (l1) at (0,0) [circle] {};
\node (l2) at (2,0) [circle] {};
\node (l3) at (4,0) [circle] {};
\node (m1) at (1, 1.732) [circle] {};
\node (m2) at (3, 1.732) [circle] {};
\node (h1) at (2, 3.464) [circle] {};
\draw let \p1=(h1), \p2=(l1), \n1={atan2(\y2-\y1,\x2-\x1)}, \n2={veclen(\y2-\y1,\x2-\x1)}
in ($ (h1)!0.5!(l1) $) ellipse [x radius=\n2/2+20pt, y radius=0.7cm,rotate=90-\n1];
\draw let \p1=(h1), \p2=(l3), \n1={atan2(\y2-\y1,\x2-\x1)}, \n2={veclen(\y2-\y1,\x2-\x1)}
in ($ (h1)!0.5!(l3) $) ellipse [x radius=\n2/2+20pt, y radius=0.7cm,rotate=90-\n1];
\draw let \p1=(l1), \p2=(l3), \n1={atan2(\y2-\y1,\x2-\x1)}, \n2={veclen(\y2-\y1,\x2-\x1)}
in ($ (l1)!0.5!(l3) $) ellipse [x radius=\n2/2+20pt, y radius=0.7cm,rotate=90-\n1];
\end{tikzpicture}
\end{document}
答案2
根据 Gonzalo 的回答,我给自己写了一个小命令
\newcommand{\fitellipsis}[2] % first and second node names without parentheses
{\draw let \p1=(#1), \p2=(#2), \n1={atan2(\y2-\y1,\x2-\x1)}, \n2={veclen(\y2-\y1,\x2-\x1)}
in ($ (\p1)!0.5!(\p2) $) ellipse [x radius=\n2/2+1cm, y radius=1.5cm, rotate=\n1];
}
这样做确实有效。您可以根据需要调整添加的(cm)单位。
答案3
以下代码使用节点制作的等边三角形regular polygon
。此节点未绘制,但可使用其锚点轻松放置点。椭圆使用节点绘制fit
。由于所有椭圆都相等,因此它们使用相同的点构建,fitting
但根据所需位置放置和旋转。
\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{positioning, fit, shapes.geometric}
\begin{document}
\begin{tikzpicture}[
myellipse/.style={
fit=(a.corner 2) (a.corner 3),
draw, ellipse,
inner xsep=0mm,
inner ysep=3mm}]
\node[regular polygon, regular polygon sides=3, inner sep=1cm] (a) {};
\foreach \i in {1, 2, 3}{
\fill[red] (a.side \i) circle (2pt);
\fill[red] (a.corner \i) circle (2pt);
}
\node[myellipse] {};
\node[myellipse, rotate=120] at (a.side 3) {};
\node[myellipse, rotate=60] at (a.side 1) {};
\end{tikzpicture}
\end{document}