UVA 438 (The Circumference of the Circle) Solution
Hints:
Suppose that the coordinates of the three points are and
Compute the following three values. If the value of is 0, they lie on a line so there's no circle to have a center.
Then the center has coordinates where
Solve in C:
#include<stdio.h>
#include<math.h>
int main(){
double a1,a2,b1,b2,c1,c2,x,y,pi=3.141592653589793,d,u,v,r,c;
while(scanf("%lf%lf%lf%lf%lf%lf",&a1,&a2,&b1,&b2,&c1,&c2)!=EOF)
{
d=(a1-b1)*(b2-c2)-(b1-c1)*(a2-b2);
u=(((a1*a1)-(b1*b1))+((a2*a2)-(b2*b2)))/2.0;
v=((b1*b1)-(c1*c1)+(b2*b2)-(c2*c2))/2.0;
x=((u*(b2-c2))-(v*(a2-b2)))/d;
y=((v*(a1-b1))-(u*(b1-c1)))/d;
r=sqrt(((x-a1)*(x-a1)+(y-a2)*(y-a2)));
c=2*pi*r;
printf("%.2lf\n",c);
}
}
Suppose that the coordinates of the three points are and
Compute the following three values. If the value of is 0, they lie on a line so there's no circle to have a center.
Then the center has coordinates where
Solve in C:
#include<stdio.h>
#include<math.h>
int main(){
double a1,a2,b1,b2,c1,c2,x,y,pi=3.141592653589793,d,u,v,r,c;
while(scanf("%lf%lf%lf%lf%lf%lf",&a1,&a2,&b1,&b2,&c1,&c2)!=EOF)
{
d=(a1-b1)*(b2-c2)-(b1-c1)*(a2-b2);
u=(((a1*a1)-(b1*b1))+((a2*a2)-(b2*b2)))/2.0;
v=((b1*b1)-(c1*c1)+(b2*b2)-(c2*c2))/2.0;
x=((u*(b2-c2))-(v*(a2-b2)))/d;
y=((v*(a1-b1))-(u*(b1-c1)))/d;
r=sqrt(((x-a1)*(x-a1)+(y-a2)*(y-a2)));
c=2*pi*r;
printf("%.2lf\n",c);
}
}
No comments