At the last lesson the students were studying circles. They learned how to draw circles with compasses. Peter has completed most of his homework and now he needs to solve the following problem. He is given two segments. He needs to draw a circle which intersects interior of each segment exactly once.
The circle must intersect the interior of each segment, just touching or passing through the end of the segment is not satisfactory.
Help Peter to complete his homework.
The first line of the test case contains four integer numbers x 11, y 11, x 12, y 12— the coordinates of the ends of the first segment. The second line contains x 21. y 21, x 22, y 22 and describes the second segment in the same way.
Input is followed by two lines each of which contains four zeroes these lines must not be processed.
All coordinates do not exceed 10 2 by absolute value.
0 0 0 4 1 0 1 4 0 0 0 0 0 0 0 0
0.5 0 2
题意:给你两条线的两个端点,让你给出一个圆的圆心和半径
思路:找出两条线段最近的两个端点,两点的中点为圆心,两点的距离的一半+一个很小的数为半径
ac代码:
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
struct point
{
double x,y;
};
double dis(point a,point b){
return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
int main()
{
point a,b,c,d;
double p,q,r;
while(cin>>a.x>>a.y>>b.x>>b.y>>c.x>>c.y>>d.x>>d.y)
{
if(a.x==0&&a.y==0&&b.x==0&&b.y==0&&c.x==0&&c.y==0&&d.x==0&&d.y==0)
break;
double x1,x2,x3,x4;
x1=dis(a,c);
x2=dis(a,d);
x3=dis(b,c);
x4=dis(b,d);
double min1;
min1=min(x1,min(x2,min(x3,x4)));
if(min1==x1)
{
p=(a.x+c.x)/2.0;
q=(a.y+c.y)/2.0;
}
else
{
if(min1==x2)
{
p=(a.x+d.x)/2.0;
q=(a.y+d.y)/2.0;
}
else
{
if(min1==x3)
{p=(b.x+c.x)/2.0;
q=(b.y+c.y)/2.0;}
else
{
p=(b.x+d.x)/2.0;
q=(b.y+d.y)/2.0;
}
}
}
r=min1/2.0+0.001;
printf("%lf %lf %lf\n",p,q,r);
}
return 0;
}