Problem Statement :
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.
Solution Code :
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int i,test;
int Ox,Oy,Ax,Ay,Bx,By;
double AB,OB,result,alpha;
cin>>test;
for(i=1;i<=test;i++)
{
cin>>Ox>>Oy>>Ax>>Ay>>Bx>>By;
AB = (Ax-Bx)*(Ax-Bx)+(Ay-By)*(Ay-By);
AB = sqrt(AB);
OB = (Ox-Bx)*(Ox-Bx)+(Oy-By)*(Oy-By);
OB = sqrt(OB);
result = 2*OB*OB - AB*AB;
result = result/(2*OB*OB);
alpha = acos (result ) ;
result = alpha * OB ;
printf("Case %d: %lf\n",i,result);
}
return 0;
}
#include<cmath>
#include<cstdio>
#include<iostream>
using namespace std;
int main()
{
int i,test;
int Ox,Oy,Ax,Ay,Bx,By;
double AB,OB,result,alpha;
cin>>test;
for(i=1;i<=test;i++)
{
cin>>Ox>>Oy>>Ax>>Ay>>Bx>>By;
AB = (Ax-Bx)*(Ax-Bx)+(Ay-By)*(Ay-By);
AB = sqrt(AB);
OB = (Ox-Bx)*(Ox-Bx)+(Oy-By)*(Oy-By);
OB = sqrt(OB);
result = 2*OB*OB - AB*AB;
result = result/(2*OB*OB);
alpha = acos (result ) ;
result = alpha * OB ;
printf("Case %d: %lf\n",i,result);
}
return 0;
}