Skip to content

Instantly share code, notes, and snippets.

@jnkather
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jnkather/ad01e397e59869b137d2 to your computer and use it in GitHub Desktop.
Save jnkather/ad01e397e59869b137d2 to your computer and use it in GitHub Desktop.
calculate distance from a given point for a cloud of points, 3D
% JN Kather 2015
% calculate distance from a given point for a cloud of points, 3D
% cloud of points
Pts = rand(10000,3);
% calculate distance from P(px|py|pz)
px = 0.5; py = 0.5; pz = 0.5;
distance = sqrt( (Pts(:,1)-px).^2 + ...
(Pts(:,2)-py).^2 + ...
(Pts(:,3)-pz).^2);
% plot
figure()
hold on
plot3(px,py,pz,'x','MarkerSize',50,'Color',[0 0 0])
scatter3(Pts(:,1),Pts(:,2),Pts(:,3),25,distance,'filled')
hold off
view(66,22)
grid on
colorbar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment