Light oj 1433 - Minimum Arc Distance【计算几何(坑精度!)】

来源:互联网 发布:网络游戏同步算法 编辑:程序博客网 时间:2024/06/16 03:59

1433 - Minimum Arc Distance
   PDF (English)StatisticsForum
Time Limit: 2 second(s)Memory Limit: 32 MB

You all probably know how to calculate the distance between two points in two dimensional cartesian plane. But in this problem you have to find the minimum arc distance between two points and they are on a circle centered at another point.

You will be given the co-ordinates of the points A and B and co-ordinate of the center O. You just have to calculate the minimum arc distance between A and B. In the picture, you have to calculate the length of arc ACB. You can assume that A and B will always be on the circle centered at O.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing six integers Ox, Oy, Ax, Ay, Bx, By where (Ox, Oy) indicates the co-ordinate of O(Ax, Ay) denote the co-ordinate of A and (Bx, By) denote the co-ordinate of B. All the integers will lie in the range [1, 10000].

Output

For each case, print the case number and the minimum arc distance. Errors less than 10-3 will be ignored.

Sample Input

Output for Sample Input

5

5711 3044 477 2186 3257 7746

3233 31 3336 1489 1775 134

453 4480 1137 6678 2395 5716

8757 2995 4807 8660 2294 5429

4439 4272 1366 8741 6820 9145

Case 1: 6641.81699183

Case 2: 2295.92880

Case 3: 1616.690325

Case 4: 4155.64159340

Case 5: 5732.01250253



题意:

给出圆的圆心和圆上两点坐标,求两点间间的劣弧长


题解:

题目很简单,基础的计算几何,但是在求的时候,要尽量减少浮点的运算次数,否则会wa,精度比较坑.....

刚开始用acos,错了,换个思路,减少了浮点数运算,用asin AC了......(也可能是之前的程序本身写的有问题)


/*http://blog.csdn.net/liuke19950717*/#include<cstdio>#include<cstring>#include<cmath>const double pi=acos(-1.0);struct point{int x,y;};double dis(point a,point b){return sqrt((a.x-b.x)*(a.x-b.x)*1.0+(a.y-b.y)*(a.y-b.y));}int main(){int t;scanf("%d",&t);for(int k=1;k<=t;++k){point p[3];for(int i=0;i<3;++i){scanf("%d%d",&p[i].x,&p[i].y);}double r=dis(p[0],p[1]),d=dis(p[1],p[2])/2.0;double ans=2*asin(d/r)*r;printf("Case %d: %.8lf\n",k,ans);}return 0;}

0 0
原创粉丝点击