TransWikia.com

How can I draw a water lily in LaTeX?

TeX - LaTeX Asked by JoudaBouda on April 24, 2021

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}
newcommandradius{3}
newcommandy{sqrt{3*radius^2 /4}}

begin{document}
pagestyle{empty}
deffirstcircle{(0,0) circle (radius)}
defsecondcircle{(3,0) circle (radius)}
defthirdcircle{({radius , y}) circle (radius)}
%deffourthcircle{(3,0) circle (3cm)}
%deffifthcircle{(3,0) circle (3cm)}
begin{tikzpicture}
    draw firstcircle;
    draw secondcircle;
%    draw thirdcircle;

end{tikzpicture}
end{document}

Why wouldn’t the third circle draw?

7 Answers

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}
defR{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);}

Correct answer by Black Mild on April 24, 2021

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

Answered by user229669 on April 24, 2021

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

Answered by Jairo A. del Rio on April 24, 2021

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}

Answered by Money Sets You Free on April 24, 2021

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

Answered by Bernard on April 24, 2021

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}

Answered by Alan Xiang on April 24, 2021

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 "nnput(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 "nput(%.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]{%
        polarreferencedegreesangles%
        newcommand{Depart}{ifodd#1-90else0fi}%
        DIVIDE{360}{#1}{Rot}  %
        DIVIDE{Rot}{2}{DemRot}%
        ifodd#1SUBTRACT{90}{DemRot}{Orig}%
        elseSUBTRACT{180}{Rot}{Orig}%
        fi
        ifodd#1ADD{Orig}{Rot}{Extr}%
        elseADD{180}{Rot}{Extr}%
        fi
        DIVIDE{Rot}{4}{QrtRot}%
        ifodd#1DEGREESSIN{QrtRot}{Drayon}%
        elseDEGREESSIN{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

Answered by gigiair on April 24, 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