Creating Random Coordinates Inside a Fixed Points
6 次查看(过去 30 天)
显示 更早的评论
Im asking for a random number generator inside an area like this;
Size of the rectange is 12 lengt 8 side,
for the circle the radius 2.
From that on I'm planning to create a mash area for my problem's further calculations.

2 个评论
Fabio Freschi
2019-9-27
If you need to create a mesh outside the PDE environment you may have a look at
- mesh2d: https://it.mathworks.com/matlabcentral/fileexchange/25555-mesh2d-delaunay-based-unstructured-mesh-generation
- distmesh: https://popersson.github.io/distmesh/
采纳的回答
Fabio Freschi
2019-9-27
% geometry data
xMax = 12;
yMax = 8;
rCircle = 2;
% number of points
N = 1000;
% points iside the rectangle
P = bsxfun(@times,rand(N,2),[xMax yMax]);
% initial plot of all points
figure, hold on, axis equal
plot(P(:,1),P(:,2),'*');
% translate in the origin
Q = bsxfun(@minus,P,[xMax/2 yMax/2]);
% index of points outside the circle
idx = sqrt(sum(Q.^2,2)) > rCircle;
% keep points outside the circle
P = P(idx,:);
% plot points outside the circle
plot(P(:,1),P(:,2),'o');
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Geometry and Mesh 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!