19

I wonder, can anyone draw a picture like this?

Water lily

I tried, but I'm at the very beginning... There should be four semicircles and one full circle. I've managed to draw only two of them so far. Here's my code:

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{shapes,backgrounds}
\newcommand\radius{3}
\newcommand\y{\sqrt{3*\radius^2 /4}}

\begin{document}
\pagestyle{empty}
\def\firstcircle{(0,0) circle (\radius)}
\def\secondcircle{(3,0) circle (\radius)}
\def\thirdcircle{({\radius , \y}) circle (\radius)}
%\def\fourthcircle{(3,0) circle (3cm)}
%\def\fifthcircle{(3,0) circle (3cm)}
\begin{tikzpicture}
    \draw \firstcircle;
    \draw \secondcircle;
%    \draw \thirdcircle;

\end{tikzpicture}
\end{document}

Why wouldn't the third circle draw?

  • 1
    If it has five 'petals', then those are not semi-circles; they are five arcs with a different radius than that of the outer circle, and a center that does not lie on the outer circle. Maybe that's why it wasn't working for you. First you need to get the geometry of the construction straight. – Federico Poloni Dec 6 '20 at 10:42
14

Are you looking for this 5-petal "water-lily" ?

enter image description here

% a 5-petal rose (or "water-lily" if you like ^^)
\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\R{3}   
\draw (0,0) circle(\R); 
\draw[smooth,magenta] plot[domain=0:36*5,samples=200] (\x:{\R*cos(5*\x)});
\end{tikzpicture}
\end{document}

I update the Asymptote version of @Jairo

enter image description here

//http://asymptote.ualberta.ca/
unitsize(3cm);
draw(unitcircle);
path petal=(1,0) .. (0,0) .. dir(144);
for(int i=1; i<=5; ++i) {draw(rotate(72*i+30)*petal,red);}
17

You can use \clip to cut away the outside parts, and use polar coordinates.

