how to create 3 random numbers in a circle with 3 different radiuses.

I have to make 15 circles with each circle there are 3 random numbers that can will find in a 3 different radiuses??

4 Comments

I find this confusing.
Do you need 15 circles with 15 radii, or 3 circles with 3 different radii? Or does "15 circles with each circle" mean that there are 15 circles inside each of 3 other circles? Please attach a diagram.
And are these 15 or 3 circles in an image (2-D array) where the values are all 0 except for 3 pixels (locations) where the values are random numbers?
I need to show a model of Strawberry field when all Bush has 3 random strawberries like in the photo
Thank you
Unfortunately I cannot tell from the picture whether there are different random maximum radius for each of the three strawberries, or if the maximum radius is the same for each of them.
My code can be used for both circumstances: if the maximum radius is the same for each of the three, then use a scalar for R, but if there are different maximum radius then use a vector of length 3 for the maximum radius R.
I can define interval to the radius? instead of the 3 radiuses

Sign in to comment.

 Accepted Answer

Let R be a row vector of the three different radii. Then assuming that the random points have to be randomly inside that radius rather than at the radius exactly,
rr = sqrt(rand(15,3)) .* R
rt = rand(15,3)* 2*pi;
[xoff, yoff] = pol2cart(rt, rr) ;
now xoff and yoff will be 15 x 3, one row for each circle and the different columns for the different radii. They are the x and y offset relative to the center of the respective circles. You need to add the coordinates of the center of the circle to those.
X = repmat(CentX(:), 1,3) + xoff
similar for y

2 Comments

rr = minRadius + sqrt(rand(15,3)) .* (maxRadius - minRadius);
rt = rand(15,3)* 2*pi;
[xoff, yoff] = pol2cart(rt, rr) ;

Sign in to comment.

More Answers (2)

How do I put the coordinates of the center of the circle? and how i do plot to graph?
Thanks a lot for your help, you saved me

9 Comments

text(xoff(:), yoff(:), num2str([xoff(:), yoff(:)], 'HorizontalAlignment', 'center')
X = repmat(CentX(:), 1,3) + xoff
how i put the here the center coordinates, i dont understand what i putting on (:).
text(xoff(:), yoff(:), num2str([xoff(:), yoff(:)], 'HorizontalAlignment', 'center')
what it do?
i'm new in matlab so i having trouble
I Really appreciate your help
text(X(:), Y(:), num2str([X(:), Y(:)], 'HorizontalAlignment', 'center')
I thank you very much for your help but I can't figure it out. you could demonstrate it by numbers and show what comes out in the end because I wasn't so successful? I can't figure out where I put the coordinates of the centers of circles and how I divide them in the field. Maybe you can attach a photo from MATLAB?
I was stuck with these formulas:
1. X = repmat(CentX(:), 1,3) + xoff 2. text(X(:), Y(:), num2str([X(:), Y(:)], 'HorizontalAlignment', 'center')
I attached a schematic illustration of the field might have easier to understand.
berries_per_bush = 3; %given
bushRadius = 15 / 2; %from diagram
minRadius = 3; %I made this up
maxRadius = bushRadius * 1.1; %I made this up
X = [7.5 28.5 49.5 70.5 91.5 15.5 38.5 61.5 84.5 7.5 28.5 49.5 70.5 91.5 15.5 38.5 61.5 84.5]; %from diagram
Y = [84.5 * ones(1,5), 61.5 * ones(1,4), 38.5 * ones(1,5), 15.5 * ones(1,4)]; %from diagram
X = X(:); Y = Y(:);
nb = length(X);
rr = minRadius + (rand(nb,berries_per_bush)) .* (maxRadius - minRadius);
rt = rand(nb,berries_per_bush)* 2*pi;
[xoff, yoff] = pol2cart(rt, rr) ;
Cx = repmat(X,1,berries_per_bush) + xoff;
Cy = repmat(Y,1,berries_per_bush) + yoff;
scatter(Cx(:), Cy(:), 'ko', 'filled');
hold on
viscircles([X(:), Y(:)], bushRadius * ones(nb,1), 'LineWidth', 1, 'Color', 'k');
hold off
axis image
text(X(:), Y(:), num2str([X(:), Y(:)], '[%.1f %.1f]'), 'HorizontalAlignment', 'center')
If you want the coordinates outside of the bush like on the diagram, then you should decide where you want them to be placed and what you want them to say and text() the strings into place, and then use <https://www.mathworks.com/help/matlab/ref/annotation.html annotation()) to draw the lines pointing where you want them to point.
This is great thank you
Is there any way to insert the bushes in the gragh?
viscircle need to show me the bush circle in the graph? It show me a graph with the location of the strawberries but without bushes. This is what it shows me in the end.
>>Error using rectangle >>Invalid property found. >>Object Name : rectangle >>Property Name : 'Color'.
>>Error in viscircles (line 79) >> thinCircHdl = rectangle('Parent', hh(k), ...
You can remove the 'color', 'k' part of the viscircles call

Sign in to comment.

Thank you very much helped me a lot.
I need to calculate how long the robotic arm to move between points. When it is a Cartesian system attached to her arm 6 axes
I hope it's not too much to ask

1 Comment

Please start a new Question for that topic.
In that new topic, you should explain whether "long" is in terms of time or in terms of distance. If it is in terms of time, then you need to talk about rotational velocities and constraints -- for example if there are no constraints and everything can move at the same time, then the time requires would be equal to the maximum time to rotate on one of the axes, since all of the rotations could take place at the same time. Either way you would need to do motion planning, since in 3 or more degrees of freedom without constraints there are always multiple ways of reaching the same destination.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!