如何在 PGF/TikZ 中查找与椭圆的交点
我试图在 PGF/TikZ 中显示一个球体来说明大圆的概念。
我当前结果的代码是:
\begin{tikzpicture}
\tikzfading[name=fade right,
left color=transparent!20,
right color=transparent!90]
\tikzfading[name=fade out,
inner color=transparent!100,
outer color=transparent!10]
\tikzfading[name=fade right gc,
left color=transparent!0,
right color=transparent!70]
\draw [<->, dashed] (0,-5) -- (0,5); % y-axis
\draw [->, dashed] (0, 0) -- (20:5); % x-axis
\draw [->, dashed] (0, 0) -- (200:5); % x-axis
\draw [->, dashed] (0, 0) -- (340:5); % z-axis
\draw [->, dashed] (0, 0) -- (160:5); % z-axis
\fill [color=cyan, opacity=0.15, path fading=fade out] (0,0) circle (4cm); % bounding circle
\fill [color=cyan, opacity=0.25, path fading=fade right, fading angle=90] (0,0) ellipse (4cm and 1cm); % x-y-axis area
% great circle 1
\draw [rotate=-40, color=red, path fading=fade right gc, fading angle=40] (0,0) ellipse (4cm and 1cm);
% great circle 2
\draw[rotate=5, color=red, path fading=fade right gc, fading angle=5] (0,0) ellipse (1.5cm and 4cm);
\end{tikzpicture}
如何
- 找到两个红色椭圆(注释为大圆1和2)的两个交点,
- 找到一条线的交点(始于中心(0,0) )和一个椭圆,并
- 在那里放置一个小圆形或矩形?
放置一个小圆圈或矩形没有问题。 非常感谢!
I am trying to display a sphere in PGF/TikZ to illustrate the idea of great circles.
The code for my current result is:
\begin{tikzpicture}
\tikzfading[name=fade right,
left color=transparent!20,
right color=transparent!90]
\tikzfading[name=fade out,
inner color=transparent!100,
outer color=transparent!10]
\tikzfading[name=fade right gc,
left color=transparent!0,
right color=transparent!70]
\draw [<->, dashed] (0,-5) -- (0,5); % y-axis
\draw [->, dashed] (0, 0) -- (20:5); % x-axis
\draw [->, dashed] (0, 0) -- (200:5); % x-axis
\draw [->, dashed] (0, 0) -- (340:5); % z-axis
\draw [->, dashed] (0, 0) -- (160:5); % z-axis
\fill [color=cyan, opacity=0.15, path fading=fade out] (0,0) circle (4cm); % bounding circle
\fill [color=cyan, opacity=0.25, path fading=fade right, fading angle=90] (0,0) ellipse (4cm and 1cm); % x-y-axis area
% great circle 1
\draw [rotate=-40, color=red, path fading=fade right gc, fading angle=40] (0,0) ellipse (4cm and 1cm);
% great circle 2
\draw[rotate=5, color=red, path fading=fade right gc, fading angle=5] (0,0) ellipse (1.5cm and 4cm);
\end{tikzpicture}
How do I
- find the two points of intersection of the two red ellipses (commented as great circle 1 and 2),
- find the point of intersection of a line (originating at the center (0,0)) with a ellipse, and
- place a little circle or rectangle there?
Placing a little circle or rectangle there is not an issue.
Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看第 4.1.4 节。 TikZ 和 PGF 手册,标题为“圆的交点”。您需要使用
intersections
库,它允许您使用name junctions
键,如\path [name junctions={of=path 1 和 path 2}];
。要使用此功能,您需要使用name path
键,如\draw [name path = y axis, <->, dashed] (0,-5) -- (0,5) ; % y 轴
。不同版本的交叉路口访问方式似乎有所不同;我本地的手册副本与我链接到的手册的说明不同。但是,至少在我的版本中,您可以使用(intersection-1)
、(intersection-2)
等访问交叉点。要在每个交叉点处获取圆圈,例如,那么,我会将您的代码更改为如下所示:除了重新格式化(以避免水平滚动条)之外,我对现有代码所做的所有更改都是添加
name path
键到你的轴和大圆。然后我添加了交叉点代码,这应该是相对不言自明的。请记住首先使用\usetikzlibrary{intersections}
,一切都应该正常。Check out section 4.1.4. of the TikZ and PGF manual, titled "The Intersection of the Circles." You need to use the
intersections
library, which allows you to use thename intersections
key, as in\path [name intersections={of=path 1 and path 2}] ;
. To use this, you'll need to use thename path
key, as in\draw [name path = y axis, <->, dashed] (0,-5) -- (0,5) ; % y-axis
. Accessing the intersections seems to vary between versions; my local copy of the manual has different instructions from the one I linked you to. However, at least on my version, you then access the intersections with(intersection-1)
,(intersection-2)
, etc. To get circles at each intersection in your example, then, I would change your code to look like the following:Other than the reformatting (to avoid the horizontal scroll bar), all I have changed of your existing code is to add the
name path
key to your axes and great circles. I then added the intersections code, which should be relatively self-explanatory. Remember to\usetikzlibrary{intersections}
first, and everything should work.