Is ...... Determine that the intersection of the link between P and the center of the circle is not on the arc, that is, the distance from P to P, or the shortest distance between P and the endpoint.
#include<iostream>#include<map>#include<string>#include<cstring>#include<cstdio>#include<cstdlib>#include<cmath>#include<queue>#include<vector>#include<algorithm>using namespace std;const double pi=acos(-1.0);struct dot{double x,y;dot(){}dot(double a,double b){x=a;y=b;}dot operator +(dot a){return dot(x+a.x,y+a.y);}dot operator -(dot a){return dot(x-a.x,y-a.y);}dot operator *(double a){return dot(x*a,y*a);}double operator *(dot a){return x*a.y-y*a.x;}dot operator /(double a){return dot(x/a,y/a);}double operator /(dot a){return x*a.x+y*a.y;}bool operator ==(dot a){return x==a.x&&y==a.y;}dot norv(){return dot(-y,x);}dot univ(){double a=mod();return dot(x/a,y/a);}dot ro(double a){return dot(x*cos(a)-y*sin(a),x*sin(a)+y*cos(a));}double mod(){return sqrt(x*x+y*y);}double dis(dot a){return sqrt(pow(x-a.x,2)+pow(y-a.y,2));}friend istream & operator >> (istream &is,dot &a){is>>a.x>>a.y;return is;}friend ostream & operator << (ostream &os,dot a){os<<a.x<<" "<<a.y;return os;}};dot o,a,b,c,p;double r;void cg(){dot A,B,C;A=a-o;B=b-o;C=c-o;if(A*B<0){if(A*C<0&&B*C>0)return;}else{if(!(A*C>0&&B*C<0))return;}swap(a,c);}double work(){dot A,B,C;A=a-o;B=p-o;C=c-o;if(A*B<0){if(A*C<0&&B*C>0)return fabs(r-p.dis(o));}else{if(!(A*C>0&&B*C<0))return fabs(r-p.dis(o));}return min(p.dis(a),p.dis(c));}void cor(){double A,B,C,D,E,F,G,H,I;A=2*(a.x-b.x);B=2*(a.y-b.y);C=pow(a.x,2)-pow(b.x,2)+pow(a.y,2)-pow(b.y,2);D=2*(a.x-c.x);E=2*(a.y-c.y);F=pow(a.x,2)-pow(c.x,2)+pow(a.y,2)-pow(c.y,2);G=dot(A,D)*dot(B,E);H=dot(C,F)*dot(B,E);I=dot(A,D)*dot(C,F);o=dot(H/G,I/G);r=o.dis(a);}int main(){int jishu=0;double ans;while(cin>>a>>b>>c>>p){cor();cg();ans=work();printf("Case %d: %.3f\n",++jishu,ans);}}
CSU 1503: distance from point to arc-computing program design competition for the tenth college student in Hunan Province