如果不使用 MATLAB、Python 或任何矢量图形语言,是否可以使用 TikZ 绘制参数曲线三角曲线(a/b = 3)和星形曲线(a/b = 4)?
\begin{tikzpicture}
\draw (0,0) circle [radius=4cm];
\draw[dashed] (0,0) circle [radius=3cm];
\draw[red] (3,0) circle [radius=1cm];
\draw[smooth] (4,0) .. controls(3,0) ..(1.4,1.4).. controls(0,3).. (0,4);
\end{tikzpicture}
答案1
仅供比较,以下是元帖子和luamplib
包。使用 进行编译lualatex
。
\documentclass[border=5mm]{standalone}
\usepackage{luamplib}
\begin{document}
\mplibtextextlabel{enable}
\begin{mplibcode}
beginfig(1);
numeric r, n;
r = 1cm;
n + 1 = 4;
path xx, yy, C[];
xx = (left--right) scaled ((n+2)*r);
yy = xx rotated 90;
numeric theta; theta = 120/n;
C1 = fullcircle scaled 2r rotated (-n * theta) shifted ((n*r, 0) rotated theta);
C2 = fullcircle scaled (2r * n);
C3 = fullcircle scaled (2r * (n+1));
path delta; numeric s; s = 1/2;
delta = for t=s step s until 360:
(r, 0) rotated (-n*t) shifted ((n*r, 0) rotated t) --
endfor cycle;
draw xx withcolor 2/3 blue;
draw yy withcolor 2/3 blue;
draw C1 withcolor 2/3 green;
draw C2 dashed evenly withcolor 2/3 green;
draw C3 withcolor 2/3 green;
draw origin -- center C1 -- point 0 of C1 withcolor 3/4;
draw delta withpen pencircle scaled 1 withcolor 2/3 red;
dotlabel.lrt("$O$", origin);
dotlabel.lrt("$" & decimal (n+1) & "r$", point 0 of C3);
dotlabel.llft("$A$", point 0 of C1);
label("$r$", 1/2[point 0 of C1, center C1] shifted (5 * unitvector(direction 0 of C1)));
label("$" & decimal n & "r$", 1/2 center C1 shifted (5 * unitvector(center C1 rotated 90)));
endfig;
\end{mplibcode}
\end{document}
改变 的值n
将绘制其他内摆线。因此,n+1 = 5;
您将得到:
也可以看看这个答案了解更多详情。
答案2
原始解决方案:三角肌
这是纯 Ti 中的快速解决方案钾Z,使用三角肌的参数定义(带有b=3a
):
\documentclass[tikz,border=3.14159mm]{standalone}
\begin{document}
\begin{tikzpicture}
\draw[cyan,very thin] (-4,-4) grid (4,4);
\draw[->] (-4,0) -- (4,0);
\draw[->] (0,-4) -- (0,4);
\draw (0,0) circle (3);
\def\a{1} \def\b{3}
\draw[line width=1pt,blue] plot[samples=100,domain=0:360,smooth,variable=\t] ({(\b-\a)*cos(\t)+\a*cos((\b-\a)*\t/\a},{(\b-\a)*sin(\t)-\a*sin((\b-\a)*\t/\a});
\end{tikzpicture}
\end{document}
快速编辑:内摆线
如果您希望能够改变的值b
以获得其他内摆线和要自动编辑的网格,这里有一个更好的解决方案(这次使用b=5a
):
\documentclass[tikz,border=3.14159mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\a{1} \def\b{5}
\draw[cyan,very thin] (-\b,-\b) grid (\b,\b);
\draw[->] (-\b,0) -- (\b,0);
\draw[->] (0,-\b) -- (0,\b);
\draw (0,0) circle (\b);
\draw[line width=2pt,red] plot[samples=100,domain=0:\a*360,smooth,variable=\t] ({(\b-\a)*cos(\t)+\a*cos((\b-\a)*\t/\a},{(\b-\a)*sin(\t)-\a*sin((\b-\a)*\t/\a}); <-- edited (to add \a*360)
\end{tikzpicture}
\end{document}
编辑:\a*360
剧情忘了写,出现a, a
1以外的情况,曲线不完整,现在好了。
完整版
现在具有所有构造线和选择滚动圆中心位置的可能性。
\documentclass[tikz,border=3.14159mm]{standalone}
\begin{document}
\begin{tikzpicture}
\def\clr{olive}
% Define parameters a and b of the hypocycloid
\def\a{2} \def\b{7}
% Define the parameters for plotting the function
\newcommand{\xt}[1]{(\b-\a)*cos(#1)+\a*cos((\b-\a)*#1/\a}
\newcommand{\yt}[1]{(\b-\a)*sin(#1)-\a*sin((\b-\a)*#1/\a}
% Coordinate system and grid
\draw[cyan,very thin] (-\b-1,-\b-1) grid (\b+1,\b+1);
\draw[->] (-\b-1,0) -- (\b+1,0);
\draw[->] (0,-\b-1) -- (0,\b+1);
% The circle into which the rolling circle rolls
\draw[\clr,thick] (0,0) circle (\b);
% The circle on which moves the center of the rolling circle
\draw[\clr,dashed,very thin] (0,0) circle (\b-\a);
% Plot the hypocycloid
\draw[line width=2pt,orange!80!red] plot[samples=100,domain=0:\a*360,smooth,variable=\t] ({\xt{\t}},{\yt{\t}});
% Define the value of t0 (current point)
% (i.e. the angular abscissa for the center of the rolling circle
% and draw the construction lines
\def\t0{40}
\draw[\clr!50!black] (\t0:\b-\a) circle (\a);
\draw[purple,fill] ({\xt{\t0}},{\yt{\t0}}) circle (2pt) -- (\t0:\b-\a) circle (1pt) node [midway, sloped, above] {\scriptsize $r=a$} -- (0,0) circle (1pt) node [midway, sloped, above] {\scriptsize $R=b-a$} node [below right] {$O$};
% Printing the values of a and b in the upper left corner
\node[\clr,rounded corners,fill=white,draw,text width=1cm,align=center] at (-\b,\b) {$a=\a$ $b=\b$};
\end{tikzpicture}
\end{document}