Forgot password?
 Create new account
View 97|Reply 0

绘制平面几何图形

[Copy link]

3148

Threads

8489

Posts

610K

Credits

Credits
66148
QQ

Show all posts

hbghlyj Posted at 2023-5-12 16:24:27 |Read mode
Last edited by hbghlyj at 2025-3-24 01:35:55在 Geometry.asy 的基础上
  1. import geometry;
Copy the Code

默认的垂直符号太大了,减小一点
  1. markangleradiusfactor /= 3;
Copy the Code

平面几何作图需要对大量的点添加标签,做这个初始化表是为了解决这个问题,虽然有点丑,但可以实现.
此(string)能返回变量名字,可以简化很多标签的工作
  1. point[] p={A,B,C,D,E,F,X,Y,Z,M,N};
  2. for(int i=0;i<p.length;++i){
  3.   dot(p[i],(string)p[i]);
  4. }
Copy the Code

返回与直线AB切于A且过C的圆
  1. circle tangentABC(point A,point B,point C)
  2. {
  3.         point B2=scale(length(B-A)^2/length(B-C)^2,B)*C;
  4.         return circle(B2,A,C);
  5. }
Copy the Code

A在BC上的投影
  1. point foot(point A,point B,point C)
  2. {
  3.         return projection(line(B,C))*A;
  4. }
Copy the Code

A在圆c上,求直线AB与圆c的另外一个交点
  1. point intersectionpoint(circle c,point A,point B)
  2. {
  3.         point[] p=intersectionpoints(line(A,B),c);
  4.         if(p[0]==A)
  5.                 return p[1];
  6.         else
  7.                 return p[0];
  8. }
Copy the Code

A在c上,求直线AB与c的另外一个交点
  1. point intersectionpoint(path c,point A,point B)
  2. {
  3.         point[] p=intersectionpoints(line(A,B),c);
  4.         if(p[0]==A)
  5.                 return p[1];
  6.         else
  7.                 return p[0];
  8. }
Copy the Code

返回三角形ABC的垂心
  1. point chuixin(point A,point B,point C)
  2. {
  3.         return orthocentercenter(triangle(A,B,C));
  4. }
Copy the Code

返回分割满足 AP=t PB 的点P,向量意义下,也就是高中教材里的定比分点
  1. point fendian(point A,point B,real t)
  2. {
  3.         point C=(A+t*B)/(1+t);
  4.         return C;
  5. }
Copy the Code

默认返回 \angle BAC 的内角平分线,如果 sharp=false,返回外角平分线
  1. line bisector(point A,point B,point C,bool sharp=true)
  2. {
  3.         real t=length(A-B)/length(A-C);
  4.         point X=fendian(B,C,t),Y=fendian(B,C,-t);
  5.         if(sharp)
  6.                 return line(A,X);
  7.         else
  8.                 return line(A,Y);
  9. }
Copy the Code

返回到A,B距离之比为t的阿氏圆
  1. circle acircle(point A,point B,real t)
  2. {
  3.         return circle(fendian(A,B,t),fendian(A,B,-t));
  4. }
Copy the Code

手机版Mobile version|Leisure Math Forum

2025-4-20 12:09 GMT+8

Powered by Discuz!

× Quick Reply To Top Return to the list