Forgot password?
 Create new account
Author: abababa

学习Asymptote时的一些问题

[Copy link]

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-4 18:35:29
hejoseph 发表于 2023-4-4 17:36
我这里没问题,不知道你那里什么问题。ASY嵌入文档的应该是my-1_0.pdf这个文件吧。
如果你只是插图完全可 ...
下面的代码my.tex:
  1. \documentclass[12pt]{article}
  2. \usepackage{amsmath,bm,yhmath,amssymb,etoolbox,esvect,stmaryrd,cite,enumitem,extarrows,mathtools,ifthen}
  3. \usepackage[amsmath, thmmarks]{ntheorem}
  4. {
  5.         \theoremstyle{nonumberplain}
  6.         \theoremheaderfont{\indent\bfseries}
  7.         \theorembodyfont{\normalfont}
  8.         \theoremsymbol{\ensuremath{\Box}}
  9.         \newtheorem{proof}{证明}
  10. }
  11. \usepackage{pgf,tikz}
  12. \usepackage[inline]{asymptote}
  13. \usepackage{float}
  14. \usepackage{pgfplots,wrapfig}
  15. \usepackage{graphicx}
  16. \usepackage{subfigure}
  17. \usepackage{tkz-euclide}
  18. \usetikzlibrary{arrows,automata,positioning,matrix,calc,intersections,shapes.geometric}
  19. \begin{document}
  20. \begin{asy}
  21. settings.outformat = "pdf";
  22. settings.prc = false;
  23. size(5cm,0);
  24. import three;
  25. draw(unitsphere);
  26. //axes3("$x$","$y$","$z$",Arrow3);
  27. \end{asy}
  28. try.
  29. \end{document}
Copy the Code


我先xelatex my.tex,出现一个警告:
  1. Package asymptote Warning: file `my-1.tex' not found on input line 31.
Copy the Code


我觉得是还没编译asy文件的原因。之后用asy *.asy,出现下面的错误:
  1. shipout3(prefix,f,preview ? nativeformat() : format,
Copy the Code


这个错误之前一直存在,我以为升级版本就好了,但并没有。按照39楼链接里的说明,把settings.outformat = "pdf";里的pdf改成html,这时重复上面的编译,asy *.asy之后,出现了一个my-1.html,这个网页文件里就有那个图。这时再用xelatex my.tex,期望是把那个图弄进my.pdf里,但是出现警告:
  1. Package asymptote Warning: file `my-1.tex' not found on input line 31
Copy the Code


图也没有进到my.pdf里。

而之前的平面图,我没有设置outformat,它就是在当前文件夹里生成了一堆图片的pdf,最后进到总的my.pdf里。

我想既然学了这个能画立体图的asymptote,就试着画几个简单的。

Comment

outputformat不是pdf无法嵌入文档的,检查下你的路径设置有没有设置对,另外看看temp那个目录是否有中文字符。  Posted at 2023-4-6 10:20

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-4 20:50:26
abababa 发表于 2023-4-4 18:35
下面的代码my.tex:
发现加上这一句settings.render=0;就好了,也不用什么outformat之类的,新的代码如下:
  1. \begin{asy}
  2. settings.render=0;
  3. import three;
  4. import graph3;
  5. size(5cm,0);
  6. draw(unitsphere);
  7. \end{asy}
Copy the Code


虽然画出来的那个球是全黑的,可能还是有问题,但我感觉单纯地画线应该没问题了。

Comment

render=0会出现问题的,3D图形没法消隐,出来的图可能问题很大,特别是面交错的图形。  Posted at 2023-4-6 10:19

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-5 19:25:12
对于3D的,过一点作一条直线的垂线,垂足要怎么画?例如:
  1. \begin{asy}
  2. settings.render=0;
  3. import three;
  4. import graph3;
  5. size(5cm,0);
  6. triple A1 = (1,sqrt(1/3),sqrt(8/3)), A3 = (2,0,0), A4 = (1,sqrt(3),0);
  7. \end{asy}
Copy the Code


想画过A1垂直于A3A4的直线的垂足。

我查了three.asy,有几个project的,弄出来都不是。

Comment

这种我一般用自己写的函数直接调用就得了  Posted at 2023-4-6 10:32

67

Threads

435

Posts

4269

Credits

Credits
4269

Show all posts

hejoseph Posted at 2023-4-6 14:14:42
Last edited by hbghlyj at 2025-4-10 05:47:40关于render=0的问题,你可以试试运行下这个asy代码:

正常情况下应该输出下图

