How can I get the 3d coordinates of a point by having its distance to some other points with known coordinates?

3 views (last 30 days)
I have some points in a 3d grid and I have their distance to a point with unknown coordinates. Are there any matlab functions that do that returns its location by getting the distances as input? there is an exchange function point2trimesh() that might do it but I cant be sure since I am quite new to this field. Is it possible to do it easily in matlab?

Answers (1)

David Goodmanson
David Goodmanson on 11 May 2017
Hello payman, here is one way to accomplish this. There are always two solutions, given by the two row vectors s, which are reflections of each other in the plane defined by the three points. You have to decide separately which one is good. Unrealizable solutions for distances d1,d2,d3 give complex numbers for s.
If you have one of the latest versions of Matlab you can use the implicit expansion feature. If not, there are three indented lines of commented code that use repmat instead. This is a script but could become a function easily enough.
% p is a 3x3 matrix, each point defined by a row of (x,y,z) coordinates
% distances are in a vector d, same order as rows of p
% example
p = rand(3,3)'
d = [1 1.1 1.2]';
% start calulation
d = d(:); % column vector
% translate to make sure that origin of coords does not lie in plane determined by the three points
q = p - p(3,:);
% q = p-repmat(p(3,:),3,1);
e = null(q)'*sqrt(norm(q(1,:))*norm(q(2,:))); % vector normal to plane
trans = (1/3)*sum(p) + e;
pnew = p - trans; % translate
% pnew = p - repmat(trans,3,1);
w = sum(pnew.*pnew,2)-d.^2;
q1 = pnew\ones(3,1);
qw = pnew\w;
A = roots([q1'*q1, (2*qw'*q1-4), qw'*qw]); % A = snew dot snew
snew = (1/2)*(q1*A.' +qw)'; % one row of (x,y,z) coords per solution vector
s = snew + trans; % translate back
% s = s + repmat(trans,2,1);
if ~isreal(s); warning('input points and distances are incompatible'); end
% end calculation
% optional check
f = @(v) sqrt(sum(v.^2));
[f(s(1,:) - p(1,:)) f(s(1,:) - p(2,:)) f(s(1,:) - p(3,:));
f(s(2,:) - p(1,:)) f(s(2,:) - p(2,:)) f(s(2,:) - p(3,:))]

Community Treasure Hunt

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

Start Hunting!