Forgot password?
 Create new account
View 225|Reply 9

tikz画一个满足条件的椭圆,并取出与圆的交点

[Copy link]

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

abababa Posted at 2023-3-7 15:05:32 |Read mode
已知一个圆上的三点ABC,现在想画一个以A,B为焦点且过点C的椭圆F,并且要定义出F与圆的几个交点,这个有什么好的方法吗?
是因为在GeoGebra里就是这样画椭圆的,然后很容易取得那些交点,但是那个导出的tikz代码觉得太复杂,不清晰,有没有什么明确一点的方法来画这个?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2023-3-7 16:18:59
Asymptote中
画一个以A,B为焦点且过点C的椭圆F
可以使用geometry模块ellipse
geometry.asy Line 2896
  1. ellipse ellipse(point F1, point F2, point M)
  2. {/*<asyxml></code><documentation>Return the ellipse passing through 'M' whose the foci are 'F1' and 'F2'.</documentation></function></asyxml>*/
  3.   real a = abs(F1 - M) + abs(F2 - M);
  4.   return ellipse(F1, F2, finite(a) ? a/2 : a);
  5. }
Copy the Code
定义出F与圆的几个交点

intersectionpoints
pair[] intersectionpoints(path p, path q, real fuzz=-1);

    returns an array containing all intersection points of the paths p and q.

asymptote.sourceforge.io/doc/Paths-and-guides.html

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2023-3-7 20:37:59
hbghlyj 发表于 2023-3-7 16:18
Asymptote中
可以使用geometry模块ellipse
见geometry.asy Line 2896
这个能和tikz在一起混用吗?因为其它的我都画好了,就只需要一个圆锥曲线(椭圆或双曲线)和圆的交点而已。

还有那个pgf的,以前用过一些简单的功能,但画椭圆、双曲线这些,是不是不能直接完成主楼的那个,还得计算一些点才行?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2023-3-8 00:06:01
abababa 发表于 2023-3-7 13:37
就只需要一个圆锥曲线(椭圆或双曲线)和圆的交点而已 ...
tikz.dev/tikz-coordinates#pgf.name:intersections

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2023-3-8 13:18:32
hbghlyj 发表于 2023-3-8 00:06
https://tikz.dev/tikz-coordinates#pgf.name:intersections
你这个pgf画椭圆的参数是中心坐标和长短轴的长度,主楼里的需求是过两个焦点和椭圆上另一点,这几个点也都是其它线相交出来的,坐标都得计算才能知道,我是说如果不计算这些点,能直接按需求画出来吗?比如
\draw [name path=ellipse] (-2,0) (2,0) ellipse (1.75,1.5);
这种,三个参数的,前两个是焦点,另一个是椭圆上一点。

701

Threads

110K

Posts

910K

Credits

Credits
94167
QQ

Show all posts

kuing Posted at 2023-3-8 17:36:46
  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usetikzlibrary{calc,intersections}
  4. \newcommand\ellbyFFP[4]{%ellipse by two F and a P
  5.   \path[#1] let \p1=(#2), \p2=(#3), \p3=(#4)
  6.   in \pgfextra{
  7.     \pgfmathsetmacro{\angle}{atan2(\y2-\y1,\x2-\x1)}
  8.     \pgfmathsetmacro{\c}{veclen(\x2-\x1,\y2-\y1)/2/1cm}
  9.     \pgfmathsetmacro{\a}{veclen(\x3-\x1,\y3-\y1)/2/1cm
  10.                         +veclen(\x3-\x2,\y3-\y2)/2/1cm}
  11.     \pgfmathsetmacro{\b}{sqrt(\a*\a-\c*\c)}
  12.   }
  13.   ($(\p1)!.5!(\p2)$) ellipse[
  14.     x radius=\a cm, y radius=\b cm, rotate=\angle];
  15. }
  16. \begin{document}
  17. \begin{tikzpicture}
  18.   \coordinate (F1) at (0,0);
  19.   \coordinate (F2) at (5,3);
  20.   \coordinate (P) at (4,4);
  21.   \ellbyFFP{draw,name path=ee}{F1}{F2}{P}
  22.   \fill[red] (F1) circle (2pt) node[above]{$F_1$}
  23.     (F2) circle (2pt) node[above]{$F_2$}
  24.     (P) circle (2pt) node[above]{$P$};
  25.   \draw[name path=cc] (2,1) circle (2.5);
  26.   \fill[red,name intersections={of=ee and cc}]
  27.     (intersection-1) circle (2pt) node[above]{1}
  28.     (intersection-2) circle (2pt) node[left]{2}
  29.     (intersection-3) circle (2pt) node[below]{3}
  30.     (intersection-4) circle (2pt) node[right]{4};
  31. \end{tikzpicture}
  32. \end{document}
Copy the Code

效果:
QQ截图20230308173629.png

编译时会停顿半秒左右,看来 intersections 计算交点有一定计算量。
tex 不是专门处理数学计算的,需要复杂计算时,能用别的工具的话还是尽量用别的。

以上方法参考了这帖:tex.stackexchange.com/questions/75017/draw-an … -of-the-distances-fr

418

Threads

1628

Posts

110K

Credits

Credits
11891

Show all posts

 Author| abababa Posted at 2023-3-8 19:17:50
谢谢,确实好用,暂时就这一个地方需要求交点,还没感觉出慢来。

查了pgf的文档,发现有ellipse但没有hyperbola,是不是这个就不能简单地画双曲线?

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2023-3-8 20:25:39
abababa 发表于 2023-3-8 12:17
简单地画双曲线?
geometry.asy第3100行
Return the hyperbola passing through $M$ whose the foci are $F_1$ and $F_2$.
  1. /*<asyxml><function type="hyperbola" signature="hyperbola(point,point,point)"><code></asyxml>*/
  2. hyperbola hyperbola(point F1, point F2, point M)
  3. {/*<asyxml></code><documentation>Return the hyperbola passing through 'M' whose the foci are 'F1' and 'F2'.</documentation></function></asyxml>*/
  4.   real a = abs(abs(F1 - M) - abs(F2 - M));
  5.   return hyperbola(F1, F2, finite(a) ? a/2 : a);
  6. }
Copy the Code

3146

Threads

8493

Posts

610K

Credits

Credits
66158
QQ

Show all posts

hbghlyj Posted at 2023-3-10 21:42:20
abababa 发表于 2023-3-8 12:17
查了pgf的文档,发现有ellipse但没有hyperbola,是不是这个就不能简单地画双曲线?
10年前讨论过 tikz画双曲线

701

Threads

110K

Posts

910K

Credits

Credits
94167
QQ

Show all posts

kuing Posted at 2023-3-10 21:52:36
hbghlyj 发表于 2023-3-10 21:42
10年前讨论过  tikz画双曲线
这个肯定不能满足楼主“简单地画”的要求

手机版Mobile version|Leisure Math Forum

2025-4-20 21:55 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list