how do I reference the distance of any points from the center of a uniform distribution in a circle

1 次查看(过去 30 天)
I have done a uniform distribution of n number of points in a circle, I am stuck in trying to reference the distance of any of those points from the center of the circle to do a further calculation;
My uniform distribution goes as follows:
% radius of the circle
R = 500;
% number of samples
n = 1000;
% my uniform distribution
angle = 2 * pi*(rand(1,n));
r = R * sqrt(rand(1,n));
y = r.*sin(angle);
x = r.*cos(angle);
% the plot of the uniform distribution
plot(x,y,'r.');

采纳的回答

Walter Roberson
Walter Roberson 2016-5-13
distances = sqrt(x.^2 + y.^2);
  2 个评论
zaxtronix
zaxtronix 2016-5-13
using the Pythagoras formula you gave makes all the distance to be positive, and the coordinates at the negative sections of the plot will not be seen, i.e (at x = -20, y = -30). Is this the only way ?
Walter Roberson
Walter Roberson 2016-5-13
By definition, the distance of an object to itself is 0: that is true for all distance metrics, part of the definition of a metric space. In order for a distance function to return a negative value, you would need it to be the case that some point B is even closer to point A then A is to itself. That makes no sense. Distances are never negative.
The way you construct your data, all of the distances will be r
Possibly what you are looking for is direction information. For that, use
atan2(y, x)

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by