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 开发者_Go百科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!
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 the name intersections
key, as in \path [name intersections={of=path 1 and path 2}] ;
. To use this, you'll need to use the name 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:
\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}
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.
精彩评论