免費論壇 繁體 | 簡體
Sclub交友聊天~加入聊天室當版主
分享
返回列表 发帖

请教tikz怎么才能画一个随机的闭曲线?

如题,下图中有一个不规则的曲线,这是我用GeoGebra画的,其实就是几个圆的一部分,觉得不太好画,也不够随机。
tikz能不能简单地画出这种不规则的曲线?或者闭的曲线。比如我想的是这样的:定义出点A_1到A_10=A_1,然后指定A_1,A_2两点,在这两点间生成一段随机曲线(最好能指定是否凸),然后依次往下做,或者循环做,就应该能作出这种闭曲线了吧。
闭曲线.gif
2021-2-17 13:05
分享到: QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友

真的随机起来,每次画的会不一样,你的圆怎么放?

TOP

像你那图,就自己随意手动指定一些点然后把它们 smooth cycle 地 plot 起来就好了,像这样
\newcommand\dian[4]{\coordinate[label={#4:$#3$}] (#2) at (#1);}
\tikz{
\dian{0,0}OO{-90}
\dian{-160:2}AA{180}
\dian{20:2}BB{0}
\dian{-0.1,1.2}CC{90}
\foreach \i in {A,B,C,O} \fill[red] (\i) circle (1pt);
\draw (O) circle (2);
\draw plot[smooth cycle] coordinates{
(B) (50:1.2) (C) (150:1.3) (A) (-120:0.8) (-30:1.5)};
}
捕获.PNG
2021-2-17 17:09
$\href{https://kuingggg.github.io/}{\text{About Me}}$

TOP

回复 3# kuing

原来如此,smooth cycle就是平滑连接的意思吧,如果不指定那个连入角度和位置,在AB两点可能连完会不在圆里,这个角度也很关键,我就是这里弄不好。

TOP

回复 4# abababa

稍微调整到看起来没超出就行了,我上面的图在 A、B 处肯定不是真相切的。

TOP

本帖最后由 abababa 于 2021-6-1 09:20 编辑

无标题.gif
2021-6-1 09:18

如图,这种图得怎么画啊,觉得这个都找不到控制点在哪里,这能不能直接用什么软件画出来,再导成tikz呢?只要求tikz就行了,里面内容比如坐标之类的不用太好看。

TOP

回复 6# abababa

试试去 https://www.mathcha.io 里用笔画出来,再导出 tikz

TOP

回复 7# kuing

试了一下:
QQ截图20210601150059.png
2021-6-1 15:03

点 tikz 后
QQ截图20210601150259.png
2021-6-1 15:03

复制出来是:
  1. \tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

  2. \begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
  3. %uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

  4. %Shape: Free Drawing [id:dp18071961560476102]
  5. \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round] (104,43.2) .. controls (104,80.6) and (103.57,120.08) .. (98,157.2) .. controls (96.19,169.28) and (95.17,182.29) .. (93,194.2) .. controls (91.65,201.61) and (88,208.27) .. (88,216.2) ;
  6. %Shape: Free Drawing [id:dp86482172172365]
  7. \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round] (164,118.2) .. controls (159.14,121.12) and (153.56,122.84) .. (149,126.2) .. controls (136.51,135.4) and (127.39,145.09) .. (116,154.2) .. controls (114.14,155.69) and (107.98,160.92) .. (105,162.2) .. controls (103.06,163.03) and (98.22,162.24) .. (99,164.2) .. controls (103.37,175.12) and (116.63,181.18) .. (125,186.2) .. controls (131.64,190.18) and (136.65,200.97) .. (143,205.2) .. controls (147.16,207.97) and (151.46,210.66) .. (155,214.2) ;
  8. %Shape: Free Drawing [id:dp8934113718637382]
  9. \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round] (194,122.2) .. controls (194,139.42) and (185.62,157.01) .. (185,176.2) .. controls (184.79,182.58) and (178.44,205.94) .. (191,207.2) .. controls (210.37,209.14) and (221.13,198.36) .. (231,185.2) .. controls (233.84,181.41) and (238,178.49) .. (240,174.2) .. controls (242.15,169.6) and (243.39,164.55) .. (246,160.2) .. controls (250.49,152.72) and (250.06,142.94) .. (252,135.2) .. controls (252.7,132.42) and (250.25,116.96) .. (253,125.2) .. controls (254.41,129.42) and (250.87,133.84) .. (250,138.2) .. controls (249.35,141.47) and (250.38,144.89) .. (250,148.2) .. controls (247.56,169.32) and (244,188.69) .. (244,210.2) ;
  10. %Shape: Free Drawing [id:dp8788589171357393]
  11. \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round] (298,124.2) .. controls (292.47,149.1) and (293,185.77) .. (293,211.2) ;
  12. %Shape: Free Drawing [id:dp04160902226876839]
  13. \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round] (296,85.2) .. controls (296,88.36) and (297.1,91.67) .. (299,94.2) ;
  14. %Shape: Free Drawing [id:dp5364140327815587]
  15. \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round] (339,125.2) .. controls (337.05,142.76) and (333.41,160.56) .. (333,178.2) .. controls (332.76,188.53) and (333.26,198.87) .. (333,209.2) .. controls (332.93,211.89) and (332.08,219.89) .. (332,217.2) .. controls (331.26,193.67) and (330.49,163.59) .. (339,140.2) .. controls (343.85,126.85) and (367.04,123.95) .. (378,122.2) .. controls (381.64,121.62) and (388.11,119.63) .. (389,123.2) .. controls (391.15,131.79) and (390.85,142.61) .. (393,151.2) .. controls (394.28,156.31) and (397.27,160.98) .. (398,166.2) .. controls (400.02,180.73) and (398.36,195.54) .. (399,210.2) ;
  16. %Shape: Free Drawing [id:dp2909930747069298]
  17. \draw  [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round] (486,120.2) .. controls (486,109.51) and (464.68,117.89) .. (454,118.2) .. controls (445.55,118.44) and (444.12,131.89) .. (442,137.2) .. controls (434.61,155.67) and (430.53,171.63) .. (432,192.2) .. controls (432.12,193.93) and (435.7,201.82) .. (438,202.2) .. controls (463.56,206.46) and (488.05,184.58) .. (497,162.2) .. controls (498.14,159.35) and (497.82,156.04) .. (499,153.2) .. controls (499.54,151.89) and (501.87,151.61) .. (502,150.2) .. controls (502.91,140.24) and (509.07,127.27) .. (502,120.2) .. controls (495.6,113.8) and (499.21,138.15) .. (499,147.2) .. controls (498.21,180.86) and (499.62,214.54) .. (499,248.2) .. controls (498.76,261.12) and (489.24,284.37) .. (474,286.2) .. controls (467.38,286.99) and (460.66,285.93) .. (454,286.2) .. controls (437.74,286.85) and (425.82,287.72) .. (415,274.2) .. controls (392.43,245.99) and (433.29,224.69) .. (449,216.2) .. controls (479.72,199.6) and (514.82,192.07) .. (545,174.2) .. controls (574.78,156.57) and (589.42,140.68) .. (614,120.2) ;




  18. \end{tikzpicture}
