6

How can split circle (tikz shape circle) in two parts. However, I would like the split to be uneven i.e. the top part occupy lets say 30% of the area and lower part the rest 70%.

Thanks

5

If you want to fill a circle segment so the circle segment takes up a specified area of the circle, you'll need to iteratively solve the area equation for the central angle of the segment.

Here's a way to do this using Newton's method:

\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathsetmacro\radius{1}

\tikzset{ % Declare the function and its derivative
    declare function={f(\a) = 1/(2*pi)*(2*\a - sin(2*deg(\a)));},
    declare function={fprime(\a) = 1/(2*pi)*(2 - cos(2*deg(\a)));}
}

\newcommand\newton[4]{ % arguments: function, derivative, start value, precision
\edef\a{#3}%
\pgfmathsetmacro\fold{#1}%
\pgfmathsetmacro\deriv{#2}%
\pgfmathsetmacro\a{\a-(\fold)/(\deriv)}%
\pgfmathsetmacro\residual{abs(#1)}%
\ifdim \residual pt > #4 pt%
    \newton{#1}{#2}{\a}{#4}%
\fi%
\edef\pgfmathresult{\a}%
}



\begin{tikzpicture}
\def\fraction{0.7}
\newton{f(\a)-\fraction}{fprime(\a)}{1}{0.00001}
\pgfmathsetmacro\angle{deg(\pgfmathresult)}

\fill [cyan!50]
    (-\angle-90:\radius)
    arc [
        start angle=-\angle-90,
        end angle=-90+\angle,
        radius=\radius
        ]
    -- (-\angle-90:\radius);
\draw (0,0) circle [radius=\radius] node {\pgfmathprintnumber{\fraction}};
\end{tikzpicture}
\end{document}
  • Wouldn't a path picture with two rectangles be faster for this? – percusse Oct 14 '13 at 8:16
  • @percusse: How would you specify what fraction of the circle is filled? – Jake Oct 14 '13 at 8:36
  • I used the taylor expansion on x-sin(x) to solve a polynomial. But on a second thought I think that would also be a rough approx. – percusse Oct 14 '13 at 9:06
  • Jake, this is simply brilliant. Thanks so much. I wanted to fill the lower part with text. Usually, with regular circle split I would have used keyword lowerpart followed by text. I am quite happy with the current solution. – Sandeep Oct 14 '13 at 14:27
3

Without even a mock-up of what you want it is difficult to understand what it is that you need, or where you are having trouble doing this, but one possibility would be to use polar coordinates, as explained in section 13.2.1 ("Canvas, XYZ and Polar Coordinate Systems") of the manual.

You can then specify coordinates with an angle and the distance instead of x and y magnitudes. This is one possibility:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
  \draw (0,0) circle [radius=1];
  \draw (36:1) -- (0,0) -- (144:1);
\end{tikzpicture}
\end{document}

enter image description here

If this is not what you want, you'll have to be more specific.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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