如何在PGF/TikZ中找到椭圆的交点

3
我想在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. 找到两个红色椭圆(标记为“大圆1”和“大圆2”)的交点,
  2. 找到一条直线(起点为中心(0,0))与一个椭圆的交点,并且
  3. 在那里放置一个小圆或矩形?

在那里放置一个小圆或矩形不是问题。 非常感谢!

1个回答

1

请查看TikZ and PGF手册的第4.1.4节,标题为“圆的交点”。您需要使用intersections库,它允许您使用name intersections键,例如:\path [name intersections={of=path 1 and path 2}] ;。为了使用它,您需要使用name path键,例如:\draw [name path = y axis, <->, dashed] (0,-5) -- (0,5) ; % y-axis。访问交点似乎因版本而异。我的本地手册与我链接给您的手册有不同的说明。然而,至少在我的版本中,您可以通过(intersection-1)(intersection-2)等来访问交点。为了在您的示例中获得每个交点处的圆形,我建议更改您的代码如下:

\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 [name path = y  axis, <->, dashed] (0,-5) -- (0,5)   ; % y-axis
  \draw [name path = x- axis,  ->, dashed] (0, 0) -- (20:5)  ; % x-axis
  \draw [name path = x+ axis,  ->, dashed] (0, 0) -- (200:5) ; % x-axis
  \draw [name path = z+ axis,  ->, dashed] (0, 0) -- (340:5) ; % z-axis
  \draw [name path = z- axis,  ->, dashed] (0, 0) -- (160:5) ; % z-axis

  % bounding circle
  \fill [color=cyan, opacity=0.15, path fading=fade out]
        (0,0) circle (4cm) ;

  % x-y-axis area
  \fill [color=cyan, opacity=0.25, path fading=fade right, fading angle=90]
        (0,0) ellipse (4cm and 1cm);

  % great circle 1
  \draw [ name path    = great circle 1
        , rotate       = -40
        , color        = red
        , path fading  = fade right gc
        , fading angle = 40]
        (0,0) ellipse (4cm and 1cm);

  % great circle 2
  \draw [ name path    = great circle 2
        , rotate       = 5
        , color        = red
        , path fading  = fade right gc
        , fading angle = 5]
        (0,0) ellipse (1.5cm and 4cm);

  % Intersections
  \path [name intersections={of=great circle 1 and great circle 2}] ;
  \foreach \i in {1,...,4}
    \fill [color=red] (intersection-\i) circle (2pt) ;

  \path [name intersections={of=y axis and great circle 1}] ;
  \fill (intersection-1) circle (2pt) ;
  \fill (intersection-2) circle (2pt) ;
  \path [name intersections={of=y axis and great circle 2}] ;
  \fill (intersection-1) circle (2pt) ;
  \fill (intersection-2) circle (2pt) ;

  \foreach \a in {x,z} {
    \foreach \ss in {+,-} {
      \def\s.{\ss} % Otherwise the space in `\a\s axis` would get gobbled.
      \path [name intersections={of=\a\s. axis and great circle 1}] ;
      \fill (intersection-1) circle (2pt) ;
      \path [name intersections={of=\a\s. axis and great circle 2}] ;
      \fill (intersection-1) circle (2pt) ;
    }
  }
\end{tikzpicture}

除了重新格式化(以避免水平滚动条),我对您现有代码所做的所有更改都是将name path键添加到您的轴和大圆中。然后,我添加了交点代码,这应该相对容易理解。记得首先使用\usetikzlibrary{intersections},然后一切都应该正常工作。


1
感谢您提供详细的答案。据我所知,我需要从CVS获取最新的开发者版本,因为“常规”的pgf-2.00.tar.gz中没有包含交集功能。由于我在安装过程中遇到了一些问题,我会尽快回来解决。 - user327684
这个(第二篇帖子=第一篇回复)http://www.latex-community.org/forum/viewtopic.php?f=45&t=5687 可能对许多其他运行MikTex的人有用。 - user327684

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接