## 190 - Circle Through Three Points

Moderator: Board moderators

gracia
New poster
Posts: 5
Joined: Mon Nov 25, 2002 9:04 am
Location: jakarta

### still confuse

but i still got WA
this is my program and may be you can tell me why i got WA #include<stdio.h>
#include<math.h>

float x,y;
float ak,bk,ck;

void output()
{
float r;
r=sqrt(ak*ak+bk*bk-ck);
printf("(x ");
if (-1*ak>=0) printf("- ");
else printf("+ ");
printf("%.3f)^2 + (y ",fabs(ak));
if (-1*bk>=0) printf("- ");
else printf("+ ");
printf("%.3f)^2 = %.3f",fabs(bk),r);
if (r*r!=r) printf("^2\n");
else printf("\n");

printf("x^2 + y^2 ");
if (2*ak<0) printf("- ");
else printf("+ ");
printf("%.3fx ",fabs(2*ak));
if (2*bk<0) printf("- ");
else printf("+ ");
printf("%.3fy ",fabs(2*bk));
if (ck<0) printf("- ");
else printf("+ ");
printf("%.3f = 0",fabs(ck));
}

void hitung()
{
int i;
float a,b,p,bil;
for (i=0;i<3;i++) {
bil=x*x+y*y;
a=x*2;
b=y*2;
}
for (i=3;i<5;i++) {
bil=bil[i-3]-bil[i-2];
a[i]=a[i-3]-a[i-2];
b[i]=b[i-3]-b[i-2];
}
p=a;
p=a;
for (i=3;i<5;i++) {
bil[i]=bil[i]*fabs(p[4-i]);
b[i]=b[i]*fabs(p[4-i]);
a[i]=a[i]*fabs(p[4-i]);
}
if((p<0&&p<0)||(p>0&&p>0)) {
bil=bil-bil;
b=b-b;
} else {
bil=bil+bil;
b=b+b;
}
bk=-1*bil/b;
ak=(bil*-1+bk*b*-1)/a;
ck=bil*-1+ak*a*-1+bk*b*-1;
}

int main()
{
while (!feof(stdin)) {
fscanf(stdin,"%f %f %f %f %f %f",&x,&y,&x,&y,&x,&y);
hitung();
output();
printf("\n\n");
}
return 0;
}

off_algos
New poster
Posts: 29
Joined: Wed Nov 13, 2002 11:37 am
Location: india

### hi gracia

why dont u try using the code button and enhance the readability of ur code
also please indent ur program before submission

also for better precision try using double

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Contact:
Yes thats the main mistake!]
i think u should read advises of Shahriar Monzor for the new comers!!!
Most of the times try to use double in place of float and long inplace of int
I didnt find other error in ur prob.
Do it. gracia
New poster
Posts: 5
Joined: Mon Nov 25, 2002 9:04 am
Location: jakarta

### whatever

