I wrote a program on the PROLOGUE, which determines whether a point with coordinates fell into a circle. The program displays correctly if the point in the circle, and if not, it still displays "Falls", and the point is not in the circle.

I give the code, please tell me what's wrong.

domains n=real predicates proverka(n,n,n,n,n) proverka1(n,n,n,n,n) clauses proverka(X,Y,Xc,Yc,R):- sqrt((X-Xc)*(X-Xc) + (Y-Yc)*(Y-Yc))<=R*R, write("Popadaet"). proverka1(X,Y,Xc,Yc,R):- sqrt((X-Xc)*(X-Xc) + (Y-Yc)*(Y-Yc))>R*R, write("Ne popadaet"). goal write("Vvedite X= "),readreal(X), write("Vvedite Y= "),readreal(Xc), write("Vvedite Xc= "),readreal(Y), write("Vvedite Yc= "),readreal(Yc), write("Vvedite R= "),readreal(R),proverka(X,Y,Xc,Yc,R),proverka1(X,Y,Xc,Yc,R). 
  • You have a problem, ahem, not quite with the Prologue. Are you sure that R*R ? Compare dimensions / units. - D-side
  • I enter only the numbers and that's it. - Gerasimov Stanislav
  • Uh-uh ... Did you read your own code at all? - D-side
  • The condition of hitting a point in the circle X^2+y^2 <= R^2

1 answer 1

Here you have the code:

 sqrt((X-Xc)*(X-Xc) + (Y-Yc)*(Y-Yc))<=R*R 

The condition of hitting a point in the circle X ^ 2 + y ^ 2 <= R ^ 2
Do you get X ^ 2 + Y ^ 2 <= R ^ 4 if you remove the roots

Should be

 sqrt((X-Xc)*(X-Xc) + (Y-Yc)*(Y-Yc))<=R 

or

 (X-Xc)*(X-Xc) + (Y-Yc)*(Y-Yc)<=R*R