I wanted to generate a line from start to end position on which there would be random points over the line and nearby with in some distance, not over the whole area.

1 view (last 30 days)
I wanted a code which generate nodes and sample them which will track the optimal path by using those random generated nodes on line or nearby that line.
basically i wanted to merge the following code with my RRT* algorithm to limit the researches. If any one could help me out of it.
numPoints = 50;
x = sort(5 * rand(1, numPoints), 'ascend');
m = 0.4;
c = 3;
y = m*x+c;
plot(x, y, 'bd-', 'LineWidth', 2);
grid on;
hold on;
amplitude = 1.6; % Whatever...
noise = amplitude * rand(1, length(y)) - amplitude / 2;
plot(x, noise, 'ms-'); % Plot noise
yNoisy = y + noise;
plot(x, yNoisy, 'r.', 'LineWidth', 2, 'MarkerSize', 10);
ax = gca;
ax.XAxisLocation = 'origin';

Answers (1)

Anurag
Anurag on 29 Aug 2023
As per my understanding of the question you need to have the random points nearby the lines but not all over the space, for this you can limit the coordinates of the points being generated.
Suppose you need the points that fall within a close vicinity of the center of the line, you may iterate through your list of points and remove those x coordinates that fall outside your defined threshold from the midpoint of the point.

Categories

Find more on Random Number Generation in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!