【问题标题】:How to Find Intersections with Ellipses in PGF/TikZ如何在 PGF/TikZ 中找到与椭圆的交点
【发布时间】:2010-05-10 08:47:34
【问题描述】:

我试图在 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. 在那里放一个小圆圈或矩形?

放置一个小圆圈或矩形没有问题。 非常感谢!

【问题讨论】:

    标签: latex intersection ellipse tikz pgf


    【解决方案1】:

    查看第 4.1.4 节。的TikZ and PGF manual,标题为“圆圈的交点”。您需要使用intersections 库,它允许您使用name intersections 密钥,如\path [name intersections={of=path 1 and path 2}] ;。要使用它,您需要使用name path 键,如\draw [name path = y axis, &lt;-&gt;, 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},一切正常。

    【讨论】:

    • 感谢您的详细回答。据我了解,我需要从 CVS 获得最新的开发人员版本,因为“常规”pgf-2.00.tar.gz 中不包含交集。由于我在安装时遇到了一些问题,我会尽快回复。
    • 这(第二个帖子 = 第一个回复)latex-community.org/forum/viewtopic.php?f=45&t=5687 可能对许多其他正在运行的 MikTex 有用。
    • 完美运行!非常感谢!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多