Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have re-written some code I wrote 3 months ago from here Filling between an ellipse and a line

However, I cant fill in the smaller triangle no matter what I try.

What I have tried so far is:

\begin{scope}                                                                  
 \clip (S) -- (F) -- (V) -- (S);                                              
 \filldraw[bottom color = cyan!50!blue, top color = green!20]                 
 (S) -- (F) -- (V) -- (S);                                                    
\end{scope} 

and

\begin{scope}                                                                  
  \clip (S) -- (F) -- (V) -- cycle;                                              
  \filldraw[bottom color = cyan!50!blue, top color = green!20]                 
  (S) -- (F) -- (V) -- (S);                                                    
\end{scope} 

and

\begin{scope}                                                                  
      \clip (S) -- (F) -- (V) -- cycle;                                              
      \filldraw[bottom color = cyan!50!blue, top color = green!20]                 
      (S) rectangle (V) -- (S);                                                    
    \end{scope} 

I have tried more but I am not going to list them all. The new code is:

\documentclass{article}
  \usepackage{tikz}
  \usetikzlibrary{cal, intersections, arrows}
  \begin{document}
  \begin{tikzpicture}[
    every label/.append style = {font = \small},
    dot/.style = {outer sep = +0pt, inner sep = +0pt, shape = circle,
      draw = black, label = {#1}},
    small dot/.style = {minimum size = .05cm, dot = {#1}},
    big dot/.style = {minimum size = .1cm, dot = {#1}},
    extended line/.style = {shorten >=-#1, shorten <=-#1},
    extended line/.default = 1cm,
    one end extended/.style = {shorten >=-#1},
    one end extended/.default = 1.25cm, line cap = round, line join = round,
    >=triangle 45]
    \pgfmathsetmacro{\a}{3}
    \pgfmathsetmacro{\b}{2.5}
    \pgfmathsetmacro{\c}{sqrt(\a^2 - \b^2)}

    \node[fill = black, big dot = {below left: \(A\)}] (A) at (-3, 0) {};
    \node[fill = black, big dot = {below right: \(P\)}] (P) at (3, 0) {};
    \node[fill = black, big dot = {below left: \(D\)}] (D) at (0, -2.5) {};
    \node[fill = black, big dot = {above left: \(B\)}] (B) at (0, 2.5) {};
    \node[fill = black, big dot = {below left: \(F\)}] (F) at (\c, 0) {};
    \node[fill = black, big dot = {below left: \(O\)}] (O) at (0,0) {};

    \draw (0, -3.25) -- (0, 3.25) node[scale = .75, fill = white,
    inner sep = 0cm, pos = .7] {\(b\)};
    \draw[name path = xline] (-3.25, 0) -- (5, 0) node[scale = .8, fill = white,
    inner sep = 0cm, pos = .2] {\(a\)};
    \draw[red, name path = circle] (O) circle (3cm);
    \draw[blue, name path = ellipse] (O) ellipse (3cm and 2.5cm);
    \path[name path = line] (2.25, 3) -- (2.25, -1);

    \path[name intersections = {of = circle and line, by = P1}];
    \node[fill = black, big dot = {above: \(Q\)}] (Q) at (P1) {};
    \path[name intersections = {of = line and xline, by = P2}];

    \draw[black] (Q) -- (P2) node[fill = black, big dot = {below right: \(V\)}]
    (V) at (P2) {};
    \path[name intersections = {of = line and ellipse, by = P3}];
    \node[fill = black, big dot = {right: \(S\)}] (S) at (P3) {};

    \draw (O) -- (Q) node[scale = .75, pos = .5, fill = white, inner sep = 0cm]
    {\(a\)};
    \draw[one end extended] (F) -- (S) node[scale = .8, pos = .5,
    fill = white, inner sep = 0.03cm] {\(r\)};

    \begin{scope}
      \clip (S) rectangle (P);
      \shadedraw[blue, outer color = blue!30!black, inner color = red!30]
      (O) ellipse (3cm and 2.5cm);
    \end{scope}
  \end{tikzpicture}
  \end{document}

enter image description here

So no matter what I do, I cant fill in (S) -- (F) -- (V) -- cycle

share|improve this question
    
@Qrrbrbirlbel what is .center do that corrects the problem. –  dustin Jun 28 '13 at 22:43
    
The .center part chooses the center anchor of the node, thus a coordinate and not a node. See my answer. –  Qrrbrbirlbel Jun 28 '13 at 22:54

1 Answer 1

up vote 3 down vote accepted

The problem is that S, F and V are nodes and not coordinates.

You see, when you connect nodes with -- (or any other path operator) TikZ takes care that you only connect their border.

If you do

\draw[green,thick] (S) -- (F) -- (V) -- cycle;

you will get

enter image description here

TikZ will carefully connect the nodes. But this doesn’t create one closed area (the -- cycle operator also doesn’t seem to have any effect, because the last stored move-to point will be V after the line from F to V has been drawn.) This is usually what you want (for drawing lines between nodes).

In your case though, you want to create an enclosed area. I am assuming you want to use the center anchor of the nodes because … well that’s probably the only sane solution.

I also advice to use the backgrounds library and the on backgrounds layer style to make sure that the area (both actually) will be drawn under the lines and nodes.

Code

\documentclass[tikz,convert=false]{standalone}
\usetikzlibrary{intersections, arrows, backgrounds}
\begin{document}
\begin{tikzpicture}[
    every label/.append style = {font = \small},
    dot/.style = {inner sep = +0pt, shape = circle,
      draw = black, label = {#1}},
    small dot/.style = {minimum size = .05cm, dot = {#1}},
    big dot/.style = {minimum size = .1cm, dot = {#1}},
    extended line/.style = {shorten >=-#1, shorten <=-#1},
    extended line/.default = 1cm,
    one end extended/.style = {shorten >=-#1},
    one end extended/.default = 1.25cm, line cap = round, line join = round,
    >=triangle 45]
    \pgfmathsetmacro{\a}{3}
    \pgfmathsetmacro{\b}{2.5}
    \pgfmathsetmacro{\c}{sqrt(\a^2 - \b^2)}

    \node[fill = black, big dot = {below left: \(A\)}] (A) at (-3, 0) {};
    \node[fill = black, big dot = {below right: \(P\)}] (P) at (3, 0) {};
    \node[fill = black, big dot = {below left: \(D\)}] (D) at (0, -2.5) {};
    \node[fill = black, big dot = {above left: \(B\)}] (B) at (0, 2.5) {};
    \node[fill = black, big dot = {below left: \(F\)}] (F) at (\c, 0) {};
    \node[fill = black, big dot = {below left: \(O\)}] (O) at (0,0) {};

    \draw (0, -3.25) -- (0, 3.25) node[scale = .75, fill = white,
    inner sep = 0cm, pos = .7] {\(b\)};
    \draw[name path = xline] (-3.25, 0) -- (5, 0) node[scale = .8, fill = white,
    inner sep = 0cm, pos = .2] {\(a\)};
    \draw[red, name path = circle] (O) circle (3cm);
    \draw[blue, name path = ellipse] (O) ellipse (3cm and 2.5cm);
    \path[name path = line] (2.25, 3) -- (2.25, -1);

    \path[name intersections = {of = circle and line, by = P1}];
    \node[fill = black, big dot = {above: \(Q\)}] (Q) at (P1) {};
    \path[name intersections = {of = line and xline, by = P2}];

    \draw[black] (Q) -- (P2) node[fill = black, big dot = {below right: \(V\)}]
    (V) at (P2) {};
    \path[name intersections = {of = line and ellipse, by = P3}];
    \node[fill = black, big dot = {right: \(S\)}] (S) at (P3) {};

    \draw (O) -- (Q) node[scale = .75, pos = .5, fill = white, inner sep = 0cm]
    {\(a\)};
    \draw[one end extended] (F) -- (S) node[scale = .8, pos = .5,
    fill = white, inner sep = 0.03cm] {\(r\)};

    \begin{scope}[on background layer]
      \begin{scope}
        \clip (S) rectangle (P);
        \shadedraw[blue, outer color = blue!30!black, inner color = red!30] (O) ellipse (3cm and 2.5cm);
      \end{scope}
      \filldraw[bottom color = cyan!50!blue, top color = green!20] (S.center) -- (F.center) -- (V.center) -- cycle;
    \end{scope}
\end{tikzpicture}
\end{document}

Output

enter image description here

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.