LightOJ - 1433 Minimum Arc Distance (数学几何)求圆上两点间的弧长

LightOJ - 1433
Minimum Arc Distance
Time Limit:                                                        2000MS                        Memory Limit: 32768KB 64bit IO Format:                            %lld & %llu                       

SubmitStatus

Description

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

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

Sample Output

Case 1: 6641.81699183

Case 2: 2295.92880

Case 3: 1616.690325

Case 4: 4155.64159340

Case 5: 5732.01250253

Hint

Source

Problem Setter: Arif Siddiquee
Special Thanks: Jane Alam Jan
//题意:
告诉你圆心坐标,和圆上两点A,B的坐标,问他们俩点之间的较小的一段弧长是多少。
//先求出AB(AB之间的距离)和R,在根据余弦定理求出AB两点所夹的圆心角的cos值,再根据cos值根据弧长公式求出弧长。
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<math.h>
#define PI acos(-1.0)
using namespace std;
double S(double x1,double y1,double x2,double y2,double x3,double y3)
{
	return (x2-x3)*(y1-y3)-(y2-y3)*(x1-x3);
}
int main()
{
	int t,T=1;
	scanf("%d",&t);
	while(t--)
	{
		double x0,x1,x2,y0,y1,y2;
		double r,ab,k,b,h,so,C,l,O,s;
		scanf("%lf%lf%lf%lf%lf%lf",&x0,&y0,&x1,&y1,&x2,&y2);
		r=sqrt((x1-x0)*(x1-x0)+(y1-y0)*(y1-y0));
		double r2=(x1-x0)*(x1-x0)+(y1-y0)*(y1-y0);
		ab=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
		double ab2=(x1-x2)*(x1-x2)+(y1-y2)*(y1-y2);
		double co=(2*r2-ab2)/(2*r2);
		O=acos(co);
		if(fabs(ab-2*r)<1e-6)
		{
			l=PI*r;
			printf("Case %d: %lf\n",T++,l);
		}
		else 			
		{
			if(O>PI)
			O=2*PI-O;
			l=O*r;
			printf("Case %d: %lf\n",T++,l);
		}		
	}
	return 0;
}

你可能感兴趣的:(LightOJ - 1433 Minimum Arc Distance (数学几何)求圆上两点间的弧长)