这是……比量p并用交点连接中心不上弧。在于:它至p距离。是不是p与端点之间的最短距离
#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);
}
}
1503: 点到圆弧的距离
Time Limit: 1 Sec Memory Limit:
128 MB Special Judge
Submit: 37 Solved: 9
[Submit][Status][Web
Board]
Description
输入一个点P和一条圆弧(圆周的一部分),你的任务是计算P到圆弧的最短距离。
换句话说。你须要在圆弧上找一个点,到P点的距离最小。
提示:请尽量使用精确算法。相比之下,近似算法更难通过本题的数据。
Input
输入包括最多10000组数据。每组数据包括8个整数x1, y1, x2, y2, x3, y3, xp, yp。圆弧的起点是A(x1,y1),经过点B(x2,y2),结束位置是C(x3,y3)。点P的位置是 (xp,yp)。输入保证A, B, C各不同样且不会共线。
上述全部点的坐标绝对值不超过20。
Output
对于每组数据,输出測试点编号和P到圆弧的距离,保留三位小数。你的输出和标准输出之间最多能有0.001的误差。
Sample Input
0 0 1 1 2 0 1 -1
3 4 0 5 -3 4 0 1
Sample Output
Case 1: 1.414
Case 2: 4.000
HINT
Source
版权声明:本文博客原创文章。博客,未经同意,不得转载。