1

Unable to highlight the intersection partof ellipse and line using \clip command, please help on this. here I want to fill the area ABCD, please guide thanks

\documentclass{article}
\usepackage{tikz,pgfplots}
%\usepackage[x11names]{xcolor}
\usepackage{tikz}
\usetikzlibrary{intersections}
\usepackage{pgfplots}\pgfplotsset{compat=newest}
\pgfdeclarelayer{bg}    % declare background
\pgfsetlayers{bg,main}  % order of layers (main = standard layer)
\pgfplotsset{compat=1.13}
\usepackage{amsmath}
\usetikzlibrary{positioning}





\begin{document}

\begin{tikzpicture}
\draw (0,-2)--(0,3); 
\draw (-4,0)--(5,0);
\draw (0,0)node(o){O} (0,1)[left]node(c){C} (0,-1)node(d){D};
\draw(0,0)circle[x radius = 3 cm , y radius = 1 cm]; % DRAW ELLIPSE
\draw (1,-1)[below]node(a){A}--(1,1)[above]node(b){B};
\clip(0,0)circle[x radius = 3 cm , y radius = 1 cm];
\fill[black] (0cm,0cm) rectangle (4cm,6cm);
\draw (0,0)node(o){O} (0,1)[left]node(c){C};

\end{tikzpicture}
\end{document}

1 Answer 1

2

Do you want something like this? The reason why you do not get any visible result is that you fill a rectangle of zero width.

\documentclass{article} 
\usepackage{tikz} 
\begin{document}
\begin{tikzpicture} 
\draw (0,-2)--(0,3); 
\draw (-4,0)--(5,0);
\draw(0,0)circle[x radius = 3 cm , y radius = 1 cm]; % DRAW ELLIPSE 
\draw (1,-1)[below]node(a){A}--(1,1)[above]node(b){B}; 
\clip(0,0)circle[x radius = 3 cm , y radius = 1 cm]; 
\draw[blue,thick] (a) -- (b);
\end{tikzpicture} 
\end{document}

enter image description here

As for your updated question, you define the points a, b, c and d as nodes, which are extended objects. That's why a path connecting these points has gaps, such that fill fails. To avoid this, use coordinate type nodes with labels.

\documentclass{article} 
\usepackage{tikz} 
\pgfdeclarelayer{bg}   
\pgfsetlayers{bg,main}
\begin{document}
\begin{tikzpicture} 
 \draw (0,-2) -- (0,3); 
 \draw (-4,0) -- (5,0);
 \draw (0,0)circle[x radius = 3 cm , y radius = 1 cm]; % DRAW ELLIPSE 
 \draw (1,-1)coordinate[label=below:$A$](a) 
     -- (1,1)coordinate[label=above:$B$](b); 
 \draw (0,0)coordinate[label=below left:$O$](o) 
     (0,1)coordinate[label=left:$C$](c)
     (0,-1)coordinate[label=below:$D$](d);
 \begin{pgfonlayer}{bg} 
  \clip (0,0) circle[x radius = 3 cm , y radius = 1 cm]; 
  \fill[blue] (a) -- (b) -- (c) -- (d) -- cycle;
 \end{pgfonlayer}
\end{tikzpicture} 
\end{document}

enter image description here

3
  • I want to highlight the area ABCD, I have just updated my code...
    – Sachin
    Mar 27, 2020 at 2:34
  • @sultan The problem is that your nodes are extended objects. So you could either draw a path between their centers, or, probably better, use coordinates instead.
    – user194703
    Mar 27, 2020 at 2:48
  • This is really helpful, I am really thankful to you..... God bless you ...
    – Sachin
    Mar 27, 2020 at 4:36

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .