我正在尝试在 tikz 中绘制一个简单的图形,其中包括:
- 椭圆
- 椭圆里面的一些标签
- 曲线附近的另一个标签
- 椭圆的外法向量,同样带有标签
生成椭圆和前两个标签没有问题。但是,我不知道如何将节点放在椭圆的边界上。怎么做?
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\filldraw[fill=black!20!white](0, 0) ellipse (100pt and 50pt);
\end{tikzpicture}
\end{document}
答案1
为了绘制法线矢量,您可以使用如何在 TikZ 中绘制路径上任意点的切线. 它允许您输入
\filldraw[fill=black!20!white, tangent=0.1](0, 0) ellipse (100pt and 50pt);
\draw [blue, ultra thick, use tangent, -latex] (0,0) -- (0,-2) node [pos=0.5, anchor=east] {Normal vector};
要得到:
\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{decorations.markings}
\tikzset{
tangent/.style={
decoration={
markings,% switch on markings
mark=
at position #1
with
{
\coordinate (tangent point-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,0pt);
\coordinate (tangent unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (1,0pt);
\coordinate (tangent orthogonal unit vector-\pgfkeysvalueof{/pgf/decoration/mark info/sequence number}) at (0pt,1);
}
},
postaction=decorate
},
use tangent/.style={
shift=(tangent point-#1),
x=(tangent unit vector-#1),
y=(tangent orthogonal unit vector-#1)
},
use tangent/.default=1
}
\begin{document}
\begin{tikzpicture}
\filldraw[fill=black!20!white, tangent=0.1](0, 0) ellipse (100pt and 50pt);
\draw [blue, ultra thick, use tangent, -latex] (0,0) -- (0,-2) node [pos=0.5, anchor=east] {Normal vector};
\end{tikzpicture}
\end{document}