I have been trying to calculate the center point of a circle based on three coordinates on the circle, using the formula found on this website: http://paulbourke.net/geometry/circlesphere/
The same formula is used on other web sites so I can check my results. If I use just basic numbers (X1=1, Y1=1, X2=2, Y2=2, X3=3, Y3=1) the results are as expected. However, if I use coordinates (decimal) I get a very strange center point (see http://www.darrinward.com/lat-long/?id=2150664, the fourth point is the one not on the yellow line, which is the calculated center point). It should be more to the left inside the circle, because the distance is not equal between all points.
My values are as follows (N and E coordinates, I know X and Y are in the wrong order and N should be Y, but the results stay the same if I change them):
- X1 = 52.30647
- Y1 = 4.772079
- X2 = 52.306215
- Y2 = 4.772626
- X3 = 52.305719
- Y3 = 4.772395
Calculated ctrX and ctrY are: - ctrX = 52.3060944411 - ctrY = 4.7722368601
I have a feeling that I'm missing something because I'm calculating coordinates on a sphere instead of on a sheet of paper. Can anyone point me in a correct direction on this?
PHP Code I use
$slAB = ($cd['y1'] - $cd['y2']) / ($cd['x1'] - $cd['x2']);
$slBC = ($cd['y3'] - $cd['y2']) / ($cd['x3'] - $cd['x2']);
$ctrX = ($slAB * $slBC * ($cd['y3'] - $cd['y1']) + $slAB * ($cd['x2'] + $cd['x3']) - $slBC * ($cd['x1'] + $cd['x2'])) / (2 * ($slAB - $slBC));
$ctrY = ((1/$slAB)*-1) * ($ctrX - ( ($cd['x1'] + $cd['x2'])/2 ) ) + ($cd['y1'] + $cd['y2'])/2;
$rad = sqrt( pow(($cd['x1'] - $ctrX), 2) + pow(($cd['y1'] - $ctrY), 2));
var_dump(array('ctrX'=>$ctrX, 'ctrY'=>$ctrY, 'rad'=>$rad))
Edit: added the PHP code
slABandslBCin your calculation ofctrX. – naslundx Aug 05 '16 at 09:48