我想绘制一个复杂的函数,并尝试了多种方法,但 TikZ 不允许我这样做。我可能做错了什么,而且非常愚蠢。
无论如何,我想在这个椭圆上画“睫毛”。也就是说,我想从椭圆的边界向外(相对于椭圆的中心)画一些小线,如下所示:
更确切地说
如果我的数学正确的话,我们可以使用以下公式来定义这个椭圆
给定椭圆上的一个点 (x,y),我们可以使用以下方式定义一个新点 (x * , y * )
但就我而言,我似乎无法让它工作。我希望睫毛位于点 x 上的 {-1, 0, ..., 5},但最终我想添加尽可能多的睫毛(即我应该能够输入睫毛的数量)。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\title{StackOverflow help example}
\begin{document}
\begin{tikzpicture}
\draw[step=1cm, gray!50!white, very thin] (-2,-2) grid (6,6); % <bottom left> grid <top right>
\draw (2,2) circle (3cm and 1cm); % draw ellipse
% This doesn't work
%\foreach \x in {-1, -0.5, ..., 5}
% \draw[red] ({\x},{2+sqrt(1-(\x-2)^2/9)}) -- ({\x+cos(asin(deg((2+sqrt(1-(\x-2)^2/9)-2)/(\x-2))))},{2+sqrt(1-(\x-2)^2/9)});
\draw[thick,->] (-2,-2) -- (6,-2) node[anchor=west]{x}; % draw x axis. anchor west means that x attaches to the east
\draw[thick,->] (-2,-2) -- (-2,6) node[anchor=south]{y}; % draw y axis. anchor east means that y attached to the west
\foreach \x in {-2, -1, 0, 1, 2, 3, 4, 5, 6}
\draw (\x cm, -2) -- (\x cm, -2.1) node[anchor=north]{$\x$};
\foreach \y in {-2, -1, 0, 1, 2, 3, 4, 5, 6}
\draw (-2, \y cm) -- (-2.1, \y cm) node[anchor=east]{$\y$};
\end{tikzpicture}
\end{document}
答案1
我不认为睫毛指向中心,但它们指向圆圈。
\documentclass{article}
\usepackage{tikz}
\def\mya{6}\def\myb{3}
\begin{document}
An ellipse can be parametrized by
\[ \gamma(t)~=~(a\,\cos t,b\,\sin t)\;.\]
The tangent to this curve is hence
\[ \dot\gamma(t)~=~(-a\,\sin t,b\,\cos t)\;.\]
The normalizaed eylashes, which are orthogonal to the tangent, point hence to
\[ \omega(t)~=~\frac{1}{\sqrt{b^2\,\cos^2 t+a^2\sin^2 t}}(b\,\cos t,a\,\sin t)\;.\]
\begin{center}
\begin{tikzpicture}
\draw (0,0) ellipse ({\mya cm} and {\myb cm});
\foreach \x in {0,10,...,180}
{\pgfmathsetmacro{\myx}{\mya*cos(\x)}
\pgfmathsetmacro{\myy}{\myb*sin(\x)}
\pgfmathsetmacro{\myu}{\myx+0.2*\myb*cos(\x)/(sqrt(pow(\myb,2)*pow(cos(\x),2)+pow(\mya,2)*pow(sin(\x),2)))}
\pgfmathsetmacro{\myv}{\myy+0.2*\mya*sin(\x)/(sqrt(pow(\myb,2)*pow(cos(\x),2)+pow(\mya,2)*pow(sin(\x),2)))}
\draw[blue] (\myx,\myy) -- (\myu,\myv);}
\end{tikzpicture}
\end{center}
\end{document}
您可以通过更改和0.2
的宏来使睫毛更长或更短。\myu
\myv
或者您可以通过在椭圆上找到一个点然后使用圆弧来使用装饰:
\documentclass[tikz]{standalone}
\usetikzlibrary{decorations.pathreplacing}
\begin{document}
\def\mya{6}\def\myb{3}
\begin{tikzpicture}
\draw (0,0) ellipse ({\mya cm} and {\myb cm});
\draw[decoration={ticks,% name of the decoration
raise=5pt,% offset from the original path
amplitude=5pt,% half-length of each tick
segment length=5mm},% distance between consecutive ticks
decorate,red,ultra thick]
({\mya*cos(135)},{\myb*sin(135)}) arc (135:20:\mya{} and \myb);
\end{tikzpicture}
\end{document}
答案2
在 PSTricks 中这是小菜一碟。
\documentclass[pstricks,border=12pt]{standalone}
\usepackage{pstricks-add}
\def\xy{3*cos(t)|2*sin(t)}
\begin{document}
\begin{pspicture}[algebraic](-3,-2)(3,2)
\psparametricplot{0}{TwoPi}{\xy}
\pscurvepoints{0}{TwoPi}{\xy}{P}
\pspolylineticks[Ds=.5,ticksize=-5pt 0]{P}{ ds }{0}{20}
\end{pspicture}
\end{document}