Generating Random Points within Box Around Figure
이전 댓글 표시
Hello! I'm stuck on a project which involves generating random points within a box around a figure.
% length, width and height of box
L=0.65; W=0.65; H=2;
% pick plenty of random points
x= L*rand(1); %x-coordinate of a point
y= W*rand(1); %y-coordinate of a point
z= H*rand(1); %z-coordinate of a point
Rectangle (‘Position’, [x y w h])
This is currently what I have and I would like to set up the box around another figure however I don't know how to plot the box around my figure as well as generate random points within the box? If anyone can direct me that would be great. Thank you.
댓글 수: 3
Adam Danz
2021년 3월 28일
What do you mean "plot the box around the figure"?
For random number generation, use rand or randi.
Mari Teli
2021년 3월 28일
Adam Danz
2021년 3월 30일
You wouldn't need to plot the 3D cube to produce random points within the 3D area. More importantly, it sounds like the 3D object is rounded so some of the cube would be outside of the 3D object.
답변 (1개)
xl yl and zl are 1x2 vectors defining the range of x y and z coordinates of the 3D object.
n is the number of random values to generate.
x = rand(1,n)*range(xl)+xl(1);
y = rand(1,n)*range(yl)+yl(1);
z = rand(1,n)*range(zl)+zl(1);
plot3(x,y,z,'o')
This does not guarantee that all random points will be within the 3D object unless the orientation of the object is parallel to all 3 axes. Otherwise, you can determine which points are outside of the object and remove or replace them.
댓글 수: 7
Adam Danz
2021년 3월 30일
What are some example inputs (pos, vec, totalLength, AR)?
Mari Teli
2021년 4월 1일
> I am having trouble specifying the ranges for x,y,z.
Use the min and max functions
min(x(:)), max(x(:))
or use
[a,b] = bounds(x(:))
Mari Teli
2021년 4월 1일
Adam Danz
2021년 4월 1일
That's what my answer does.
Is there something about the answer that's not clear?
Mari Teli
2021년 4월 1일
카테고리
도움말 센터 및 File Exchange에서 Chemistry에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!