# Fit Circle to Points

**URL:** <https://root-forum.cern.ch/t/fit-circle-to-points/35721>\
**Category:** Newbie\
**Created:** [August 21, 2019, 4:00pm UTC](https://root-forum.cern.ch/t/fit-circle-to-points/35721 "2019-08-21T16:00:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rma491](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rma491](https://root-forum.cern.ch/u/rma491)\
**Post date:** [August 21, 2019, 4:00pm UTC](https://root-forum.cern.ch/t/fit-circle-to-points/35721/1 "2019-08-21T16:00:35Z")

</div>

Hi!

I am trying to adapt the following code to different data sets.  
[https://root.cern/doc/master/fitCircle\_8C.html](https://root.cern/doc/master/fitCircle_8C.html) For some data sets the fit works for some it  
does not.

Trying to solve the problem I modified the parameters from this  
double pStart[3] = {0,0,1};  
to this  
double pStart[3] = {0,0,0};  
and it works better but still not very well.

Can anyone explain me why we need to initialize these parameters and why the third is initialized to 1 in the example?

Thanks!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 22, 2019, 7:20am UTC](https://root-forum.cern.ch/t/fit-circle-to-points/35721/2 "2019-08-22T07:20:39Z")

</div>

Looking at [the code](https://root.cern/doc/master/fitCircle_8C.html) it looks like the first two parameters are the coordinates of the circle centre and the third one its radius. May be for some of your data set the initial values 0,0,1 are too far from the result and the fitting procedure does not converge ?

---

<div class="post-metadata">

**Author:** ![rma491](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/b4bc9f/32.png) [@rma491](https://root-forum.cern.ch/u/rma491)\
**Post date:** [August 22, 2019, 8:53am UTC](https://root-forum.cern.ch/t/fit-circle-to-points/35721/3 "2019-08-22T08:53:57Z")

</div>

Yeah, indeed, the fit does not converge for some of the data sets…  
Is there any way I can apply a fit which be independent on such initial input?  
I have way too many data sets in order to input manually the parameters…

How about the Coope method, is this implemented in ROOT?

Thank you!

---

<div class="post-metadata">

**Author:** ![couet](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/couet/32/12037_2.png) [@couet](https://root-forum.cern.ch/u/couet)\
**Post date:** [August 22, 2019, 9:08am UTC](https://root-forum.cern.ch/t/fit-circle-to-points/35721/4 "2019-08-22T09:08:34Z")

</div>

I guess @moneta can answer better than me as he is our “fitting expert”.  
Those which do not converge have centre different from (0,0) may be ?
