reverse 3D euclidean distance

4 views (last 30 days)
Hi there,
I am standing at an unknown point U(x,y,z) in the room. I can measure 3 (euclidean) distances D to 3 known points P in the room. I try to find the point, where I am at. My equation system looks like this:
(x-3)²+(y-1)²+(z-4)²=D1²=81
(x-12)²+(y-1)²+(z-4)²=D2²=36
(x-34)²+(y-2)²+(z-4)²=D3²=601
I can put the known points into a matrix P, the measured distance in a vector D:
P=[3 1 4;12 1 4; 34 2 4]
P =
3 1 4
12 1 4
34 2 4
D=[81 36 601]
Do you know how I can find U(x,y,z) ?
I am not sure if I can use
D = pdist(X,'euclidean');

Accepted Answer

Star Strider
Star Strider on 25 Jul 2019
Try this:
P=[3 1 4;12 1 4; 34 2 4];
D=[81 36 601];
fcn = @(b,x) (b(1)-x(:,1)).^2 + (b(2)-x(:,2)).^2 + (b(3)-x(:,3)).^2;
B = fminsearch(@(b) norm(D(:) - fcn(b,P)), [1; 1; 1])
producing:
B =
10.0000
5.0000
-0.0000
that are the (x,y,z) coordinates, as best fminsearch can calculate them.
  2 Comments
Ferdinand Grosse-Dunker
Ferdinand Grosse-Dunker on 25 Jul 2019
Works perfekt, thank you. Can you comment on the function you use?
Star Strider
Star Strider on 25 Jul 2019
As always, my pleasure.
The documentation for the fminsearch function is at the link. It is an unconstrained optimiser that uses a derivative-free method to find the minimum.
The code I use for my objective function ‘fcn’ and as an argument to fminsearch are Anonymous Functions. They are quite useful for coding short functions, although they have their limitations.
I use the norm function so that the fminsearch function finds the minimum value that satisfies the sum-of-squares criterion (since this is essentially a curve-fiting problem).

Sign in to comment.

More Answers (1)

Akira Agata
Akira Agata on 25 Jul 2019
There should be 2 answers.
Here is my try.
P = [3 1 4;12 1 4; 34 2 4];
D = [81 36 601];
func = @(x) (vecnorm(x - P(1,:))-sqrt(D(1)))^2+...
(vecnorm(x - P(2,:))-sqrt(D(2)))^2+...
(vecnorm(x - P(3,:))-sqrt(D(3)))^2;
x1 = fminsearch(func,[1 1 1]);
x2 = fminsearch(func,[10 10 10]);
>> x0
x0 =
10.0000 5.0000 -0.0000
>> x1
x1 =
10.0000 5.0000 8.0000

Categories

Find more on Mathematics in Help Center and File Exchange

Products


Release

R2018b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!