|
写一个函数, 输入一点和一个二次曲线(geometry.asy定义的conic结构体), 输出点到二次曲线的所有切点?
圆的情形, 见olympiad.asy
点到圆的2个切点(按逆时针标为1和2):
- // The nth point of tangency from a point P to the circle with center O and radius r
- // where n can be 1 or 2 - the points of tangency are labeled in counterclockwise order around the circle.
- // If P is inside the circle, the center of the circle is returned rather than an error.
- pair tangent(pair P, pair O, real r, int n=1)
- {
- real d,R;
- pair X,T;
- d=abs(P-O);
- if (d<r) return O;
- R=sqrt(d^2-r^2);
- X=intersectionpoint(circle(O,r),O--P);
- if (n==1)
- {
- T=intersectionpoint(circle(P,R),Arc(O,r,degrees(X-O),degrees(X-O)+180));
- }
- else if (n==2)
- {
- T=intersectionpoint(circle(P,R),Arc(O,r,degrees(X-O)+180,degrees(X-O)+360));
- }
- else {T=O;}
- return T;
- }
复制代码 |
|