Forgot password?
 Create new account
View 89|Reply 16

tikz中画克莱因瓶(用pgf)

[Copy link]

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

abababa Posted at 4 days ago |Read mode
Last edited by hbghlyj at ereyesterday 04:01下面的链接给出了一个画法:
tex.stackexchange.com/questions/350924/pgfplo … n-02pi/350932#350932

代码为:
  1. % used PGFPlots v1.14
  2. \RequirePackage{luatex85}
  3. \documentclass[border=5pt]{standalone}
  4. \usepackage{pgfplots}
  5.     \pgfplotsset{
  6.         % use this `compat' level or higher to use the Lua backend
  7.         compat=1.12,
  8.         % used equations and parameters from
  9.         % <https://de.wikipedia.org/w/index.php?title=Kleinsche_Flasche&oldid=160519755#Beschreibung_im_3-dimensionalen_Raum>
  10.         /pgf/declare function={
  11.             b = 2;
  12.             h = 6;
  13.             r(\u) = 2 - cos(\u);
  14. %            x(\u,\v) = b * (1 - sin(\u)) * cos(\u);
  15. %                       + r(\u) * cos(\v) * (2 * exp( -(\u/2 - pi)^2 ) - 1);
  16. %            y(\u,\v) = r(\u) * sin(\v);
  17. %            z(\u,\v) = h * sin(\u)
  18. %                       + 0.5 * r(\u) * sin(\u) * cos(\v) * exp( -(\u-3*pi/2)^2 );
  19.         },
  20.     }
  21. \begin{document}
  22.     \begin{tikzpicture}
  23.         \begin{axis}[
  24. %            axis lines=none,
  25.             % use radians as input for the trigonometric functions
  26.             % (this avoids converting the numbers to `deg' format first)
  27.             trig format plots=rad,
  28.             domain=0:2*pi,
  29.             samples=50,
  30.             % change variables from `x' and `y' to `u' and `v'
  31.             variable=u,
  32.             variable y=v,
  33.             colormap/viridis,
  34.         ]
  35.             \addplot3 [
  36. %                mesh,
  37.                 % I use suf here, because it just looks better ;)
  38.                 surf,
  39.                 z buffer=sort,
  40.                 fill opacity=0.35,
  41.             ] (
  42.                 % unfortunately these give an error ...
  43. %                {x(u,v)},
  44. %                {y(u,v)},
  45. %                {z(u,v)},
  46.                 % ... so we write them directly
  47.                 {b * (1 - sin(u)) * cos(u) + r(u) * cos(v) * (2 * exp( -(u/2 - pi)^2 ) - 1)},
  48.                 {r(u) * sin(v)},
  49.                 {h * sin(u) + 0.5 * r(u) * sin(u) * cos(v) * exp( -(u - 3 * pi / 2)^2 )}
  50.             );
  51.         \end{axis}
  52.     \end{tikzpicture}
  53. \end{document}
Copy the Code


但我画出来的和链接里的图不一样:

这个要怎么做才能画出链接里那种呢?

701

Threads

110K

Posts

910K

Credits

Credits
94160
QQ

Show all posts

kuing Posted at 4 days ago
需要用 LuaLaTeX 编译

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 4 days ago
kuing 发表于 2025-4-15 16:58
需要用 LuaLaTeX 编译
原来如此,那用xelatex编译的话,要怎么改那些东西才能效果一样呢?

Comment

不了解😥  Posted at 4 days ago

1

Threads

101

Posts

1753

Credits

Credits
1753

Show all posts

Aluminiumor Posted at 4 days ago
  1. \RequirePackage{luatex85}
Copy the Code

这个包是专门为 LuaLaTeX 设计的,恐怕不好改。
反正更换编译器很方便的。

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 4 days ago
Aluminiumor 发表于 2025-4-15 19:45
这个包是专门为 LuaLaTeX 设计的,恐怕不好改。
反正更换编译器很方便的。 ...
换xelatex编译,结果就不一样了,就是主楼里我上传的那个图,那个就是xelatex编译出的结果,和链接里的图完全不同

1

Threads

101

Posts

1753

Credits

Credits
1753

Show all posts

Aluminiumor Posted at 4 days ago
abababa 发表于 2025-4-15 19:47
换xelatex编译,结果就不一样了,就是主楼里我上传的那个图,那个就是xelatex编译出的结果,和链接里的图 ...
我的意思是在你的编辑器设置中将编译程序设置为lualatex再编译,这样效果就一样了,我试过了。

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 4 days ago
Aluminiumor 发表于 2025-4-15 19:54
我的意思是在你的编辑器设置中将编译程序设置为lualatex再编译,这样效果就一样了,我试过了。 ...
我不只编译这一个啊,这只是我想用的一个图,用lualatex的话,别的东西编译不通过啊

701

Threads

110K

Posts

910K

Credits

Credits
94160
QQ

Show all posts

kuing Posted at 4 days ago
abababa 发表于 2025-4-15 20:08
我不只编译这一个啊,这只是我想用的一个图,用lualatex的话,别的东西编译不通过啊。 ...
就把那生成的 PDF 用插图的方式插入到你的主文档中就是了。

况且这图运行时间比较长,不论能不能改成 xelatex,也应该用插图的方式,不然你会浪费很多时间在编译上,除非你的主文档只编译一两次。

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 4 days ago
kuing 发表于 2025-4-15 20:24
就把那生成的 PDF 用插图的方式插入到你的主文档中就是了。

况且这图运行时间比较长,不论能不能改成 xel ...
慢的地方都用\iffalse \fi注释掉了,等都做完了,最后编译时编译一次就成了。

目前是找了一个别的图弄上的,也很复杂:
  1. \begin{tikzpicture}
  2. \begin{axis}[
  3.         hide axis,
  4.         view={40}{40},
  5.         rotate around={90:(current axis.origin)}
  6. ]
  7. \addplot3[
  8.         surf,
  9.         point meta=x,opacity=0.5,
  10.         colormap/greenyellow,
  11.         samples=25,
  12.         samples y=25,
  13.         z buffer=sort,
  14.         domain=0:180,
  15.         domain y=0:360
  16. ](
  17.         {-2/15*cos(x)*(3*cos(y)-30*sin(x)+90*cos(x)^4*sin(x)-60*cos(x)^6*sin(x)+5*cos(x)*cos(y)*sin(x))},
  18.         {
  19.          -1/15*sin(x)*(3*cos(y)-3*cos(x)^2*cos(y)-48*cos(x)^4*cos(y)+48*cos(x)^6 *cos(y)
  20.          -60 *sin(x)+5*cos(x)*cos(y)*sin(x)-5*cos(x)^3*cos(y)*sin(x)-80*cos(x)^5*cos(y)*sin(x)
  21.          +80*cos(x)^7*cos(y)*sin(x))
  22.         },
  23.         {2/15*(3+5*cos(x)*sin(x))*sin(y)}      
  24. );
  25. \end{axis}
  26. \end{tikzpicture}
Copy the Code

而且那个转90度的,转完了位置就偏右了,不在中间了

701

Threads

110K

Posts

910K

Credits

Credits
94160
QQ

Show all posts

kuing Posted at 4 days ago
abababa 发表于 2025-4-15 20:28
慢的地方都用\iffalse \fi注释掉了,等都做完了,最后编译时编译一次就成了。

目前是找了一个别的图弄上 ...
那插图又有什么不好的呢?🤔

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at 4 days ago
kuing 发表于 2025-4-15 20:30
那插图又有什么不好的呢?🤔
插图要弄个图片在一边,觉得不好管理,这个编译出来是矢量的吧,还能放大不失真啥的。

701

Threads

110K

Posts

910K

Credits

Credits
94160
QQ

Show all posts

kuing Posted at 4 days ago
abababa 发表于 2025-4-15 20:33
插图要弄个图片在一边,觉得不好管理,这个编译出来是矢量的吧,还能放大不失真啥的。 ...
插入 PDF 也是矢量不失真的啊。

Comment

原来如此,还以为插入图片就是像那种放大了就变成像素点的图了。  Posted at 4 days ago

3150

Threads

8482

Posts

610K

Credits

Credits
66119
QQ

Show all posts

hbghlyj Posted at ereyesterday 02:52
abababa 发表于 2025-4-15 09:45
但我画出来的和链接里的图不一样:

我知道了,把declare function中的 r(\u) = 2 - cos(\u); 替换后面即可:

701

Threads

110K

Posts

910K

Credits

Credits
94160
QQ

Show all posts

kuing Posted at ereyesterday 02:56
hbghlyj 发表于 2025-4-17 02:52
我知道了,把declare function中的 r(\u) = 2 - cos(\u); 替换后面即可:
(虽然我不懂……

418

Threads

1627

Posts

110K

Credits

Credits
11885

Show all posts

 Author| abababa Posted at ereyesterday 14:33
hbghlyj 发表于 2025-4-17 02:52
我知道了,把declare function中的 r(\u) = 2 - cos(\u); 替换后面即可:
原来如此

手机版Mobile version|Leisure Math Forum

2025-4-19 17:39 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list