In the first step, I have to make the below shape! However, the program must generate black dots and red dots randomly. The number of red dots is always 10 and their coordinates are random, and of course only the correct values can be between zero and 10, as well as the black dot, which is always a random dot with the same characteristic of red dots. The blue dot is always in the zero and zero coordinates. The starting point or origin is the lower left corner marked in blue. The destination point is marked in black, which in this example is in coordinates 5 and 7. Suppose that we can only move 1 unit in each step and we can only go to the destination through the green dots. The red dots are actually obstacles in the path that we must somehow get around.
The program is supposed to offer two routes:
1 shortest between origin and destination! -
2 paths that required the least number of turns.
Assumption: Consider the length of horizontal, vertical and oblique steps the same, and for the shortest path only the number of step is important.
my code so far:, but I cannot go more. since I should do it without using for and while loops. the figures I need to produce are attached to this question.
any help is really appreciated. I need a hint to do the rest.
x = 0:10;
y = 0:10;
plot(xx, yy, 'bo', 'MarkerSize', 15,'markeredgecolor','b','markerfacecolor','g');
plot(xx(1,1),yy(1,1),'o', 'MarkerSize', 15,'markeredgecolor','r','markerfacecolor','b')
annotation('textbox', [0.32, 0.06, 0.1, 0.1], 'String', "start point!")
plot(xxr, yyr, 'o', 'MarkerSize', 15,'markeredgecolor','b','markerfacecolor','r');
plot(xxb, yyb, 'o', 'MarkerSize', 15,'markeredgecolor','r','markerfacecolor','k');
D = sqrt((xx .^ 2) + (yy .^ 2));
% Find the closest one from (0,0)
[minDistance, indexOfMin] = min(D);
closestX = xx(indexOfMin);
closestY = yy(indexOfMin);
% Mark it with red *
hold on; % Don't blow away existing points.
plot(closestX, closestY, 'r*', 'MarkerSize', 8, 'LineWidth', 2);
% Draw a line from the closest point to (0, 0)
line([0, closestX], [0, closestY], 'LineWidth', 2, 'Color', 'r');