Clear Filters
Clear Filters

Distance from center to the points

34 views (last 30 days)
I need the distance to the points (first generated point will be point 1 and so on) from the centre (0,0) from the graph generated by the code below:
**********************************
Code taken from the following Reference: % https://au.mathworks.com/matlabcentral/answers/315717-poisson-point-process-with-fixed-n
r=1; %radius of disk
xx0=0; yy0=0; %centre of disk
%Simulate binomial point process
pointsNumber=5;
theta=2*pi*(rand(pointsNumber,1)); %angular coordinates
rho=r*sqrt(rand(pointsNumber,1)); %radial coordinates
%Convert from polar to Cartesian coordinates
[xx,yy]=pol2cart(theta,rho); %x/y coordinates of Poisson points
%Shift centre of disk to (xx0,yy0)
xx=xx+xx0
yy=yy+yy0
% X = [0,0;xx,yy];
% d = pdist(X,'euclidean')
%Plotting
scatter(xx,yy);
xlabel('x');ylabel('y');
axis square;
**************************************************
Any assistance would be highly appreciated.

Accepted Answer

Star Strider
Star Strider on 27 Aug 2019
Add this line to your code just after the pol2cart call:
D = pdist2([0 0], [xx, yy]); % Distance
If you want to display the distances on your plot, add these lines after the axis square call:
tc = sprintfc(' %.2f',D); % Display Distances
text(xx, yy, tc, 'HorizontalAlignment','left') % Display Distances
You can also experiment with this:
set(gca, 'XAXisLocation','origin', 'YAXisLocation','origin')
Put it just after the scatter call.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!