32

I need to find algorithm that can calculate centroid A (aka gravity center, geometric center, center of mass) from the figure where circles T1,T2,T3,T4,T5,..,Tn intersect AND length of line R from centroid to farthest corner of mentioned figure

Following information is given:

  • T1 Latitude = 56.999883 Longitude = 24.144473 Radius = 943
  • T2 Latitude = 57.005352 Longitude = 24.151168 Radius = 857
  • T3 Latitude = 57.005352 Longitude = 24.163356 Radius = 714
  • T4 Latitude = 56.999042 Longitude = 24.168506 Radius = 714
  • T5 Latitude = 56.994226 Longitude = 24.15709 Radius = 771

Result should look like this: A Latitude = XX.XXXXXXX Longitude = XX.XXXXXXX Radius = XX

enter image description here

As you probably already figured out, I am working on software that can find device location by closest Wifi Access Points or Mobile Base stations, as number of access points or base stations might change, I need an algorithm that can adapt to uncertain amount of points.

There are some similar questions here and here, but none of them exactly answers to my question.

8
  • what language are you working in?
    – WolfOdrade
    Commented Nov 8, 2012 at 23:35
  • Mostly PHP, little bit of JavaScript. I guess I had to mention this before but I am a web developer and to understand Whuber's answer I will have to find a mathematician. Commented Nov 8, 2012 at 23:54
  • Are the radii derived from relative signal strengths? Commented Nov 9, 2012 at 2:25
  • 1
    I expected something like that: the nice thing is that the signal strengths will decay with (almost) an inverse square law and will be measured (typically) with a constant relative error, at least within an effective working range. This implies the radii will be measured with an error proportional to their inverse squares: this can be incorporated directly into the weighted least squares solution by adjusting the weights accordingly.
    – whuber
    Commented Nov 9, 2012 at 19:37
  • 1
    @Reddox, partly - I managed to calculate it with php_exec() using mathematica on serverside. Commented Mar 24, 2014 at 9:27

3 Answers 3

35

The radius measurements surely are subject to some error. I would expect the amount of error to be proportional to the radii themselves. Let us assume the measurements are otherwise unbiased. A reasonable solution then uses weighted nonlinear least squares fitting, with weights inversely proportional to the squared radii.

This is standard stuff available in (among other things) Python, R, Mathematica, and many full-featured statistical packages, so I will just illustrate it. Here are some data obtained by measuring the distances, with relative error of 10%, to five random access points surrounding the device location:

Data table

Mathematica needs just one line of code and no measurable CPU time to compute the fit:

fit = NonlinearModelFit[data, Norm[{x, y} - {x0, y0}], {x0, y0}, {x, y}, Weights -> 1/observations^2]

Edit--

For large radii, more accurate (spherical or ellipsoidal) solutions can be found merely by replacing the Euclidean distance Norm[{x, y} - {x0, y0}] by a function to compute the spherical or ellipsoidal distance. In Mathematica this could be done, e.g., via

fit = NonlinearModelFit[data, GeoDistance[{x, y}, {x0, y0}], {x0, y0}, {x, y}, 
        Weights -> 1/observations^2]

--end of edit

One advantage of using a statistical technique like this is that it can produce confidence intervals for the parameters (which are the coordinates of the device) and even a simultaneous confidence ellipse for the device location.

ellipsoid = fit["ParameterConfidenceRegion", ConfidenceLevel -> 0.95];
fit["ParameterConfidenceIntervalTable", ConfidenceLevel -> 0.95]

Confidence interval table

It is instructive to plot the data and the solution:

Graphics[{Opacity[0.2], EdgeForm[Opacity[0.75]], White, Disk[Most[#], Last[#]] & /@ data, 
  Opacity[1], Red, ellipsoid, 
  PointSize[0.0125], Blue, Point[source], Red, Point[solution],
  PointSize[0.0083], White, Point @ points}, 
  Background -> Black, ImageSize -> 600]

Map

  • The white dots are the (known) access point locations.

  • The large blue dot is the true device location.

  • The gray circles represent the measured radii. Ideally, they would all intersect at the true device location--but obviously they do not, due to measurement error.

  • The large red dot is the estimated device location.

  • The red ellipse demarcates a 95% confidence region for the device location.

The shape of the ellipse in this case is of interest: the locational uncertainty is greatest along a NW-SE line. Here, the distances to three access points (to the NE and SW) barely change and there is a trade-off in errors between the distances to the two other access points (to the north and southeast).

(A more accurate confidence region can be obtained in some systems as a contour of a likelihood function; this ellipse is just a second-order approximation to such a contour.)

When the radii are measured without error, all the circles will have at least one point of mutual intersection and--if that point is unique--it will be the unique solution.

This method works with two or more access points. Three or more are needed to obtain confidence intervals. When only two are available, it finds one of the points of intersection (if they exist); otherwise, it selects an appropriate location between the two access points.

4
  • +1 This answer from 11 years ago answered stats.stackexchange.com/questions/634974/…. You must have a very good memory or know how to search well.
    – JimB
    Commented Dec 15, 2023 at 20:14
  • @Jim It's a vague memory coupled with lots of experience searching SE sites ;-).
    – whuber
    Commented Dec 15, 2023 at 20:25
  • Can you share a reference on how mathematica obtains the confidence ellipsoid? I'd like to compute it myself using only python and numpy after estimating the params with nonlinear least squares.
    – Mr. Fegur
    Commented Jul 25 at 1:48
  • @Mr.Fegur It must be a standard maximum likelihood confidence region, assuming Gaussian errors.
    – whuber
    Commented Jul 25 at 3:04
1

In this case, every circle intersects all the other circles and so we can determine the intersection points this way:

First determine all n*(n-1) intersection points. Call the set of these intersection point I. Take a list of points T which contains the innermost points. Then for each point p in I, check if p is inside every circle. If p is inside every circle, then this is point on the innermost intersection. Add such a point to the list T.

Now you have the desired intersection coordinates. I can think of at least two ways to predict the location:

  1. Just calculate the centroid (use distance as weight?) of the polygon formed by T and centroid is the desired location.
  2. Calculate the minimum circle that contains every point of T. Then the center of this circle is the desired location. Calculating R should be straightforward after this.

Another note: first convert signal strength to distance using free space path model (or variations). My take is: you have any training dataset, you should try to find path loss exponent using some learning technique instead of using n=2 or n=2.2 as fixed value.

1
  • what is T...the "innermost points" - if I have 5 nodes..how many "innermost points" should I be checking for?
    – ewizard
    Commented Mar 3, 2018 at 2:42
1

I just tried the following algorithm for 3D distances (and therefore, it should work as well for 2D distances). It is not an exact model, but an iterative one that gets very close to the true answer after only something like 10 iterations.

I haven't tested its performance against an exact approach, and so, as far as I know, it could be less performant than such a solution. I thought I'd share it nonetheless.

The algorithm goes like this:

  1. Make an initial guess Q that equals the average of all circle centers Cn
  2. For every circle center Cn and circle radii Rn, find a delta vector ΔQn that follows the formula:

ΔQn = normalize(Cn - Q) * (magnitude(Cn - Q) - Rn)

  1. Add the average of all the vectors in ΔQn to Q

  2. Repeat step 2. and 3. until the required precision is reached

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.