reverse 3D euclidean distance

조회 수: 11 (최근 30일)
Ferdinand Grosse-Dunker
Ferdinand Grosse-Dunker 2019년 7월 25일
댓글: Star Strider 2019년 7월 25일
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');

채택된 답변

Star Strider
Star Strider 2019년 7월 25일
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
Ferdinand Grosse-Dunker
Ferdinand Grosse-Dunker 2019년 7월 25일
Works perfekt, thank you. Can you comment on the function you use?
Star Strider
Star Strider 2019년 7월 25일
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).

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Akira Agata
Akira Agata 2019년 7월 25일
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

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

제품


릴리스

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by