I have to detect if the point belongs to the area (the pic. of it is attached). The condition I wrote seems too long. I am pretty sure there is a way to write it in a more simple way, but I just don't know how. The only succeeded code of all that I've tried is presented below.
float x, y; int a = 2, b = 1, r = 3;
printf("x = ", x);
scanf ("%f", &x);
printf("y = ", y);
scanf ("%f", &y);
if ( ((pow((x-a), 2) + pow((y-b), 2) <= pow(r,2)) && ((pow((x-a), 2) + pow((y-b),2) >= 1)) && (x <= 2) && (x >= -3) && (y >= -1) && (y <= 4)) || fabs(x) <= 1 && fabs(y) <=1 || (y == x+2 && y >= -1 && x >= -3))
{
printf ("Belongs to the area");
}
else
{
printf ("Doesn't belong to the area");
}
The output is correct, so I expect it would be the same.

Aucun commentaire:
Enregistrer un commentaire