views:

132

answers:

3

Let me know if this is mathoverflow material, and I'll wend my way over there. I'm hoping someone will recognise this and point me in the right direction...

I'm trying to map out related nodes. I've figured out how to calculate the minimum distances between all the points, and now I need to know how to turn those into actual co-ordinates in 2D space.

So, given a point Pn (where n > 1), a set of points [P1..Pn-1], and a set of distances [d1..dn-1] where each d represents the minimum distance between Pn and d's respective point, how do I calculate the best valid co-ordinate set [x,y] for Pn?

When I say 'best' valid co-ordinate set, I mean the set that brings Pn closest to all the other points without violating any of the constraints.

My first thought was to stick P1 at [0,0], P2 at [0,d] (d1 for P2) and then for P3 I would put it at [0,y] where y is the minimum distance that P3 has to be at to satisfy its d1 and d2 and then move it in a circle around P2 at a radius of d2 for as long as it still satisfies d1.

That would have to be repeated for all points, which sounds like it would take ages.

Does this problem ring any bells with anyone? I'm not sure what formula or algorithms I'm looking for.

Update I hadn't thought about what 'closest' means. I knew what I meant when I wrote it, but I hadn't thought about calculating it!

Minimum sum of squares sounds like it will do the job.

+1  A: 

It sounds a lot as if you're trying to do some form of multidimensional scaling.

Martin B
Thanks Martin - I'm looking at this now.
Matt Ellen
I'm accepting this answer because it led me on to Self Organising Maps.
Matt Ellen
A: 

My guess is that in general this would be hard. What you are doing is starting with the whole plane, then removing discs (of radius d) around each of your existing Ps, and then asking - where on this mutilated plane is the point 'closest' to all the existing Ps?

Even once you've decided what you mean by 'closest' (minimize sum of squared distance is traditional, but that might not be what you want), you are still faced with the problem that the mutilated plane can in the general case be of an arbitrarily complicated shape. I would suggest you do head over to mathoverflow.

AakashM
Thanks for your thoughts, AakashM. What is a Mutilated Plane? I tried Googling it, but I couldn't find anything.
Matt Ellen
@Matt : it's just a plane with some (circular, in this case) holes cut out of it. Like a slice of Swiss cheese. I don't know of a proper term for it :)
AakashM
+1  A: 

The solution, without the constraints, is to set

Pn = Σi=1n-1 Pi / (n-1)

(With constraints is more difficult; I have an idea of how to do it, see my advice below)

Proof

We are looking to minimize

Σi=1n-1 ||Pn - Pi||2
= Σi=1n-1 (Pn - Pi)·(Pn - Pi)
= Σi=1n-1 Pn·Pn - 2Pn·Pi + Pi·Pi
= Σi=1n-1 Pn·Pn - Σi=1n-1 2Pn·Pi + Σi=1n-1 Pi·Pi
= (n-1)Pn·Pn - 2Pn·Σi=1n-1 Pi + Σi=1n-1 Pi·Pi

Since we are in 2d, this is a quadratic equation of 2-variables; we can take the partial-derivatives to find the critical-point (and thus the minimum):

f = (n-1)Pnx2 + (n-1)Pny2 - 2PnxΣi=1n-1 Pix - 2PnyΣi=1n-1 Piy + Σi=1n-1 Pi·Pi (constant, so doesn't matter for derivative)
Dxf = 2(n-1)Pnx - 2Σi=1n-1 Pix
Dyf = 2(n-1)Pny - 2Σi=1n-1 Piy

Setting those last two derivatives to 0, we get the result.

This is known as a barycentric combination (or barycenter, or center of mass or whathave you). While this doesn't answer your question, the last equation should help:

k = (n-1)Pn·Pn - 2Pn·Σi=1n-1 Pi + Σi=1n-1 Pi·Pi

Where k is some constant. If we were to graph this on a plane, then for some k we'd get a single point: Pn, our barycenter. As we increased k, we'd get the graph of a circle centered at Pn - all the points on this circle have the same sum-of-squares value. As we increase k, this sum-of-squares value gets larger and larger.

If we were going to solve this mathematically and rigerously, we'd want to find the smallest k which creates a circle which has a point that satifies all the constraints. I don't know how we'd do that.

To estimate the answer in a program, I'd keep creating larger and larger circles centered around our barycenter until we find one that works. To determine if a circle works: find all collision points of our barycentric-circle with all the other circles created by the constraints, and everyplace our circle collides with another, create a cut point. With all our cut-points, we've divided our circle into arcs (no more than 2n-1 arcs, unless our center is exactly one of the points) - all points on each arc will share the same status of "satisfying the constraints or not", so choose any point on the arc to test it. Do this for all arcs on the circle, and if none of them satisfy it, make the circle a little bit bigger.

We could make this a bit better by noticing that increasing the circle-size doesn't help any if we're still colliding the same amount of times with all the same circles.

BlueRaja - Danny Pflughoeft
Thanks BlueRaja! I will take the time to look into this.
Matt Ellen