Skip to content

Instantly share code, notes, and snippets.

@jnkather
Created May 27, 2015 18:46
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/f10d65eb00ad45cf04b6 to your computer and use it in GitHub Desktop.
Save jnkather/f10d65eb00ad45cf04b6 to your computer and use it in GitHub Desktop.
calculate distance from a given point for a cloud of points, 2D
% JN Kather 2015
% calculate distance from a given point for a cloud of points, 2D
% cloud of points
Pts = rand(500,2);
% calculate distance from P(px|py)
px = 0.5; py = 0.5
distance = sqrt((Pts(:,1)-px).^2 + (Pts(:,2)-py).^2);
% plot
figure()
hold on
plot(px,py,'x','MarkerSize',50,'Color',[0 0 0])
scatter(Pts(:,1),Pts(:,2),25,distance,'filled')
hold off
colorbar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment