필터 지우기
필터 지우기

Hello everybody I have a question . I have a cuboid shape, I want to calculate all the points within this figure as x,y values and save to workspace>

조회 수: 6 (최근 30일)
Hello everybody
I have a question . I have a cuboid shape, I want to calculate all the points within this figure as x,y values and save to workspace>

답변 (2개)

VINAYAK LUHA
VINAYAK LUHA 2022년 6월 8일
편집: VINAYAK LUHA 2022년 6월 8일
Hi Wisam ,
As per my understanding of your problem , you wish to store all interior integer coordinates in the cuboid,in this case each point will be a tuple of 3 elements, (x,y,z) .
Let (x1,y1,z1) and (x2,y2,z2) be the endpoints of body digonal of the cuboid,then interior points can be calculated as follows.
let,
x1=5;x2=8; y1=4;y2=6;z1=0;z2=2;
xmin=min(x1,x2);
xmax=max(x1,x2);
ymin=min(y1,y2);
ymax=max(y1,y2);
zmin=min(z1,z2);
zmax=max(z1,z2);
points=[[]];
for x=xmin:xmax
for y=ymin:ymax
for z=zmin:zmax
points=[points;[x,y,z]];
end
end
end
disp(points)
5 4 0 5 4 1 5 4 2 5 5 0 5 5 1 5 5 2 5 6 0 5 6 1 5 6 2 6 4 0 6 4 1 6 4 2 6 5 0 6 5 1 6 5 2 6 6 0 6 6 1 6 6 2 7 4 0 7 4 1 7 4 2 7 5 0 7 5 1 7 5 2 7 6 0 7 6 1 7 6 2 8 4 0 8 4 1 8 4 2 8 5 0 8 5 1 8 5 2 8 6 0 8 6 1 8 6 2
scatter3(points(:,1),points(:,2),points(:,3),'o')
Hope this helps.
  댓글 수: 1
Wisam Mohammed
Wisam Mohammed 2022년 6월 9일
i have this code to generate the shape below , then I NEED all the possible point inside the shape. as x, y
pgon = polyshape([2.23 0.1404 8.258 10.37],[14.95 0.9339 1.579 15.61 ]);
plot(pgon)
grid on

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


Matt J
Matt J 2022년 6월 9일
tf = inpolygon(xq,yq,[2.23 0.1404 8.258 10.37],[14.95 0.9339 1.579 15.61 ]);
x=xq(tf);
y=yq(tf);

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

제품


릴리스

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by