0

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

  • It's hard to say what went wrong if we can't see what you have done (not just what you hoped to do). – naslundx Aug 05 '16 at 09:21
  • Naslundx, I added the PHP code I use in the post above – HansGeering Aug 05 '16 at 09:27
  • Just from a quick look, I think you should switch slAB and slBC in your calculation of ctrX. – naslundx Aug 05 '16 at 09:48
  • naslundx, any specific place to swap them? If I swap them everywhere in the calculation of ctrX I get the following results, which are even more off center than the original: 52.306215058852,4.7722930895929 – HansGeering Aug 05 '16 at 09:52

1 Answers1

0

You are doing calculations with the latitude and longitude given in degrees, which is the problem: it's dangerous. At this latitude, in Amsterdam Schiphol, 1 second of latitude is not the same distance as 1, but around 1.64 seconds of longitude.

What looks like a circle on the map is actually a 1.64 (horizontal) × 1 (vertical) ellipse in the coordinate system. To construct this, squash the horizontal axis by 1.64. Divide the Y (horizontal) coordinates by this number:

  • Y1 = 2.917859931575434
  • Y2 = 2.918194391541954
  • Y3 = 2.918053147936349

Now construct your circle from the three points as you would. The formula is correct, and yields the result (Xc, Yc) = (52.30605658593861, 2.9178091740775374).

When we multiply back the 1.64 into the Y (horizontal) coordinate, this transforms the circle into a 1.64 × 1 ellipse in the original coordinate system, which is what we want. This gives the final latitude and longitude as:

  • (Xc, Yc) = (52.30605658593861, 4.771995987519797)

and plotting that on the map confirms it as the centre of the circle you want.

I have cut a corner here: to find the exact centre, you would have to employ spherical trigonometry, but the area we are performing our calculations in is so small compared to the Earth's size that we can treat it as flat. This allows the scaling technique I performed above.

Such scaling issues are a major topic in cartography, the study of maps. The latitude-longitude system we routinely use to express points on the globe is deficient in this regard, in that it does not preserve distances. There are other ways of expressing these points that do preserve distances, but they are beyond the scope of this answer.

Parcly Taxel
  • 105,904
  • Thanks Parcly, this works. As I was working with such small distances, I would not have thought the distance between degrees of longitude would make any difference. – HansGeering Aug 05 '16 at 10:39