|
- \documentclass{article}
- \usepackage{tikz}
- \usetikzlibrary{calc,intersections}
- \newcommand\ellbyFFP[4]{%ellipse by two F and a P
- \path[#1] let \p1=(#2), \p2=(#3), \p3=(#4)
- in \pgfextra{
- \pgfmathsetmacro{\angle}{atan2(\y2-\y1,\x2-\x1)}
- \pgfmathsetmacro{\c}{veclen(\x2-\x1,\y2-\y1)/2/1cm}
- \pgfmathsetmacro{\a}{veclen(\x3-\x1,\y3-\y1)/2/1cm
- +veclen(\x3-\x2,\y3-\y2)/2/1cm}
- \pgfmathsetmacro{\b}{sqrt(\a*\a-\c*\c)}
- }
- ($(\p1)!.5!(\p2)$) ellipse[
- x radius=\a cm, y radius=\b cm, rotate=\angle];
- }
- \begin{document}
- \begin{tikzpicture}
- \coordinate (F1) at (0,0);
- \coordinate (F2) at (5,3);
- \coordinate (P) at (4,4);
- \ellbyFFP{draw,name path=ee}{F1}{F2}{P}
- \fill[red] (F1) circle (2pt) node[above]{$F_1$}
- (F2) circle (2pt) node[above]{$F_2$}
- (P) circle (2pt) node[above]{$P$};
- \draw[name path=cc] (2,1) circle (2.5);
- \fill[red,name intersections={of=ee and cc}]
- (intersection-1) circle (2pt) node[above]{1}
- (intersection-2) circle (2pt) node[left]{2}
- (intersection-3) circle (2pt) node[below]{3}
- (intersection-4) circle (2pt) node[right]{4};
- \end{tikzpicture}
- \end{document}
复制代码
效果:
编译时会停顿半秒左右,看来 intersections 计算交点有一定计算量。
tex 不是专门处理数学计算的,需要复杂计算时,能用别的工具的话还是尽量用别的。
以上方法参考了这帖:tex.stackexchange.com/questions/75017/draw-an-ellipse-from-the-t ... -of-the-distances-fr |
|