Problem Description
Given the 3D coordinate locations of four sensors and their known
distance from a target, calculate the location of the target.
Background & Techniques
We have sensors at known locations in 3D space.
Each sensor can supply distance information to a target but knows nothing
about the target's direction. Alternatively, the sensors are Satellites and
the target is a GPS receiver which reads very accurate time stamps
transmitted by the satellites and calculates distances based on time offsets
between its clock when a clock time message is received and satellites' clock
time when the message was sent (as contained in the message).
Given the sensor (X, Y, Z) coordinates and their distance-to-target values,
we'll use Gaussian Elimination to solve a set of linear equations describing
the problem and derived as follows:
The distance Di to target at (Xt, Yt,
Zt) for sensor "i" located at (Ai,
Bi, Ci) is given by
Sqr(Di)=Sqr(Ai - Xt) + Sqr(Bi -
Yt) + Sqr(Ci - -Zt)
after expanding:
Di2 = Ai2 - 2AiXt
+ Xt2 +Bi2 - 2BiYt
+Yt2 +Ci2 - 2CiZt
+ Zt2
Solving this system of quadratic equations can be tricky, but we can we can subtract the Sensor1 equation from each of the other 3 to obtain
linear equations like the following example for Sensor2::
2(A1-A2)Xt + 2(B1-B2)Yt
+ 2(C1-C2)Zt = D22 -
A22 - B22 - C22
- D12
The resulting 3 equations in 3 unknowns form a system of linear equations
which are solved here using Gaussian Elimination to find the (Xt, Yt,
Zt) target coordinates.
Note that the original problem is over-specified, 4
equations with 3 unknowns. Two sensors can narrow target location down to a
circle (the intersection of 2 spheres with target distance as radii), the
3rd sensor narrows the location down to two possible points, (the
intersection of the circle with the 3rd sensor's sphere). The
4th sensor should determine which of those two points is the target. Any
error in specified locations or distances would either have no solution or
require that some input values be adjusted. The techniques applied
here result in reported distances being adjusted to produce a solution.
Differences between input and
calculated distances are listed as part of the solution.
The Solve button returns a position which may be at distances different from
those in the original distance equations but do satisfy the distances
relative to Sensor 1. Part of what we sacrifice by eliminating
one of the equations and converting quadratics to linear. A better
solution in the GPS case might be to incorporate dummy 4th variable
representing the distance error due to clock synchronization errors between
the satellites and the GPS receiver. The multivariate
Newton-Raphson algorithm is a possible way to solve using 4 quadratic
equations in 4 unknowns. Sounds like a good candidate for our
next project!
Non-programmers are welcome to read on, but may
want to skip to the bottom of this page to download
executable version of the program.
Notes for Programmers
I developed the algebraic technique described above after spending a week
trying to get the geometric approach to work. Geometrically, each of
the 4 sensors and its target distance define a sphere upon which the target
must lie, and that should be the common point of intersection of all 4
spheres. My plan was to
find the circle defined by the intersection of spheres 1 and 2, then find
the 2 points where that circle intersected sphere 3 and then choose which of
those two points came closes to the surface of sphere 4. I never
did track down some little bug in the process and thus the switch of
approaches.
There are 19 TEdit controls for user input; 4 for each of the 4 sensors
plus 3 if the user wants to enter target values. The target values
were convenient when debugging the code with sets of points with known
solutions. In order to simplify the code, I defined an array,
Sensors, of
TSensorEdits records, each containing 4 TEdit pointers (object
references are always pointers), plus the numeric version of the X, Y, Z, and R
(distance) values represent by the edits for that sensor.
Unit UMatrix is the unit from the old Borland Turbo Pascal
Numeric Toolbox which contains the GuussianElimination procedure used
here among other matrix operations.
Load and Save buttons use Ini file types to save and reload
problem cases.
Running/Exploring the Program