next time i will use code button and indent my program
i think if the input
2 2 2 2 2 2
the output should be
(x-2.000)^2 + (y-2.000) ^2= 0.000^2
x^2 + y^2 - 4.000x - 4.000y+ 8.000= 0
am i right ?
i have change my program but i still got WA
i really2 confuse the LA-Z-BOy
Learning poster
Posts: 94
Joined: Wed Jul 31, 2002 12:44 pm
Contact:
yo,
there is no input like
0 0 0 0 0 0 or
2 2 2 2 2 2 or
1 2 1 2 1 2 either.
so you don't have to take care of these type of inputs.
btw, we're dealing with 'circles' here, aren't we? gracia, are you still taking input as you've shown before?
[c]while (!feof(stdin)) {
fscanf(stdin,"%f %f %f %f %f %f",&x,&y,&x,&y,&x,&y);
/* ... */
}
[/c]
here's a problem. feof returns 1 after attempt to read one item has failed. so you should try this...
[c]while (TRUE) {
fscanf(stdin,"%f %f %f %f %f %f",&x,&y,&x,&y,&x,&y);
if (feof(stdin)) break;
/* ... */
}
[/c]
and your prog fails for input: (i haven't gone thru your code, just ran it)
1.0 2.0 1.0 5.0 3.0 3.0
where the output should be
[c](x - 1.500)^2 + (y - 3.500)^2 = 1.581^2
x^2 + y^2 - 3.000x - 7.000y + 12.000 = 0
[/c]
and i think float is enough for this problem, but it's safer to use doubles.
Istiaque Ahmed [the LA-Z-BOy]

Jalal
Learning poster
Posts: 65
Joined: Sun Jun 02, 2002 8:41 pm
Contact:
Gracia!
ur output is ok. but
the solve of the problem require
(x - h)^2 + (y - k)^2 = r^2
x^2 + y^2 + 2gx + 2fy + c = 0

Here h=x co-ordiante of center and k=y co-ordinate
of the center. But in ur code u didnt make it. lets take some input:
0 0 5 0 2.5 2.5
output will be:
(x - 2.500)^2 + (y - 2.500)^2 = 2.500^2
x^2 + y^2 + 5.000x + 5.000y + 12.500 = 0

but ur one gives:
(x - 2.500)^2 + (y - 0.000)^2 = 2.500^2
x^2 + y^2 + 5.000x + 0.000y + 0.000 = 0

so the code got some problem with the
k and f value. make it ok.
hope can help. shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

### 190 WA

i am getting WA.

can any one give me any critical inputs.

Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:
Here a help:

[quote]
algebraic way of finding the equation of a circle given three points.

For instance, say you are given the points (8,3), (4,-5), and (-4,-1), and are asked to find the equation of the circle that contains these points.

You know the general equation of a circle: (x-h) We are all in a circular way, no advances, only moving and moving!

Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:
I have created a picture for the geometrical approach or you may think vector:

http://acm.iwarp.com/photo.html

Is it clear !?!
Last edited by Moni on Sat Mar 22, 2003 8:33 pm, edited 1 time in total. We are all in a circular way, no advances, only moving and moving!

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
I try to solve this problem and I got WA too. I used the same algorithm as you said Moni Could anyone tell me some special cases ?
I try to print "+ 0.000" and "- 0.000" but I always got WA

Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Could anyone tell me: is this way of output results correct or not ?

Code: Select all

``````		printf("(x %s %.3lf)^2 + (y %s %.3lf)^2 = %.3lf^2\n",((h < 0.0) ? "+" : "-"),
fabs(h),((k < 0.0) ? "+" : "-"),fabs(k),fabs(r));
printf("x^2 + y^2 %s %.3lfx %s %.3lfy %s %.3lf = 0\n",((c < 0.0) ? "+" : "-"),
fabs(c),((d < 0.0) ? "+" : "-"),fabs(d),((e < 0.0) ? "+" : "-"),fabs(e));
``````
Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

angga888
Experienced poster
Posts: 143
Joined: Sat Dec 21, 2002 11:41 am
Location: Indonesia
I used this as my output and I got AC

Code: Select all

``````    printf("(x");
if (a<0) printf(" - "); else printf(" + ");
printf("%.3lf)^2 + (y",fabs(a));
if (b<0) printf(" - "); else printf(" + ");
printf("%.3lf)^2 = %.3lf^2\n",fabs(b),r);
printf("x^2 + y^2");
if (A<0) printf(" - "); else printf(" + ");
printf("%.3lfx",fabs(A));
if (B<0) printf(" - "); else printf(" + ");
printf("%.3lfy",fabs(B));
if (C<0) printf(" - "); else printf(" + ");
printf("%.3lf = 0\n\n",fabs(C));``````
Be careful with small precision error, use double instead of float.

Good Luck! Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:
Angaa , I use double ...
But If I see you print something like
(x - 2.000)^2 .....
(x + 2.000)^2 ....
when a (my h) isnegative. it's good ? I think that I should output + in this case ...

Dominik
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Moni
Experienced poster
Posts: 202
Joined: Fri Mar 22, 2002 2:00 am
Location: Chittagong. CSE - CUET
Contact:
[quote]Look! First I calculated the slope of AB = (By-Ay)/(Bx-Ax);
Now as we all know from plane geometry, We are all in a circular way, no advances, only moving and moving!

Eric
Learning poster
Posts: 83
Joined: Wed Sep 11, 2002 6:28 pm
Location: Hong Kong
Jalal wrote:lets take some input:
0 0 5 0 2.5 2.5
output will be:
(x - 2.500)^2 + (y - 2.500)^2 = 2.500^2
x^2 + y^2 + 5.000x + 5.000y + 12.500 = 0
but ur one gives:
(x - 2.500)^2 + (y - 0.000)^2 = 2.500^2
x^2 + y^2 + 5.000x + 0.000y + 0.000 = 0
I think yours is incorrect.
My accepted program gives
(x - 2.500)^2 + y^2 = 2.500^2
x^2 + y^2 - 5.000x = 0
I am not sure about the display of '0.000'.
But his equation is correct.