Creating Random Coordinates Inside a Fixed Points

조회 수: 7 (최근 30일)
Hjodie
Hjodie 2019년 9월 27일
댓글: Hjodie 2019년 9월 27일
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.
Screen Shot 2019-09-27 at 12.26.11.png
  댓글 수: 2
darova
darova 2019년 9월 27일
YOu can use PDE toolbox to create a mesh and export it to MATLAB workspace

댓글을 달려면 로그인하십시오.

채택된 답변

Fabio Freschi
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');
  댓글 수: 1
Hjodie
Hjodie 2019년 9월 27일
Appreciated, thanks for the help which is that fast :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Geometry and Mesh에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by