render=0会输出下图,这是因为没法正确消隐

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-6 15:39:10
hejoseph 发表于 2023-4-6 14:14
关于render=0的问题,你可以试试运行下这个asy代码:
size(200);
import graph3;
shipout3(prefix,f,preview ? nativeformat() : format,

上面这个错误,好像和显卡有关,我昨天发给网友,他那里也是这个问题,没能弄出pdf来,但生成html的那个都是好的。我搜索这个,发现还是有人遇到相同的问题:
linux.debian.bugs.dist.narkive.com/CzpDhAUs/b … te-error-in-shipout3

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-6 16:22:50
abababa 发表于 2023-4-5 19:25
对于3D的,过一点作一条直线的垂线,垂足要怎么画?例如:
我知道那个怎么算,但是想弄个一般的,现在点是用triple定义的,直线怎么定义不知道。
点$(x_0,y_0,z_0)$到点$(x_1,y_1,z_1), (x_2,y_2,z_2)$所成直线的垂足坐标为
\[(k(x_2-x_1)+x_1, k(y_2-y_1)+y_1, k(z_2-z_1)+z_1)\]

其中
\[k=\frac{(x_1-x_0)(x_2-x_1)+(y_1-y_0)(y_2-y_1)+(z_1-z_0)(z_2-z_1)}{(x_2-x_1)^2+(y_2-y_1)^2+(z_2-z_1)^2}\]

Comment

空间直线一般两种表达方式:点和方向向量,两平面方程。你如果做一般的,自己做一个文件,需要的时候引入就行了。  Posted at 2023-4-6 16:27

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-7 07:53:10
abababa 发表于 2023-3-27 11:24
这个在我这里运行,出现以下问题:
shipout3(prefix,f,preview ? nativeformat() : format,

若本机总是不行, 可以使用Asymptote Web Application [output选择pdf]
如果PDF需要嵌入PRC可以使用Asymptote server的command-line interface
  1. curl --data-binary 'import teapot;' 'asymptote.ualberta.ca:10007?f=pdf&prc' -o teapot.pdf
Copy the Code


ASY-Forum

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-7 16:58:47
Last edited by hbghlyj at 2023-4-7 17:25:00
abababa 发表于 2023-4-3 14:27
搜索到两个类似的:
根据John Bowman用下面的命令编译
  1. ./configure --disable-gc
  2. make clean
  3. make CFLAGS=-g
Copy the Code

gdb --args asy 1.asy检查
  1. Starting program: /usr/local/bin/asy 1.asy
  2. [Thread debugging using libthread_db enabled]
  3. Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
  4. Program received signal SIGSEGV, Segmentation fault.
  5. 0x00005555558f2066 in GC_find_limit_with_bound (p=0x555555ac04a8 "",
  6.     up=up@entry=0, bound=bound@entry=0x0) at os_dep.c:1018
  7. 1018                    GC_noop1((word)(*result));
Copy the Code

用valgrind检查
  1. valgrind --track-origins=yes asy test
Copy the Code
输出有很多. 最后几行是
  1. ==35368==
  2. ==35368== Conditional jump or move depends on uninitialised value(s)
  3. ==35368==    at 0x49D2CA: GC_find_header (headers.c:32)
  4. ==35368==    by 0x4A186C: GC_mark_and_push_stack (mark.c:1487)
  5. ==35368==    by 0x4A1931: GC_push_all_eager (mark.c:1589)
  6. ==35368==    by 0x4AF158: GC_with_callee_saves_pushed (mach_dep.c:335)
  7. ==35368==    by 0x4A259C: GC_push_regs_and_stack (mark_rts.c:853)
  8. ==35368==    by 0x4A259C: GC_push_roots (mark_rts.c:926)
  9. ==35368==    by 0x4A0F67: GC_mark_some (mark.c:388)
  10. ==35368==    by 0x498004: GC_stopped_mark (alloc.c:880)
  11. ==35368==    by 0x498FBE: GC_try_to_collect_inner (alloc.c:626)
  12. ==35368==    by 0x499ECC: GC_collect_or_expand (alloc.c:1678)
  13. ==35368==    by 0x49A214: GC_allocobj (alloc.c:1784)
  14. ==35368==    by 0x49E09E: GC_generic_malloc_inner (malloc.c:194)
  15. ==35368==    by 0x49E2C0: GC_generic_malloc (malloc.c:254)
  16. ==35368==  Uninitialised value was created by a stack allocation
  17. ==35368==    at 0x4AF0C1: GC_with_callee_saves_pushed (mach_dep.c:229)
  18. ==35368==
  19. ==35368==
  20. ==35368== More than 100 errors detected.  Subsequent errors
  21. ==35368== will still be recorded, but in less detail than before.
  22. ==35368== Use of uninitialised value of size 8
  23. ==35368==    at 0x49D2F7: GC_find_header (headers.c:33)
  24. ==35368==    by 0x4A186C: GC_mark_and_push_stack (mark.c:1487)
  25. ==35368==    by 0x4A1931: GC_push_all_eager (mark.c:1589)
  26. ==35368==    by 0x4AF158: GC_with_callee_saves_pushed (mach_dep.c:335)
  27. ==35368==    by 0x4A259C: GC_push_regs_and_stack (mark_rts.c:853)
  28. ==35368==    by 0x4A259C: GC_push_roots (mark_rts.c:926)
  29. ==35368==    by 0x4A0F67: GC_mark_some (mark.c:388)
  30. ==35368==    by 0x498004: GC_stopped_mark (alloc.c:880)
  31. ==35368==    by 0x498FBE: GC_try_to_collect_inner (alloc.c:626)
  32. ==35368==    by 0x499ECC: GC_collect_or_expand (alloc.c:1678)
  33. ==35368==    by 0x49A214: GC_allocobj (alloc.c:1784)
  34. ==35368==    by 0x49E09E: GC_generic_malloc_inner (malloc.c:194)
  35. ==35368==    by 0x49E2C0: GC_generic_malloc (malloc.c:254)
  36. ==35368==  Uninitialised value was created by a stack allocation
  37. ==35368==    at 0x4AF0C1: GC_with_callee_saves_pushed (mach_dep.c:229)
  38. ==35368==
  39. ==35437==
  40. ==35437== HEAP SUMMARY:
  41. ==35437==     in use at exit: 3,281,028 bytes in 15,961 blocks
  42. ==35437==   total heap usage: 303,368 allocs, 287,407 frees, 78,911,078 bytes allocated
  43. ==35437==
  44. ==35437== LEAK SUMMARY:
  45. ==35437==    definitely lost: 2,725,919 bytes in 6,671 blocks
  46. ==35437==    indirectly lost: 360 bytes in 3 blocks
  47. ==35437==      possibly lost: 0 bytes in 0 blocks
  48. ==35437==    still reachable: 554,749 bytes in 9,287 blocks
  49. ==35437==         suppressed: 0 bytes in 0 blocks
  50. ==35437== Rerun with --leak-check=full to see details of leaked memory
  51. ==35437==
  52. ==35437== For lists of detected and suppressed errors, rerun with: -s
  53. ==35437== ERROR SUMMARY: 640245 errors from 101 contexts (suppressed: 0 from 0)
  54. ==35368==
  55. ==35368== HEAP SUMMARY:
  56. ==35368==     in use at exit: 1,050,411 bytes in 11,466 blocks
  57. ==35368==   total heap usage: 210,055 allocs, 198,589 frees, 8,857,023 bytes allocated
  58. ==35368==
  59. ==35368== LEAK SUMMARY:
  60. ==35368==    definitely lost: 853,760 bytes in 6,670 blocks
  61. ==35368==    indirectly lost: 0 bytes in 0 blocks
  62. ==35368==      possibly lost: 0 bytes in 0 blocks
  63. ==35368==    still reachable: 196,651 bytes in 4,796 blocks
  64. ==35368==         suppressed: 0 bytes in 0 blocks
  65. ==35368== Rerun with --leak-check=full to see details of leaked memory
  66. ==35368==
  67. ==35368== For lists of detected and suppressed errors, rerun with: -s
  68. ==35368== ERROR SUMMARY: 640245 errors from 101 contexts (suppressed: 0 from 0)
Copy the Code

没有懂

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-7 18:21:47
hbghlyj 发表于 2023-4-7 07:53
若本机总是不行, 可以使用Asymptote Web Application [output选择pdf]
如果PDF需要嵌入PRC可以使用Asympto ...
不想用那么多工具,要不是为了画圆锥曲线方便点,我就不学这个asymptote了,用tkz-euclide就很好。

Comment

如果不是画3D图估计生成pdf不会有问题  Posted at 2023-4-7 22:01

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-9 05:00:27
abababa 发表于 2023-4-6 08:39
上面这个错误,好像和显卡有关
我昨天这个问题:
sourceforge.net/p/asymptote/discussion/409349/thread/ca9f0b6278/
John Bowman told me to upgrade graphic drivers:
OpenGL GLSL version 1.40 is very old (circa 2009). For full functionality (e.g. transparency) you will need to upgrade to GLSL 4.3 or later (which dates back to 2013). You should upgrade your drivers.

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-9 21:33:02
Last edited by hbghlyj at 2023-4-10 11:50:00
abababa 发表于 2023-4-6 08:39
好像和显卡有关...

编译 Vulkan 时出错
汇编消息:
  1. {standard input}: Assembler messages:
  2. {standard input}:310129: Warning: end of file not at end of a line; newline inserted
  3. {standard input}:310173: Error: unknown pseudo-op: `.lvl261'
  4. {standard input}: Error: open CFI at the end of file; missing .cfi_endproc directive
  5. cc: fatal error: Killed signal terminated program cc1
Copy the Code
嗯,根据 stackoverflow.com/a/25584112,看起来这可能是构建期间内存不足的情况?需要终止其他进程以释放内存。
重新编译多次,终于成功了。

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-10 18:52:35
abababa 发表于 2023-4-6 08:39
好像和显卡有关...

我在 Centos 8 上的错误消息是类似的。
昨天发到Asymptote Discussion
sourceforge.net/p/asymptote/discussion/409349/thread/ca9f0b6278/
John Bowman - 6 hours ago
Under your platform there is a problem with OSMesa initialization. CentOS tends to use very old software. CentOS 8.5.2111 was released sometime ago, in November 2021 and CentOS was subsequently discontinued. Try upgrading to a newer OS.
需要升级操作系统。

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-11 00:47:10
abababa 发表于 2023-4-6 08:39
shipout3(prefix,f,preview ? nativeformat() : format,

上面这个错误,好像和显卡有关,我昨天发给网友 ...
升级到Ubuntu 22.04.2 LTS后编译freeglut和asymptote,根据此讨论设置 gs 路径,尝试渲染3D图形,报错
    shipout3(prefix,f,preview ? nativeformat() : format,
            ^
/usr/local/share/asymptote/three.asy: 2896.13: runtime: to support onscreen OpenGL rendering; please install the glut library, then ./configure; make
因为我已经根据官方文档编译安装了freeglut 3.2.1,所以只需要安装libglm-dev
  1. apt-get install libglm-dev
Copy the Code
上述错误消失了。出现新错误:
freeglut (asy): failed to open display ''

Putty设置“X display location=:0”后,“xeyes”和“xclock”运行成功 Quicker_20230410_183738.png
出现新错误:
X Error of failed request:  GLXUnsupportedPrivateRequest
  Major opcode of failed request:  143 (GLX)
  Minor opcode of failed request:  17 (X_GLXVendorPrivateWithReply)
  Serial number of failed request:  24
  Current serial number in output stream:  24

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-14 02:25:20
Last edited by hbghlyj at 2023-4-15 12:50:00Floating-point unit 浮点运算器
A floating-point unit is a part of a computer system specially designed to carry out operations on floating-point numbers. Typical operations are addition, subtraction, multiplication, division, and square root.

FP exceptions GNU libc
The IEEE 754 standard defines five exceptions that can occur during a calculation. Each corresponds to a particular sort of error, such as overflow.

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-15 19:42:13
hbghlyj 发表于 2023-4-14 02:25
试一下
the -mask command-line option  Mask fpu exceptions
加上这个-mask,编译那个最简单的球的那个,就是draw(unitsphere);,这个出来了,而且也是有点立体感的那个球,不是像平面图那样的。其它的还不知道会不会有问题。

Comment

帖内代码建议使用[inlinecode]  Posted at 2023-4-15 19:54

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-15 19:46:01
可以试一下47# hejoseph的代码看输出是否和左图一致.
可以把-mask保存在config.asy中, 就不必每次都加-mask

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-15 20:55:59
hbghlyj 发表于 2023-4-15 19:46
可以试一下47# hejoseph的代码看输出是否和左图一致.
可以把-mask保存在config.asy中, 就不必每次都加-ma ...
47楼的那个,仅用import graph3;是正常的,前面加一个import three;就出问题了。

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-15 21:07:02
abababa 发表于 2023-4-15 13:55
47楼的那个,仅用import graph3;是正常的,前面加一个import three;就出问题了。

asymptote.ualberta.ca 仅用import graph3;import three;是正常的,一并用也正常

418

Threads

1627

Posts

110K

Credits

Credits
11886

Show all posts

 Author| abababa Posted at 2023-4-15 21:33:11
hbghlyj 发表于 2023-4-15 21:07
试 http://asymptote.ualberta.ca 仅用或是正常的,一并用也正常
我这里后来也没问题了,不知道怎么回事,代码我就改了这一句,但是后来手动把那些.asy,.pre等文件都删除了。

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-4-15 21:53:31
Last edited by hbghlyj at 2023-4-16 13:25:00Asymptote forum
Could you run without -mask in the debugger (e.g. gdb) and tell me which library call in glrender.cc the floating point exception is generating the floating point exception? Once we identify the line number we can locally apply the mask like this (there might be more than one place):
  1. fpu_trap(false); // Work around FE_INVALID
  2. // offending call goes here
  3. fpu_trap(settings::trap());
Copy the Code

手机版Mobile version|Leisure Math Forum

2025-4-20 12:21 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list