我正在尝试在 Latex 中绘制开花图
我使用了代码
\documentclass[10pt]{article}
\usepackage{pgf,tikz}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\pagestyle{empty}
\begin{document}
\definecolor{xdxdff}{rgb}{0.49019607843137253,0.49019607843137253,1.}
\definecolor{qqqqff}{rgb}{0.,0.,1.}
\begin{tikzpicture}[line cap=round,line join=round,>=triangle 45,x=1.0cm,y=1.0cm]
\clip(1.,-0.5) rectangle (12.,6.5);
\draw (1.6100313170731664,1.4816196363636465) node[anchor=north west] {(3,0)};
\draw (3.3700313170731664,0.9450342705099871) node[anchor=north west] {(3,1)};
\draw (4.550519121951216,0.9450342705099871) node[anchor=north west] {(3,2)};
\draw (5.816860585365849,0.9664976851441335) node[anchor=north west] {(3,3)};
\draw (6.9544215609756055,0.9664976851441335) node[anchor=north west] {(3,4)};
\draw (8.091982536585363,0.9664976851441335) node[anchor=north west] {(3,5)};
\draw (9.315397170731703,0.9450342705099871) node[anchor=north west] {(3,6)};
\draw (11.118323999999998,1.5245464656319392) node[anchor=north west] {(3,7)};
\draw (2.4,2.4)-- (3.6,1.2);
\draw (2.4,3.6)-- (4.8,1.2);
\draw (2.4,4.8)-- (6.,1.2);
\draw (3.6,4.8)-- (7.2,1.2);
\draw (4.8,4.8)-- (8.4,1.2);
\draw (6.,4.8)-- (9.6,1.2);
\draw (7.2,4.8)-- (10.8,1.2);
\draw (8.4,4.8)-- (10.8,2.4);
\draw (2.4,4.8)-- (2.4210691630004746,1.1581663907342912);
\draw (2.4210691630004746,1.1581663907342912)-- (10.8,1.2);
\draw (10.8,4.8)-- (10.8,1.2);
\draw (2.4210691630004746,1.1581663907342912)-- (10.8,2.4);
\draw (2.4,2.4)-- (10.8,3.6);
\draw [shift={(6.402736682926827,-3.0444929490022137)}]
plot[domain=1.0598862253036718:2.042618783382904,variable=\t]
({1.*8.992885760790182*cos(\t r)+0.*8.992885760790182*sin(\t r)},
{0.*8.992885760790182*cos(\t r)+1.*8.992885760790182*sin(\t r)});
\draw [shift={(6.622708780487803,8.11123485587585)}] plot[domain=4.168824211395043:5.256052424730513,variable=\t]({1.*8.123972953929934*cos(\t r)+0.*8.123972953929934*sin(\t r)},{0.*8.123972953929934*cos(\t r)+1.*8.123972953929934*sin(\t r)});
\draw (2.4,4.8)-- (10.8,4.8);
\draw (2.4,3.6)-- (10.8,4.8);
\draw (1.6100313170731664,2.5762537827051117) node[anchor=north west] {(3,1)};
\draw (1.58856790243902,3.7138147583148693) node[anchor=north west] {(3,1)};
\draw (1.5241776585365812,5.13040012416853) node[anchor=north west] {(0,0)};
\draw (3.412958146341459,5.36649768514414) node[anchor=north west] {(0,1)};
\draw (4.529055707317069,5.36649768514414) node[anchor=north west] {(0,2)};
\draw (5.709543512195118,5.387961099778287) node[anchor=north west] {(0,3)};
\draw (6.847104487804875,5.36649768514414) node[anchor=north west] {(0,4)};
\draw (8.177836195121948,5.36649768514414) node[anchor=north west] {(0,5)};
\draw (9.315397170731703,5.302107441241701) node[anchor=north west] {(0,6)};
\draw (11.182714243902437,5.023083050997799) node[anchor=north west] {(0,7)};
\draw (11.139787414634144,3.864058660753894) node[anchor=north west] {(3,1)};
\draw (11.118323999999998,2.597717197339258) node[anchor=north west] {(3,1)};
\begin{scriptsize}
\draw [fill=qqqqff] (2.4210691630004746,1.1581663907342912) circle (2.5pt);
\draw [fill=qqqqff] (3.6,1.2) circle (2.5pt);
\draw [fill=qqqqff] (4.8,1.2) circle (2.5pt);
\draw [fill=qqqqff] (6.,1.2) circle (2.5pt);
\draw [fill=qqqqff] (7.2,1.2) circle (2.5pt);
\draw [fill=qqqqff] (8.4,1.2) circle (2.5pt);
\draw [fill=qqqqff] (9.6,1.2) circle (2.5pt);
\draw [fill=qqqqff] (10.8,1.2) circle (2.5pt);
\draw [fill=qqqqff] (2.4,2.4) circle (2.5pt);
\draw [fill=qqqqff] (3.6,2.4) circle (2.5pt);
\draw [fill=qqqqff] (4.8,2.4) circle (2.5pt);
\draw [fill=qqqqff] (6.,2.4) circle (2.5pt);
\draw [fill=qqqqff] (7.2,2.4) circle (2.5pt);
\draw [fill=qqqqff] (8.4,2.4) circle (2.5pt);
\draw [fill=qqqqff] (9.6,2.4) circle (2.5pt);
\draw [fill=qqqqff] (10.8,2.4) circle (2.5pt);
\draw [fill=qqqqff] (2.4,3.6) circle (2.5pt);
\draw [fill=qqqqff] (3.6,3.6) circle (2.5pt);
\draw [fill=qqqqff] (4.8,3.6) circle (2.5pt);
\draw [fill=qqqqff] (6.,3.6) circle (2.5pt);
\draw [fill=qqqqff] (7.2,3.6) circle (2.5pt);
\draw [fill=qqqqff] (8.4,3.6) circle (2.5pt);
\draw [fill=qqqqff] (9.6,3.6) circle (2.5pt);
\draw [fill=qqqqff] (10.8,3.6) circle (2.5pt);
\draw [fill=qqqqff] (2.4,4.8) circle (2.5pt);
\draw [fill=qqqqff] (3.6,4.8) circle (2.5pt);
\draw [fill=qqqqff] (4.8,4.8) circle (2.5pt);
\draw [fill=qqqqff] (6.,4.8) circle (2.5pt);
\draw [fill=qqqqff] (7.2,4.8) circle (2.5pt);
\draw [fill=qqqqff] (8.4,4.8) circle (2.5pt);
\draw [fill=qqqqff] (10.8,4.8) circle (2.5pt);
\draw [fill=xdxdff] (9.6,4.8) circle (2.5pt);
\draw[color=xdxdff] (9.798323999999996,5.259180611973409) node {$J_1$};
\end{scriptsize}
\end{tikzpicture}
\end{document}
输出显示
答案1
这是一个metapost
解决方案。
bloomgrapha(m,n,s,u)
绘制网格版本。m
和n
问题中的一样,s
确定标签比例,并u
确定图形比例。bloomgraphb(m,n,d,s,u)
如上所示,绘制“绽放”版本。这里m
=layers,n
=petals per layer。附加参数d
决定花瓣延伸多远。
draw bloomgrapha(4,8,.75,7mm);
生产
上半部分draw bloomgraphb(4,8,1.5,.75,2cm);
看起来像
标签有点模糊,因此您可以进行调整,让它们看起来像您想要的那样。
编译lualatex
:
\documentclass{article}
\usepackage{luamplib}
\mplibnumbersystem{double}
\mplibtextextlabel{enable}
\mplibcodeinherit{enable}
\everymplib{beginfig(0);}
\everyendmplib{endfig;}
\mplibforcehmode
\begin{document}
\begin{mplibcode}
vardef bloomgrapha(expr m,n,s,u)=
save ang_; ang_:=30;
save node_; pair node_[][];
save g_; picture g_;
g_:=image(
interim defaultscale:=s;
for i=0 upto m-1:
for j=0 upto n-1:
node_[j][i]:=u*(j,i);
draw node_[j][i] withpen pencircle scaled .1u;
label.llft("\tiny{("&decimal(m-i-1)&","&decimal(j)&")}",node_[j][i]);
endfor;
endfor;
for i=0 upto n-1: draw node_[i][m-1]--node_[i][0]; endfor;
draw node_[0][m-1]{dir ang_}..{dir -ang_}node_[n-1][m-1]--cycle;
draw node_[0][0]{dir -ang_}..{dir ang_}node_[n-1][0]--cycle;
for i=1 upto m-1:
for j= 0 upto n-1:
draw node_[j][i]--node_[(j+1) mod n][i-1];
endfor;
endfor;);
g_
enddef;
% fixed this a bit, sep = separation of bounding box from point
vardef bloomlabel(expr s,z,sep) =
save p,d; picture p;
p = s infont defaultfont scaled defaultscale;
interim bboxmargin:=sep;
% d is length of line from center of bb to its edge in dir of point.
d = abs((origin--z) intersectionpoint (bbox p shifted -center p));
p shifted (z-d*dir(angle(z))-center p)
enddef;
vardef bloomgraphb(expr m,n,d,s,u)=
save p,t,bg,k,r;
path p[]; transform t; picture bg;
k:=360/n;
p0=fullcircle scaled u;
p1=d[origin,point 8/(2n) of p0]; % changing 1.4 alters length of petals
p2=point 0 of p0{dir 0}..p1..{dir (180+k)}point (8/n) of p0; % petal
% transform=rotate and scale
origin transformed t=origin;
point 0 of p2 transformed t=point 1 of p2;
point 2 of p2 transformed t=point 1 of (p2 rotated k);
bg:=image(
interim defaultscale:=s;% changes label size
draw p0 withpen pencircle scaled .02u;
for i=0 upto m-1:
for j=0 upto n-1:
r:=k*j;
draw p2 rotated r withpen pencircle scaled .02u; % draw petal
draw bloomlabel("{\tiny("&decimal(i)&","&decimal(j)&")}",point 0 of (p2 rotated r),2);
draw fullcircle scaled .03u shifted point 0 of (p2 rotated r) withpen pencircle scaled .02u; % draw dots
unfill fullcircle scaled .03u shifted point 0 of (p2 rotated r);
unfill fullcircle scaled .03u shifted point 2 of (p2 rotated r);
endfor;
p2:=p2 transformed t; %transform petal
endfor;
);
bg
enddef;
\end{mplibcode}
\begin{center}
\begin{mplibcode}
pen mypen; mypen=pencircle scaled .5bp;
pickup mypen;
draw bloomgrapha(4,8,.75,7mm);
\end{mplibcode}\\[3cm]
\begin{mplibcode}
draw bloomgraphb(4,8,1.5,.75,2cm);
\end{mplibcode}
\end{center}
\end{document}
出自(同前言):
\begin{mplibcode}
u:=6cm;
path p[];
n:=20; % petals
m:=20; % layers
k:=360/n;
p0=fullcircle scaled .2u;
p1=1.1[origin,point 8/(2n) of p0];
p2=point 0 of p0--p1--point (8/n) of p0;
draw p2 withpen pencircle scaled 2bp;
transform t;
origin transformed t=origin;
point 0 of p2 transformed t=point 1 of p2;
point 2 of p2 transformed t=point 1 of (p2 rotated k);
p3=p2 transformed t..reverse subpath (0,1) of p2 rotated k..reverse subpath (1,2) of p2..cycle;
p3:=p3 transformed inverse t;
save q; path q;
q:=p3;
fill fullcircle scaled .8u withcolor black;
for i=0 upto m-1:
for j=0 upto n-1:
draw q rotated (k*j) withpen pencircle scaled ((2i+1)/(n)) withcolor (i/(m))[black,white];
fill q rotated (k*j) withcolor (i/m)[white,black];
endfor;
q:=q transformed t;
endfor;
\end{mplibcode}
答案2
这只是提到两件事。
- 只需要一个嵌套循环即可绘制此图。(好吧,有几个
\ifnum
,但仍然如此。) - 正如论文中提到的,这些图总是相同的。也就是说,可以使用相同的算法,但使用不同的坐标系来绘制图形。
这个答案从三个坐标系说明了这一点:
- 笛卡尔
- 极性
- 圆柱形
以下是完整的代码。
\documentclass[tikz,border=3mm]{standalone}
\makeatletter
\define@key{mypolarkeys}{x}{\def\myx{#1}}
\define@key{mypolarkeys}{y}{\def\myy{#1}}
\tikzdeclarecoordinatesystem{mypolar}%
{%
\setkeys{mypolarkeys}{#1}%
\pgfpointpolarxy{\myx}{\myy}%
}
%
\define@key{mycartesiankeys}{x}{\def\myx{#1}}
\define@key{mycartesiankeys}{y}{\def\myy{#1}}
\tikzdeclarecoordinatesystem{mycartesian}%
{%
\setkeys{mycartesiankeys}{#1}%
\pgfpointxy{\myx}{\myy}%
}
%
\define@key{mycylindricalkeys}{x}{\def\myx{#1}}
\define@key{mycylindricalkeys}{y}{\def\myy{#1}}
\tikzdeclarecoordinatesystem{mycylindrical}%
{%
\setkeys{mycylindricalkeys}{#1}%
\pgfpointadd{\pgfpointxyz{0}{0}{\myy}}{\pgfpointpolarxy{\myx}{\pgfkeysvalueof{/tikz/Bloom/r}}}%
}
\makeatother
\tikzset{blullet/.style={circle,draw,fill=blue,inner sep=2pt},
pics/Bloom graph/.style={code={%
\tikzset{Bloom/.cd,#1}
\def\pv##1{\pgfkeysvalueof{/tikz/Bloom/##1}}%
\path foreach \Y in {0,...,\the\numexpr\pv{n}-1}
{foreach \X [evaluate=\X as \NextX using {int(Mod(\X-1,\pv{m}))}] in {0,...,\the\numexpr\pv{m}-1}
{(\pv{cs}\space cs:x={\pv{xmin}+(\X/\pv{m})*(\pv{xmax}-\pv{xmin})},y={\pv{ymin}+(\Y/\pv{n})*(\pv{ymax}-\pv{ymin})})
coordinate[blullet,label={$(\Y,\X)$}]
(b-\Y-\X)
\ifnum\X>0
edge (b-\Y-\the\numexpr\X-1)
\fi
\ifnum\Y>0
edge (b-\the\numexpr\Y-1\relax-\NextX)
\ifnum\X=0
edge (b-\the\numexpr\Y-1\relax-\X)
\fi
\ifnum\X=\numexpr\pv{m}-1
edge (b-\the\numexpr\Y-1\relax-\X)
\ifnum\Y=\numexpr\pv{n}-1
edge[Bloom/edge 1] (b-\the\numexpr\pv{n}-1\relax-0)
\fi
\fi
\else
\ifnum\X=\numexpr\pv{m}-1
edge[Bloom/edge 2] (b-0-0)
\fi
\fi
}};
}},
/tikz/Bloom/.cd,m/.initial=8,n/.initial=4,r/.initial=pi,
ymin/.initial=-1,ymax/.initial=-6,
xmin/.initial=0,xmax/.initial=12,cs/.initial=mycartesian,
edge 1/.style={},edge 2/.style={}
}
\begin{document}
\begin{tikzpicture}[every label/.style={inner sep=1pt,font=\small,anchor=north east}]
\pic{Bloom graph={edge 1/.style=bend left,edge 2/.style=bend right}};
\end{tikzpicture}
\begin{tikzpicture}[every label/.style={yshift=-1ex,font=\small,anchor=north}]
\pic{Bloom graph={xmin=0,xmax=360,ymin=2,ymax=6,cs=mypolar}};
\end{tikzpicture}
\begin{tikzpicture}[every label/.style={yshift=-1ex,font=\small,anchor=north}]
\path (-30:1 and 0.3) coordinate(x) (60:1 and 0.3) coordinate(y)
(0,1) coordinate(z);
\begin{scope}[x={(x)},y={(y)},z={(z)}]
\pic{Bloom graph={xmin=0,xmax=360,ymin=0,ymax=5,cs=mycylindrical}};
\end{scope}
\end{tikzpicture}
\end{document}
我没有调整图表来获得惊人的输出,这主要是为了说明如何引入各种坐标系并定义一个允许随意更改的图片。
非线性变换也是一种可行的方法。任何玩这个的人可能需要这个很酷但投票率很低的答案。