我想知道有人能画出这样的画吗?
我试过了,但我才刚刚开始……应该有四个半圆和一个完整的圆。到目前为止,我只画出了其中两个。这是我的代码:
\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}
第三个圆为什么画不出来?
答案1
您在寻找这朵五瓣“睡莲”吗?
% 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}
我更新了@Jairo 的 Asymptote 版本
//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);}
答案2
答案3
使用LuaTeX,很容易生成一些更通用的结果。
\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}
答案4
超轻纯 LaTeX 解决方案(“小即是美”):
\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}
使用 xpicture 包的更复杂的解决方案:
\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}