我试图在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)处)与一个椭圆的交点,然后
  • 在那里放置一个圆形或矩形吗?

  • 放置一些圆形或矩形没有问题。
    非常感谢你!

    最佳答案

    请参阅第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, <->, 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},一切都应该正常工作。

    关于latex - 如何在PGF/TikZ中找到带有椭圆的交点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2801370/

    10-13 02:58