2010-05-10 66 views
3

我想在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. 找到兩個紅色橢圓相交的兩個點(評論道大圓1和2),
  2. 找到一條線(起源於中心(0,0))與一個橢圓的交點,並在那裏放置一個小圓或矩形?

放置一個小圓圈或矩形不存在問題。 非常感謝!

回答

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, <->, 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獲得最新的開發者版本,因爲intersection不包含在「regular」pgf-2.00.tar.gz中。由於我在安裝時遇到了一些問題,因此我會盡快回復。 – user327684 2010-05-10 21:51:30

+0

這個(第二篇文章=第一個回覆)http://www.latex-community.org/forum/viewtopic.php?f=45&t=5687可能對許多其他運行MikTex有用。 – user327684 2010-05-11 07:51:41

+0

完美的作品!非常感謝! – user327684 2010-05-11 07:58:21