我想从焦点到椭圆上的任意点绘制 2 个矢量(不一定是任意的,但如果我能知道如何做到这一点,我就可以随后选择我的位置)。
实心圆是焦点,另一个是空心焦点,我没有考虑。
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate around = {-20:(0, 0)}]
\pgfmathsetmacro{\a}{2}
\pgfmathsetmacro{\b}{1.5}
\pgfmathsetmacro{\c}{sqrt(\a^2 - \b^2)}
\draw (-3, 0) -- (3, 0);
\filldraw[white] (-\c, 0) circle (.05cm); %empty focus
\draw (-\c, 0) circle (.05cm); %empty focus
\filldraw[black] (\c, 0) circle (.05cm); %focus
\draw plot[domain = -99:99] ({\a * cos(\x)}, {\b * sin(\x)});
\draw plot[domain = -99:99] ({-\a * cos(\x)}, {\b * sin(\x)});
\end{scope}
\end{tikzpicture}
\end{document}
答案1
ellipse
我会使用命令而不是语法来绘制椭圆plot
:这样编译起来更快,而且更容易阅读。要从焦点到椭圆上的某个点绘制一条线,可以使用语法(<angle>:<x radius> and <y radius>)
。
请注意,对于空圆圈,您可以使用单个命令,并为和\filldraw
分别指定颜色。fill
draw
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\begin{scope}[rotate around = {-20:(0, 0)}]
\pgfmathsetmacro{\a}{2}
\pgfmathsetmacro{\b}{1.5}
\pgfmathsetmacro{\c}{sqrt(\a^2 - \b^2)}
\draw (-3, 0) -- (3, 0);
\filldraw[draw=black, fill=white] (-\c, 0) circle (.05cm); %empty focus
\filldraw[black] (\c, 0) circle (.05cm); %focus
\draw (0,0) ellipse [x radius=\a, y radius=\b];
\draw [-latex] (\c,0) -- (30:{\a} and {\b});
\draw [-latex] (\c,0) -- (130:{\a} and {\b});
\end{scope}
\end{tikzpicture}
\end{document}
答案2
您可以使用该intersections
库:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections}
\begin{document}
\begin{tikzpicture}[>=latex]
\begin{scope}[rotate around = {-20:(0, 0)}]
\pgfmathsetmacro{\a}{2}
\pgfmathsetmacro{\b}{1.5}
\pgfmathsetmacro{\c}{sqrt(\a^2 - \b^2)}
\draw (-3, 0) -- (3, 0);
\filldraw[white] (-\c, 0) circle (.05cm); %empty focus
\draw (-\c, 0) circle (.05cm); %empty focus
\filldraw[black] (\c, 0) circle (.05cm); %focus
\draw[name path=ell1] plot[domain = -99:99] ({\a * cos(\x)}, {\b * sin(\x)});
\draw[name path=ell2] plot[domain = -99:99] ({-\a * cos(\x)}, {\b * sin(\x)});
\path[name path=line1] (\c, 0) -- (30:4cm);
\path[name path=line2] (\c, 0) -- (150:4cm);
\draw[->,name intersections={of=line1 and ell1,by={a}}] (\c,0) -- (a);
\draw[->,name intersections={of=line2 and ell2,by={b}}] (\c,0) -- (b);
\end{scope}
\end{tikzpicture}
\end{document}