复制代码
$\href{https://kuingggg.github.io/}{\text{About Me}}$

TOP

回复 7# kuing

谢谢,这个确实好用,但我画图能力太差,画得不够光滑。

然后我发现GeoGebra软件里,有那个画过三点的圆弧的工具,我就试着用了一下,感觉还行,用圆弧一段一段拼起来。如下:
  1. \begin{tikzpicture}[scale=0.5,label style/.style={font=\scriptsize}]
  2. \draw[color=blue] (1.2,5.5) node {$A$};
  3. \draw [shift={(0.8,3.23)}] plot[domain=0.49:4.12,variable=\t]({1*0.57*cos(\t r)+0*0.57*sin(\t r)},{0*0.57*cos(\t r)+1*0.57*sin(\t r)});
  4. \draw [shift={(3.87,1.17)}] plot[domain=3.51:5.83,variable=\t]({1*0.52*cos(\t r)+0*0.52*sin(\t r)},{0*0.52*cos(\t r)+1*0.52*sin(\t r)});
  5. \draw [shift={(4.67,1.84)}] plot[domain=1.92:3.73,variable=\t]({1*1.55*cos(\t r)+0*1.55*sin(\t r)},{0*1.55*cos(\t r)+1*1.55*sin(\t r)});
  6. \draw [shift={(4.42,2.47)}] plot[domain=0.01:1.9,variable=\t]({1*0.88*cos(\t r)+0*0.88*sin(\t r)},{0*0.88*cos(\t r)+1*0.88*sin(\t r)});
  7. \draw [shift={(5.99,2.74)}] plot[domain=-2.78:0.66,variable=\t]({1*0.74*cos(\t r)+0*0.74*sin(\t r)},{0*0.74*cos(\t r)+1*0.74*sin(\t r)});
  8. \draw [shift={(5.38,2.23)}] plot[domain=0.68:1.68,variable=\t]({1*1.54*cos(\t r)+0*1.54*sin(\t r)},{0*1.54*cos(\t r)+1*1.54*sin(\t r)});
  9. \draw [shift={(5.13,4.6)}] plot[domain=3.33:4.82,variable=\t]({1*0.84*cos(\t r)+0*0.84*sin(\t r)},{0*0.84*cos(\t r)+1*0.84*sin(\t r)});
  10. \draw [shift={(3.25,4.49)}] plot[domain=-0.05:1.17,variable=\t]({1*1.05*cos(\t r)+0*1.05*sin(\t r)},{0*1.05*cos(\t r)+1*1.05*sin(\t r)});
  11. \draw [shift={(4.35,6.45)}] plot[domain=2.33:4.1,variable=\t]({1*1.2*cos(\t r)+0*1.2*sin(\t r)},{0*1.2*cos(\t r)+1*1.2*sin(\t r)});
  12. \draw [shift={(3.24,7.62)}] plot[domain=-0.81:2.52,variable=\t]({1*0.41*cos(\t r)+0*0.41*sin(\t r)},{0*0.41*cos(\t r)+1*0.41*sin(\t r)});
  13. \draw [shift={(-1.23,9.81)}] plot[domain=5.15:5.84,variable=\t]({1*4.56*cos(\t r)+0*4.56*sin(\t r)},{0*4.56*cos(\t r)+1*4.56*sin(\t r)});
  14. \draw [shift={(1.04,5.4)}] plot[domain=2.42:5.67,variable=\t]({1*0.42*cos(\t r)+0*0.42*sin(\t r)},{0*0.42*cos(\t r)+1*0.42*sin(\t r)});
  15. \draw [shift={(1.99,4.81)}] plot[domain=-0.94:2.61,variable=\t]({1*0.7*cos(\t r)+0*0.7*sin(\t r)},{0*0.7*cos(\t r)+1*0.7*sin(\t r)});
  16. \draw [shift={(2.96,3.62)}] plot[domain=2.31:3.76,variable=\t]({1*0.83*cos(\t r)+0*0.83*sin(\t r)},{0*0.83*cos(\t r)+1*0.83*sin(\t r)});
  17. \draw [shift={(0.55,1.93)}] plot[domain=-0.69:0.61,variable=\t]({1*2.11*cos(\t r)+0*2.11*sin(\t r)},{0*2.11*cos(\t r)+1*2.11*sin(\t r)});
  18. \draw [shift={(1.93,0.85)}] plot[domain=2.54:5.47,variable=\t]({1*0.37*cos(\t r)+0*0.37*sin(\t r)},{0*0.37*cos(\t r)+1*0.37*sin(\t r)});
  19. \draw [shift={(-0.03,2.08)}] plot[domain=-0.56:0.82,variable=\t]({1*1.94*cos(\t r)+0*1.94*sin(\t r)},{0*1.94*cos(\t r)+1*1.94*sin(\t r)});
  20. \draw [shift={(-0.81,1.41)}] plot[domain=-0.55:0.81,variable=\t]({1*1.87*cos(\t r)+0*1.87*sin(\t r)},{0*1.87*cos(\t r)+1*1.87*sin(\t r)});
  21. \draw [shift={(1.44,0.06)}] plot[domain=2.64:4.9,variable=\t]({1*0.75*cos(\t r)+0*0.75*sin(\t r)},{0*0.75*cos(\t r)+1*0.75*sin(\t r)});
  22. \draw [shift={(1.12,8.63)}] plot[domain=4.76:5.2,variable=\t]({1*9.32*cos(\t r)+0*9.32*sin(\t r)},{0*9.32*cos(\t r)+1*9.32*sin(\t r)});
  23. \draw [shift={(5.17,0.83)}] plot[domain=-0.99:1.43,variable=\t]({1*0.54*cos(\t r)+0*0.54*sin(\t r)},{0*0.54*cos(\t r)+1*0.54*sin(\t r)});
  24. \draw [shift={(5.08,0.53)}] plot[domain=1.38:2.64,variable=\t]({1*0.84*cos(\t r)+0*0.84*sin(\t r)},{0*0.84*cos(\t r)+1*0.84*sin(\t r)});
  25. \end{tikzpicture}
复制代码
不过那个点A为什么没变成scriptsize的大小呢?我记得以前我用tkz-euclide时,加上label style/.style={font=\scriptsize}这个,就能把字母变成小字号了。

TOP

回复 9# abababa

你这个是 node ,和 label 是不同嘀。
可以用 every node/.style={font=\scriptsize}

TOP

回复 9# abababa

你这图编译起来有点慢,用那么多 plot 还需要算三角函数,有点浪费资源了。

用画图那个,画得快就会光滑些,反正这种图又不用画精确。
而且画完后可以编辑,选中它,点 To Curve ,可以调整路径上的点(绿)和控制线(灰)什么的:
QQ截图20210601220126.png
2021-6-1 22:01

其他功能自己摸索一下吧,我也是第一次玩这个。
  1. \tikzset{every picture/.style={line width=0.75pt}} %set default line width to 0.75pt        

  2. \begin{tikzpicture}[x=0.75pt,y=0.75pt,yscale=-1,xscale=1]
  3. %uncomment if require: \path (0,300); %set diagram left start at 0, and has height of 300

  4. %Curve Lines [id:da6706373276390154]
  5. \draw [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round]   (114.6,191.2) .. controls (93.6,178.2) and (84.45,142.55) .. (83.6,124.2) .. controls (82.95,110.29) and (83.65,88.79) .. (89.6,75.2) .. controls (95.81,61.01) and (113.9,48.34) .. (126.6,44.2) .. controls (155.13,34.91) and (200.92,31.83) .. (228.6,51.2) .. controls (251.94,67.54) and (261.03,102.77) .. (261.6,129.2) .. controls (260.6,151.2) and (260.6,175.2) .. (237.6,193.2) ;
  6. %Curve Lines [id:da5618889865772791]
  7. \draw [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round]   (111.6,105.2) .. controls (128.6,81.2) and (151.6,85.2) .. (164.6,103.2) ;
  8. %Curve Lines [id:da0393879878023462]
  9. \draw [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round]   (185.6,102.2) .. controls (199.6,82.2) and (226.6,85.2) .. (236.6,103.2) ;
  10. %Curve Lines [id:da19585522116648368]
  11. \draw [color={rgb, 255:red, 0; green, 0; blue, 0 }  ][line width=3] [line join = round][line cap = round]   (144.6,161.2) .. controls (148.18,163.98) and (160.07,169.93) .. (164.6,170.2) .. controls (187.6,174.2) and (204.6,165.2) .. (217.6,148.2) ;




  12. \end{tikzpicture}
复制代码

TOP

回复 10# kuing

原来如此,以后我把两个都加上,就不用分node或label了。

回复 11# kuing
谢谢,我还是拽不准确,一拽那些点就弄乱了,某个地方就出来一个角,应该是我的图有很多凹凸不平的地方,不像你这个差不多就是圆,to curve的时候没产生那么多控制点。等我以后再试试吧,暂时先用原来的那个。我在想能不能从原图里弄出来直接就生成那种tikz的图,就是上传一个图然后转成这种的。

TOP

回复 12# abababa

重新画吧,手速快些,就好调了。
点可以删除,选中绿点,点上面的 o-

TOP

返回列表 回复 发帖