Hi all, I am attempting to write a C# trilateration function, but it is beyond my limited math knowledge...

I have a number of known points (currently 8, but this number may change)

I have the x, y, z coordinates for each.

P1[3];

P2[3];

P3[3];

P4[3];

P5[3];

P6[3];

P7[3];

P8[3];

P3[3];

where each array has 3 values, x, y and z.

I know the distance from the unknown point (x) to each of the known points.

double D1;

double D2;

double D3;

double D4;

double D5;

double D6;

double D7;

double D8;

So given these values, I need to find the xyz coordinates of the unknown point X[3];

What is the most straightforward way to do this? I have found examples in other code languages, but nothing that I understand in c#. And only ever with three points.

Any and all assistance would be much appreciated!

Thanks in advance!

That means that there is an error (or errors) somewhere.

Do you know why? How accurately do you know the positions of the base stations? How did you measure the distances?

>> I am trialling cycling through groups of 3 and averaging the result. Is this the best way to go about it?

A better technique might be to minimize the RMS error.

You have n base stations A thru N and n distances Da thru Dn.

Once you have an approximate solution X, calculate a new set of distances between this point and your base stations to get a new set of distances Dax thru Dnx.

The RMS error is sqrt[ (1 - Dax/Da)² + (1 - Dbx/Db)² + (1 - Dcx/Dc)² + . . . + (1 - Dnx/Dn)² ]

Move your solution point in the x, y, and z directions to minimize the error.