# Determination of radius based on data points

I have some data points:

A=Uncompress[FromCharacterCode[
Flatten[ImageData[Import["http://i.stack.imgur.com/s6rlR.png"],"Byte"]]]]

B=Uncompress[FromCharacterCode[
Flatten[ImageData[Import["http://i.stack.imgur.com/jylyd.png"],"Byte"]]]]


If A and B are $\color{blue}{\text{joined}}$ and plotted in graphic to be below

My questions:

1. How to determine the value of both radius or diameter of circles?

2. How to determine the distance between circle 1 and circle 2?

Well,a method based on Image Processing strik to my mind.Let do it.

Build a image for your data

pos = Join[A, B];
bound = MinMax /@ Transpose[pos];
bin = ReplaceImageValue[
ConstantImage[0, Ceiling[Subtract @@@ (Reverse /@ bound)]],
TranslationTransform[-First /@ bound][pos] -> 1] Do a DistanceTransform in bin and get what your are after

ImageAdjust[dist = DistanceTransform[FillingTransform[Dilation[bin, 1]]]] TakeLargest[Flatten[ImageData[dist]], 2]


{92.0054, 92.0054}

And I think if your are in the 11.2 comming up,RegionImage will make your life be easer when you build that bin.

• +1 Neat! Learned a lot from your answer. – ubpdqn Sep 12 '17 at 10:52
• @ubpdqn Thanks for kind word.. – yode Sep 12 '17 at 11:19
d = {#1^2, #1, #2, #2^2} & @@@ A;
lm = LinearModelFit[d, {1, a, b, c}, {a, b, c}]
ex = lm["BestFitParameters"].{1, x^2, x, y} - y^2
ru = CoefficientRules[ex]
c0 = {0, 0}
r0 = Sqrt[{0, 0} /. ru]
d2 = {#1^2, #1, #2, #2^2} & @@@ B;
lm2 = LinearModelFit[d2, {1, a, b, c}, {a, b, c}]
x1 = ({1, 0} /. cr)/2
c1 = {x1, 0}
r1 = ({0, 0} /. cr) + x0^2 // Sqrt
ListPlot[{A, B},
Epilog -> {Dashed, Circle[c0, r0], Circle[c1, r1], Red,
PointSize[0.02], Point[{c0, c1}], Blue, Arrowheads[{-0.05, 0.05}],
Arrow[{c0, c1}], Text[x1, (c0 + c1)/2, {0, -1}]}]

• I think the OP try to know the two radius form RandomSample[Join[A, B]] but not from A then B – yode Sep 12 '17 at 11:21
• @yode the 2 radii are in the text that follows the image with the centers preceding. – ubpdqn Sep 12 '17 at 11:23

Denote $f(x_i,y_i)=(x_i-x_0)^2+(y_i-y_0)^2$ a squared distance from a data point $(x_i,y_i)$ to the supposed circle center $(x_0,y_0)$. The idea is like this: values of $|f(x_i,y_i)-f(x_j,y_j)|$ or $(f(x_i,y_i)-f(x_j,y_j))^2$ should be small if $(x_0,y_0)$ is at the same distance from all $(x_i,y_i)$. For example one can minimize function $$g(x_0,y_0)=\sum_{i=2}^n(f(x_{i},y_{i})-f(x_{i-1},y_{i-1}))^2$$ wrt $(x_0,y_0)$.

f[x_, y_] = ((x - x0)^2 + (y - y0)^2);
distsqrd = f @@@ A;
g = Total@(ListConvolve[{-1, 1}, distsqrd]^2);


Minimizing $g$:

minA = NMinimize[g, {x0, y0}]


{0.01583549,{x0->0.000013,y0->-9.5718009*10^-10}}

Now taking the mean value of distances obtained gives

rA = Mean[(distsqrd /. minA[])^(1/2)]


90.9200011

The same procedure for B gives

minB


{0.61139090, {x0 -> 123.000010, y0 -> 1.2381995*10^-15}}

rB


90.9200036

The distance between the circle centers is

Norm[({x0, y0} /. minA[]) - ({x0, y0} /. minB[])]


122.99999706