Uniformly distributed points generation inside quadrilateral with given points
16 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
NKM
el 11 de Mayo de 2020
Editada: Rena Berman
el 14 de Mayo de 2020
I have a quadrilaterla with vertices (1,0),(1,2),(2,1) and (3,4). How can I generate uniformly distributed points inside it along with plot?
2 comentarios
John D'Errico
el 11 de Mayo de 2020
Is this a one time problem with this specific quad? Or tomorrow will you have some different quadrilateral? Or will you have a more general polygon? The reason I ask is the solution would depend on what you really need to do next.
The simple solution would be to triangulate the quadrilateral. Then generate points randomly inside the triangles, based on their area. Not difficult.
Respuesta aceptada
Ameer Hamza
el 11 de Mayo de 2020
Editada: Ameer Hamza
el 11 de Mayo de 2020
One of the way can be to find a rectangle enclosing all the vertices, create uniformly distributed random points inside the rectangle and then filter out the points using inpolygon()
x = [2 2 3 4];
y = [1 3 2 5];
% sort the vertices to create a convex polygon
X = [x.' y.'];
idx = convhull(X);
X = X(idx, :);
% find enclosing rectangle
ll_corner = [min(x) min(y)]; % lower_left corner
tr_corner = [max(x) max(y)]; % top_right corner
points = rescale(rand(10000, 2), ll_corner, tr_corner); % scale the random number
% to be inside the rectangle
idx = inpolygon(points(:,1), points(:,2), X(:,1), X(:,2));
points = points(idx, :);
figure();
ax = axes();
plot(X(:,1), X(:,2), 'LineWidth', 1)
hold on
plot(points(:,1), points(:,2), '.')
0 comentarios
Más respuestas (1)
Matt J
el 11 de Mayo de 2020
I haven't used it, but this FEX tool claims to be able to do it:
0 comentarios
Ver también
Categorías
Más información sobre Surface and Mesh Plots en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!