找回密码
 快速注册
搜索
查看: 573|回复: 83

学习Asymptote时的一些问题

[复制链接]

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

abababa 发表于 2023-3-9 20:14 |阅读模式
现在要弄一些关于圆锥曲线的题,感觉原来的tikz不是特别方便,想学学Asymptote这个,但使用时有很多问题弄不明白。

  1. \begin{asydef}
  2. settings.prc=true;
  3. import three;
  4. import math;
  5. import geometry;
  6. import texcolors;
  7. \end{asydef}
  8. \begin{asy}
  9. size(4cm,0);
  10. pen g=blue+linewidth(1);
  11. pair A=(3,0);
  12. pair O=(0,0);
  13. pair B=rotate(45, O, A);
  14. dot(O, p=g);
  15. dot(B, p=g);
  16. drawline(O,A, p=g);
  17. label("$O$",O,p=g,align=SW);
  18. label("$A$",A,p=red,align=SE);
  19. //label("$B$",B,p=red,align=SE);
  20. \end{asy}
复制代码


代码如上所示,我目前有三个问题:
一是画点的名称时,用label,然后方位怎么定?比如我代码中是想让O点在它的西南方位,可画出来不是这样的,这个要怎么做?
二是旋转怎么做,我代码中的意图是想把A点绕O点逆时针旋转45度,得到B点,但编译时出错了,应该是我写的不对吧,请问正确的要怎么做?
三是那个O,A的名称,画出来时感觉字号都很大,这个怎么才能统一调整一下字号(只在这个图的环境里,不涉及正文的字号)?

点评

建议帖子加Asymptote标签  发表于 2023-3-10 19:41
之前Asymptote的帖子被移动到其他软件区了  发表于 2023-3-10 19:41
回复 @hbghlyj 我也考虑过移,不过看起来楼主好像是放在 LaTeX 环境里用的所以就没移(其实我也不是很了解这些)  发表于 2023-3-10 20:14

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-10 17:48
hbghlyj 发表于 2023-3-9 20:25
currentpen=fontsize(0.5cm)

是的,这个找到了,可以在pen p=blue后面用加号连起来:pen p=blue+fontsize(1);然后就能画带颜色、带粗细的线了。
前两个怎么解决?

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-10 18:36
hbghlyj 发表于 2023-3-10 18:01
画出来标签在西南

这个画出来,不在西南啊,如图:
QQ截图20230310183528.jpg

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-10 18:37

这个乘法的,我在文档里看到了,只能绕原点旋转,但我要绕固定点旋转,还要做加法吗?

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-10 19:34
abababa 发表于 2023-3-10 11:36
这个画出来,不在西南啊,如图:

在西南啊,如图:
size(4cm,0);
pen g=blue+linewidth(1);
pair O=(0,0);
pair A=(3,0);
draw(A--O);
dot(O, p=g);
label("$O$",O,p=g,align=SW);

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2023-3-10 21:08
问题在于 drawline(O,A); 和 draw(O--A); 是不一样的。

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-10 21:26
kuing 发表于 2023-3-10 14:08
问题在于 drawline(O,A); 和 draw(O--A); 是不一样的。


drawline需要import math; 吧
size(4cm,0);
pen g=blue+linewidth(2);
pair O=(0,0);
pair A=(3,0);
draw(box(O,(3,3)),p=invisible);
import math;drawline(A,O);
dot(O, p=g);
label("$O$",O,p=g,align=SW);

drawline没有align吧
是指label的align吧
改成drawline后仍然在西南

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-10 21:29
abababa 发表于 2023-3-10 11:37
但我要绕固定点旋转,还要做加法吗? ...


文档

transform rotate(real angle, pair z=(0,0));

    rotates by angle in degrees about z;

730

主题

1万

回帖

9万

积分

积分
93593
QQ

显示全部楼层

kuing 发表于 2023-3-10 21:29
hbghlyj 发表于 2023-3-10 21:26
drawline需要import math; 吧

drawline没有align吧


我想说的是 drawline 作的是过两点的直线(而非两点之间的连线(段)),导致楼主所看到的线的端点其实并不是 O 和 A,于是误以为是 label 方位出了错。

size(4cm,0);
pen g=blue+linewidth(2);
pen h=red+linewidth(4);
pair O=(0,0);
pair A=(3,0);
pair B=(0,1);
pair C=(3,1);
draw((-2,-1)--(5,2),p=invisible);
import math;
drawline(A,O);
label("$O$",O,p=g,align=SW);
label("$A$",A,p=g,align=SE);
draw(B--C);
label("$B$",B,p=g,align=NW);
label("$C$",C,p=g,align=NE);
dot(O,p=h);dot(A,p=h);dot(B,p=h);dot(C,p=h);

上图先 draw((-2,-1)--(5,2),p=invisible); 作一条隐藏线撑大可视区域,然后 drawline(A,O); draw(B--C);

点评

哦! 我明白了  发表于 2023-3-10 21:30

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-10 21:34
kuing 发表于 2023-3-10 13:14
不过看起来楼主好像是放在 LaTeX 环境里用的所以就没移(其实我也不是很了解这些)

但是本帖的问题不是 LaTeX 的问题,是Asymptote本身的问题
另外点评@用户不能提醒到用户 但在StackExchange 评论@用户能提醒到用户

点评

现在知道问题所在了,刚才我并不确定是否和 LaTeX 有关,所以这样说。  发表于 2023-3-10 21:47

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-11 20:32
kuing 发表于 2023-3-10 21:08
问题在于 drawline(O,A); 和 draw(O--A); 是不一样的。

