Description
Fit a circle (cx, cy, radius) to a set of points using an iterative, converging, method that does not use derivatives. Actualy, there are two similar methods in this file, one which uses a Monte-Carlo population of candidates, and another which uses a 3d grid of candidates. The latter method is used in 'roughalign.py' and 'roughalign2.py' as it is at least 2x faster, and is deterministic (i.e. all runs produce the same sequence of results). Either method can fit a circle to an arbitrary precision (although this does not mean that the error will reach zero). The algorithm is tuned for speed to produce results which are accurate to between 0.01 and 0.1 pixels. Since the limb is estimated to at best 1 pixel resolution, this is more than sufficient.
Usage
fitcircle.py x1 y1 x2 y2 x3 y3 [x4 y4 ...]
When run from the command line, this program fits a circle to a set of input points. The initial circle is at the center of the points, with the average radius. The iterations can stop after a fixed number, or when the error falls below a set value (e.g. 0.001). At each step the program prints out the index of the best grid candidate (0-26, 13 at center), cx, cy, radius, error, and current grid size:
Examples
50: ~/Projects/Python/AstroPy > fitcircle.py -1 0 -0.707 0.707 0 1 0.707 0.707 1 0 Initial: 0.000000 0.482800 0.844298 0.232258 1: 13 0.000000 0.482800 0.844298 0.232258 1.000000 2: 13 0.000000 0.482800 0.844298 0.232258 0.900000 3: 13 0.000000 0.482800 0.844298 0.232258 0.810000 4: 13 0.000000 0.482800 0.844298 0.232258 0.729000 5: 13 0.000000 0.482800 0.844298 0.232258 0.656100 6: 10 0.000000 -0.107690 0.844298 0.215131 0.590490 7: 11 0.000000 -0.698180 1.434788 0.200095 0.590490 8: 13 0.000000 -0.698180 1.434788 0.200095 0.590490 9: 15 0.000000 -0.166739 0.903347 0.195505 0.531441 10: 16 0.000000 0.364702 0.903347 0.174080 0.531441 ... 122: 15 0.000000 -0.000117 0.998512 0.001486 0.003757 123: 13 0.000000 -0.000117 0.998512 0.001486 0.003757 124: 16 0.000000 0.003264 0.998512 0.001378 0.003381 125: 13 0.000000 0.003264 0.998512 0.001378 0.003381 126: 10 0.000000 0.000221 0.998512 0.001329 0.003043 127: 11 0.000000 -0.002822 1.001555 0.001148 0.003043 128: 13 0.000000 -0.002822 1.001555 0.001148 0.003043 129: 13 0.000000 -0.002822 1.001555 0.001148 0.002739 130: 15 0.000000 -0.000357 0.999090 0.001031 0.002465 131: 16 0.000000 0.002108 0.999090 0.000913 0.002465 Final: 0.000000 0.002108 0.999090 0.000913
İSky Coyote 2007