I have a list of circles (centre and radius), and for each circle, I need to do some processing for all circles whose centres are inside the circle.
I do a simple double loop as
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef struct Points
{
double x;
double y;
double r;
} Points;
int main()
{
int num = 10000; // number of circles
Points c[num]; // circles
for (int i = 0; i < num; i++)
{
for (int j = 0; j < num; j++)
{
// checking if the distance of point i and j is small than i's radius
if (c[i].r > sqrt(pow(c[i].x - c[j].x, 2) + pow(c[i].y - c[j].y, 2)))
{
// do the processing
}
}
}
return 0;
}
The problem is the performance. For 10,000 circles I do 100M iterations.