原来如此,弄成draw就好了。
旋转那个也弄明白了:
pair B=rotate(45,O)*A;//将点A绕点O逆时针旋转45度,所得点定义为点B

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-11 21:14
发现geometry里有很多命令是和point有关的,那定义点的时候,直接定义成point也行吧?比如这样:
point A=(point)(3,0);

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-13 21:05
abababa 发表于 2023-3-11 21:14
发现geometry里有很多命令是和point有关的,那定义点的时候,直接定义成point也行吧?比如这样:
point A=( ...

画交点时可能超出图的边界了,代码如下:

  1. \begin{asy}
  2. point A=(3,0)
  3. point O=(0,0);
  4. point B=rotate(-40,O)*A;
  5. point C=rotate(-160,O)*A;
  6. point D=rotate(50,O)*A;
  7. segment AB=segment(A,B);
  8. segment AC=segment(A,C);
  9. segment AD=segment(A,D);
  10. segment BC=segment(B,C);
  11. segment BD=segment(B,D);
  12. segment CD=segment(C,D);
  13. point M=intersectionpoint(AB,CD);
  14. point N=intersectionpoint(AD,BC);
  15. label("$M$",M, p=blue,align=SE);
  16. \end{asy}
复制代码


编译时出现下面的警告:
warning [unbounded]: x scaling in picture unbounded
warning [unbounded]: y scaling in picture unbounded

然后图画不出来。意思可能是这个图超出边界了吧,这个要怎么弄才行?

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-13 21:15
abababa 发表于 2023-3-13 14:05
画交点时可能超出图的边界了,代码如下:

point A=(3,0)后面没有;
intersectionpoint两条线段没有交点
size(200);
import geometry;
point A=(3,0);
point O=(0,0);
point B=rotate(-40,O)*A;
point C=rotate(-160,O)*A;
point D=rotate(50,O)*A;
draw(A--B--C--D--cycle);
point M=extension(A,B,C,D);
dot(M);
draw(D--M--A,dashed);
currentpen=blue;
label("$M$",M,NE);
label("$A$",A,E);
label("$B$",B,S);
label("$C$",C,W);
label("$D$",D,N);

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-14 17:20
hbghlyj 发表于 2023-3-13 21:15
后面没有
两条线段没有交点

原来如此,换了这个就好了。

现在还有一个新问题,就是标签的时候:
label("$M$",M, p=blue,align=N);

但这个N已经在前面定义成点了,在这里就用不了它,这个在北方的要怎么写才行呢?

点评

(0,1)  发表于 2023-3-14 17:22
原来如此,感觉还是字符型的好用,不会重复。  发表于 2023-3-15 15:04

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-15 15:05
对于圆锥曲线C和一点P,想作点P关于C的极线,要怎么弄?
其实最开始只想画出准线,就是焦点的极线,这个容易弄,但想画更一般的,而且感觉这个用得也挺多。

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-15 17:30
我看到1#写了settings.prc=true;应该是为了在Acrobat reader中可以旋转视角吧
这里说同时要写settings.embed=true;这句?

413

主题

1558

回帖

1万

积分

积分
11498

显示全部楼层

 楼主| abababa 发表于 2023-3-15 19:37
hbghlyj 发表于 2023-3-15 17:30
我看到1#写了应该是为了在Acrobat reader中可以旋转视角吧
而这里说同时要写这句? ...

我也不知道这些有什么用,反正目的就是能编译通过,生成正确的pdf就行了。
今天问了网友,他还把那些命令(函数?)都重新定义了一遍,和tkz-euclide的名称兼容,不过我觉得tkzInterLL,tkzInterLC,tkzInterCC这些命令确实又直观又简短。

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-15 20:07


abababa 发表于 2023-3-15 12:37
我也不知道这些有什么用,反正目的就是能编译通过,生成正确的pdf就行了。 今天问了网友,他还把那些命令 ...
只为了生成正确的pdf, 那么不需要嵌入3d数据settings.prc=true;three.asy - prc
Embed the 3D PRC format in a PDF file and view the resulting PDF file with version 9.0 or later of Adobe Reader. This requires settings.outformat="pdf" and settings.prc=true, which can be specified by the command-line options -f pdf and -f prc, put in the Asymptote configuration file (see configuration file), or specified in the script before module three (or graph3) is imported. The media9 LaTeX package is also required (see embed). The example 100d.asy illustrates how one can generate a list of predefined views (see 100d.views). A stationary preview image with a resolution of n pixels per bp can be embedded with the setting render=n; this allows the file to be viewed with other PDF viewers. Alternatively, the file externalprc.tex illustrates how the resulting PRC and rendered image files can be extracted and processed in a separate LaTeX file. However, see LaTeX usage for an easier way to embed three-dimensional Asymptote pictures within LaTeX. For specialized applications where only the raw PRC file is required, specify settings.outformat="prc". The PRC specification is available from https://web.archive.org/web/20081204104459/http://livedocs.adobe.com/acrobat_sdk/9/Acrobat9_HTMLHelp/API_References/PRCReference/PRC_Format_Specification/

3149

主题

8386

回帖

6万

积分

$\style{scale:11;fill:#eff}꩜$

积分
65391
QQ

显示全部楼层

hbghlyj 发表于 2023-3-15 20:11
abababa 发表于 2023-3-15 12:37
不过我觉得tkzInterLL,tkzInterLC,tkzInterCC这些命令确实又直观又简短。


tkzInterLLtkzInterLCtkzInterCC都对应于Asymptote的intersectionpoints吗?

手机版|悠闲数学娱乐论坛(第3版)

GMT+8, 2025-3-4 12:04

Powered by Discuz!

× 快速回复 返回顶部 返回列表