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

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.');

 Accepted Answer

distances = sqrt(x.^2 + y.^2);

2 Comments

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 ?
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)

Sign in to comment.

More Answers (0)

Categories

Find more on 2-D and 3-D Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!