Finding a centre and plotting a sphere

2 vues (au cours des 30 derniers jours)
Adin Adac
Adin Adac le 22 Mar 2021
Commenté : Adin Adac le 22 Mar 2021
Hi, I'm new to matlab and completely lost on this one. I have to make a function which evaluates Euclidean distances between two sets of points, finds a sphere with centre at the middle-point between two most distant points and calculate its radius.
Basically I have 2 sets of points, from which I form the distance matrix D by using
D = sqrt( bsxfun(@plus,sum(P.^2,2),sum(R.^2,2)') - 2*(P*R') )
centre of the sphere should be between the 2 points with the largest distance between them. How to find that point?

Réponse acceptée

David Hill
David Hill le 22 Mar 2021
M=0;%point sets p and q assumed to be in matrix form, for example [1 2 3;4 5 6]
for k=1:size(q,1)
[m,idx]=max(sqrt(sum((p-q(k,:)).^2,2)));
if m>M
M=m;
points=[p(idx,:);q(k,:)];
end
end
radius=M/2;
center=sum(points)/2;
  1 commentaire
Adin Adac
Adin Adac le 22 Mar 2021
This works perfectly, thank you!

Connectez-vous pour commenter.

Plus de réponses (1)

Matt J
Matt J le 22 Mar 2021
Modifié(e) : Matt J le 22 Mar 2021

Community Treasure Hunt

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

Start Hunting!

Translated by