\documentclass[tikz,border=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[declare function={R=3;alpha=-20;},thick]
 \draw circle[radius=R]; 
 \clip circle[radius=R]; 
 \draw foreach \X in {0,...,6}
 {(alpha+60*\X:R) circle[radius=R]};
\end{tikzpicture}
\end{document}

enter image description here

  • 2
    your water-lily has 6 petals ^^ I think there is no 5 petals one as OP described above (5 circular arcs and 1 full circle) – Black Mild Dec 4 '20 at 18:26
  • 1
    @BlackMild Buy five, get one free. 😃 (One can easily generalize this to an arbitrary number of petals.) – user229669 Dec 4 '20 at 18:27
  • I am lazy to do some maths (non-existence ^^) \documentclass[tikz,border=3mm]{standalone} \begin{document} \begin{tikzpicture}[declare function={R=3;alpha=-20;},thick] \draw[clip] circle(R); \def\n{5} \draw foreach[parse=true] \i in {1,...,\n} {(alpha+360*\i/\n:R) circle(R)}; \end{tikzpicture} \end{document} – Black Mild Dec 4 '20 at 18:33
  • @BlackMild Obviously this does not work. You can't just place the centers on the boundary of the clipped circle and leave the radii at R. – user229669 Dec 4 '20 at 18:39
  • sorry for wrong guess! It does exist 5 petal water-lily as described in the question – Black Mild Dec 4 '20 at 19:52
13

Using LuaTeX, it is easy to generate some more generic results.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usepackage{luacode}

\begin{document}

\tikzset{
  arcstyle/.style={
    thick
  }
}

\begin{luacode*}
one_degree = math.pi / 180

function get_inscribed_point(radius, n_poly, index, rotation)
  local ang = (360.0 / n_poly * index + rotation) * one_degree
  local x = radius * math.cos(ang)
  local y = radius * math.sin(ang)
  return {x,y}
end


function get_arc_info(p1, p2, p3)
  local xa, ya = table.unpack(p1)
  local xb, yb = table.unpack(p2)
  local xc, yc = table.unpack(p3)
  
  local coef1 = xb*xb - xc*xc + yb*yb - yc*yc
  local coef2 = xa*xa - xb*xb + ya*ya - yb*yb
  local coef3 = 2.0 * ((xa-xb)*(yb-yc)-(xb-xc)*(ya-yb))
  
  -- calculate center
  local center_x = (-(ya-yb)*coef1+(yb-yc)*coef2)/coef3
  local center_y = ((xa-xb)*coef1-(xb-xc)*coef2)/coef3
  
  -- calculate radius
  local radius = math.sqrt(math.pow(xa-center_x, 2)+math.pow(ya-center_y, 2))
  
  -- calculate arc angle range
  local arc_ang1 = math.asin((0.5*math.sqrt(math.pow(xb-xa,2)+math.pow(yb-ya,2))/radius))
  local arc_ang2 = math.asin((0.5*math.sqrt(math.pow(xc-xb,2)+math.pow(yc-yb,2))/radius))
  local arc_angle = (arc_ang1 + arc_ang2) * 2.0
  
  -- find out if (xc,yc) or (xa,ya) has the smallest angle
  -- make sure xc has the smallest angle (if not, swap two points)
  local ang_a = math.atan2(ya-center_y,xa-center_x)
  local ang_c = math.atan2(yc-center_y,xc-center_x)
  if ang_a < ang_c then
    ang_a = ang_a + 2 * math.pi
  end
  
  -- determine start angle
  local start_angle =ang_c
  local end_angle = ang_a
  
  -- return results
  return {
    ["center_x"] = center_x,
    ["center_y"] = center_y,
    ["radius"] = radius,
    ["start_angle"] = start_angle / one_degree,
    ["end_angle"] = end_angle / one_degree,
    ["arc_start_x"] = xc,
    ["arc_start_y"] = yc
  }
end

function draw_arc(p1, p2, p3)
    local arc = get_arc_info(p1, p2, p3)
      
    tex.print(string.format([[\draw[arcstyle] (%f cm, %f cm) arc (%f:%f:%f cm);]],
      arc["arc_start_x"],
      arc["arc_start_y"],
      arc["start_angle"],
      arc["end_angle"],
      arc["radius"]))
end

function draw_lily(radius, n_poly, offset, rotation)
  for i=1,n_poly do
    local ind1 = i - 1
    local ind2 = (i+offset - 1)%n_poly
    local p1 = get_inscribed_point(radius, n_poly, ind1, rotation)
    local p2 = {0.0,0.0}
    local p3 = get_inscribed_point(radius, n_poly, ind2, rotation)
    draw_arc(p1, p2, p3)
  end
end

\end{luacode*}


\begin{tikzpicture}
\draw (0,0) circle (2cm);
\directlua{
  draw_lily(2.0, 6, 2, 0.0)
}
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\directlua{
  draw_lily(2.0, 6, 2, 15.0)
}
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\directlua{
  draw_lily(2.0, 8, 2, 15.0)
}
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\directlua{
  draw_lily(2.0, 12, 2, 15.0)
}
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\directlua{
  draw_lily(2.0, 12, 3, 15.0)
}
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\directlua{
  draw_lily(2.0, 12, 4, 15.0)
}
\end{tikzpicture}
\begin{tikzpicture}
\draw (0,0) circle (2cm);
\directlua{
  draw_lily(2.0, 36, 2, 15.0)
}
\end{tikzpicture}

\end{document}
  • Just out of curiosity, wouldn't it be easier to invoke embedded Metapost library instead of using TikZ/PGF? Other than that, nice code. – Jairo A. del Rio Dec 5 '20 at 0:09
  • 1
    Thanks! Honestly, I have never used Metapost. It would be really interesting to look into it. Coding something like this is fun, brings me back some of the computer graphics homework that I did a while ago – Alan Xiang Dec 5 '20 at 0:12
  • 1
    As LuaTeX provides both Lua and Metapost, they are nice to use together, especially when speed is of concern (adityam.github.io/context-blog/post/metapost-vs-tikz-speed). However, TikZ seems to be better suited to LaTeX. – Jairo A. del Rio Dec 5 '20 at 0:22
12

Another pstricks solution, with pst-eucl, which has commands to draw regular polygons and the circumscribed circle of a triangle:

\documentclass[svgnames]{standalone}
\usepackage{pst-eucl}

\begin{document}

\begin{pspicture}(-2.2,-2.2)(1.6,2.2)
\SpecialCoor
\psset{PointSymbol=none, PointName=none}
\pstGeonode(0,0){O}(2;40){A}
\pstRegularPolygonOA{O}{A}{5}{B, C, D, E}
\psclip{\pscircle[linecolor=PaleVioletRed](O){2}}%
\foreach \b/\e/\c in {A/D/H, B/E/I, C/A/J, D/B/K, E/C/L}{\pstCircleABC[linecolor=LightPink]{O}{\b}{\e}{\c}}
 \endpsclip
\end{pspicture}
\end{document}
 

enter image description here

  • 1
    Wow...many times I informed you I am one of a lover of PSTricks... – MadyYuvi Dec 5 '20 at 6:44
  • May I know why you use svg option of standalone? – Diaa Dec 5 '20 at 10:18
  • 1
    @Diaa: It is not an option of standalone, but of xcolor, that pstricks already loads without option. Loading it as a class option ensures the option is passed to xcolor without an ‘option clash’ message. – Bernard Dec 5 '20 at 10:23
10

An extra light pure LaTeX solution (``Small is beautiful''):

\documentclass {article}
\usepackage{pict2e}
\usepackage{comment}
\begin{document}

\unitlength=5cm
\begin{picture}(2,2)(-1,-1)
    
\begin{comment}
; Elisp code to generate the repetitive LaTeX code for petals.
; only if you are an Emacs user. C-x C-e to evaluate.
(dolist (i (number-sequence 0 4)
    (insert (format "\n\n\\put(0,0){\\circle{%.3f}}" (* 4 (cos (* 2 (/ float-pi 5)))))))
(let* 
   ((angle-d (- (* (+ i 4) 72) 90))
    (angle-r (* angle-d(/ float-pi 180))))
 (insert 
  (format "\n\\put(%.3f,%.3f){\\arc[%d,%d]{1}}"
         (cos angle-r)
         (sin angle-r)
         (-(* i 72)18) 
         (+(* i 72)54)))))
\end{comment}
  \put(-0.951,-0.309){\arc[-18,54]{1}}
  \put(-0.000,-1.000){\arc[54,126]{1}}
  \put(0.951,-0.309){\arc[126,198]{1}}
  \put(0.588,0.809){\arc[198,270]{1}}
  \put(-0.588,0.809){\arc[270,342]{1}}

  \put(0,0){\circle{1.236}}
 \end{picture}
\end{document} 

Water lily

A more sophisticated solution using the xpicture package :

     \documentclass{article}
     \usepackage{xpicture}
     \usepackage{multido}
    
    \begin{document}
    
    
\newcommand{\xrosace}[1]{%
        \polarreference\degreesangles%
        \newcommand{\Depart}{\ifodd#1-90\else0\fi}%
        \DIVIDE{360}{#1}{\Rot}  %
        \DIVIDE{\Rot}{2}{\DemRot}%
        \ifodd#1\SUBTRACT{90}{\DemRot}{\Orig}%
        \else\SUBTRACT{180}{\Rot}{\Orig}%
        \fi
        \ifodd#1\ADD{\Orig}{\Rot}{\Extr}%
        \else\ADD{180}{\Rot}{\Extr}%
        \fi
        \DIVIDE{\Rot}{4}{\QrtRot}%
        \ifodd#1\DEGREESSIN{\QrtRot}{\Drayon}%
        \else\DEGREESSIN{\DemRot}{\Drayon}%
        \fi
        \MULTIPLY{2}{\Drayon}{\rayon}%
        \DIVIDE{1}{\rayon}{\Irayon}%
        \Circle{1}%
        \multido{\rangle=\Depart+\Rot,%
                \rorig=\Orig+\Rot,%
                \rextr=\Extr+\Rot}{#1}%
        {\Put(\Irayon,\rangle){\circularArc{\Irayon}{\rorig}{\rextr}}}
}% fin xrosace

    
    
    \unitlength=2cm
    
    \begin{xpicture}(9,4)(-3,-1)
    
            \Put(-4, 0){\xrosace{3}}
            \Put(-2, 0){\xrosace{4}}
            \Put( 0, 0){\xrosace{5}}
            \Put( 2, 0){\xrosace{6}}
            \Put( 4, 0){\xrosace{7}}
            \Put(-4,-2){\xrosace{8}}
            \Put(-2,-2){\xrosace{9}}
            \Put( 0,-2){\xrosace{10}}
            \Put( 2,-2){\xrosace{11}}
            \Put( 4,-2){\xrosace{12}}
    
    \end{xpicture}
    
    \end{document}

multi rosace

  • Really innovative...+1 for without tikz and all.... – MadyYuvi Dec 7 '20 at 15:31
8

Is a Metapost alternative allowed?

\documentclass{standalone}
\usepackage[shellescape,latex]{gmp}
\begin{document}
\begin{mpost}[name=lily]
numeric unit;
unit := 2cm;
path Circle; Circle := (fullcircle shifted -center fullcircle) scaled (2*unit);
path Form; Form := (unit*right) .. origin .. (unit*dir(144));
draw Circle;
for i = 1 upto 5:
    draw Form rotated (72*i+30);
endfor;
\end{mpost}%
\usempost{lily}%
\end{document}

enter image description here

  • What do you mean by "Metapost alternative"? – Peter Mortensen Dec 6 '20 at 12:21
  • @PeterMortensen Questions about drawing something are usually asked with an answer in TikZ expected. I asked if Metapost was a valid solution. Sorry for the broken English. – Jairo A. del Rio Dec 6 '20 at 12:24
8

A PSTricks solution only for either fun or comparison purposes.

enter image description here

\documentclass[pstricks,border=3mm]{standalone}
\begin{document}
\pspicture[linecolor=blue,linewidth=2pt](-5,-5)(5,5)
\psclip{\pscircle{5}}
    \foreach \i in {0,60,...,300}{\pscircle(5;\i){5}}
\endpsclip
\endpspicture
\end{document}

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.