-
Array of circles
I'm about writing a program reads series of cirlces and determines whether circle overlaps with previous input circles or not (Supposed you input 4 circles). Any hints for this would be greate appreciate
typdef struct Circle
{
int x, y;
double radius;
};
typedef struct Distance
{
double distance;
};
struct Distance Centerdis(Cricle C1, Circle C2);
struct Distance SumRadius(double r1, double r2)
int main()
{
Circle C[100];
Distance d1, d2;
int i;
for(i = 0; i < 100; i++)
{
printf("Enter center circle %: ", i);
get(C[i])
------???? I don't know how to write codes to determine cirlce overlap with some previous circles -------
}
struct Distance Centerdis(Cricle C1, Circle C2)
{
Distance D;
..........
return D;
}
struct Distance SumRadius(double r1, double r2)
{
Distance D;
.................
return D;
}
-
Well here's a start...
Code:
#define MAX_CIRCLES 100
double centreDist(struct Circle circle1, struct Circle circle2);
double sumRadius(struct Circle circle1, struct Circle circle2);
void getCircle(struct Circle * pCircle);
...
struct Circle circle[MAX_CIRCLES];
bool overlap;
unsigned int i, j;
...
for (i = 0; i < MAX_CIRCLES; i++)
{
printf("Enter Circle #%d: ", i);
getCircle(&circle[i]);
overlap = false;
for (j = 0; j < i; j++)
{
if (centreDist(circle[i], circle[j]) <= sumRadius(circle[i], circle[j]))
{
overlap = true;
break;
}
}
}
...
I've changed a few bits and pieces to make life easier for myself, like ignoring the Distance struct which I didn't see the point of, and changing the declaration of sumRadius(). You also need to decide whether or not you consider circles that touch as overlapping. Anyway, hopefully this will get you started...