You can reduce the problem by finding the "widest" axis of your point cloud. This will be the diameter of your smallest circle. Any smaller circle could not enclose the extreme points defining this diameter.
An ineffective algorithm for this starts with a loop at angles ɵ from 0 to 45 degrees. For each angle ɵ, transform the coordinates of each point by rotating the coordinate system by ɵ. Then just find max(x)-min(x) and max(y)-min(y) to find the maximum degree for this rotation. Continue to find the maximum degree for all turns.
Here is a C program that implements this simple algorithm, returning the length of the minimum diameter:
To adapt this code to your specific problem, add this code at the end:
double center_x = (x[max_i]+x[min_i])/2; double center_y = (y[max_i]+y[min_i])/2; double radius = sqrt( (x[max_i]-x[min_i])*(x[max_i]-x[min_i]) + (y[max_i]-y[min_i])*(y[max_i]-y[min_i])))/2;
Undoubtedly, there is a more effective approach (for example: first find a convex hull, and then consider only those points that define the hull), but this may be sufficient if the number of points is not astronomical.
source share