TransWikia.com

Fill the section of an ellipse with TikZ

TeX - LaTeX Asked by Mario Vago Marzal on July 6, 2021

I’m learning TikZ and I would like to learn how to fill a ellipse section determined by the center and two points on the curve wich coordinates are, obviously, known. I mean something like this:

pretended result

Thank you in advance!

2 Answers

A solution with clipping around the ellipse.

Fill ellipse sector

documentclass[tikz,border=3.14mm]{standalone}
begin{document}
    begin{tikzpicture}
        defa{-20} defb{115} % Angles for the filling
        defr{4} defR{3}     % Radii of the ellipse
        defell{(0,0) ellipse (r cm and R cm)}
        begin{scope}
            clip ell;
            filldraw[red,draw=black,thick] (0,0) -- (a:2*r cm) |- (b:2*r cm)-- cycle;  
        end{scope}             
        draw[thick] ell;
    end{tikzpicture}
end{document}

Answered by SebGlav on July 6, 2021

A simple approach using polar coordinates that does not require clipping:

documentclass[tikz,border=1mm]{standalone}
begin{document}
    begin{tikzpicture}[thick]
        draw (0:0) ellipse (4 and 3);
        draw[fill=red] (0:0) -- (-20:4 and 3) arc (-20:115:4 and 3) -- cycle;
    end{tikzpicture}
end{document}

enter image description here

Polar coordinates in TikZ are defines as (t:r) where t is the angular coordinate and r the radial coordinate (that is the distance from the center). The radius of the ellipse (which is equal to that of the arc part of the sector) is 4 and 3 which means that the larger radius is 4cm and the smaller radius is 3cm. This radius is also used as radial coordinate for the starting point of the arc of the sector.

Answered by Jasper Habicht on July 6, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP