Clear Filters
Clear Filters

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 views (last 30 days)
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>

Answers (2)

VINAYAK LUHA
VINAYAK LUHA on 8 Jun 2022
Edited: VINAYAK LUHA on 8 Jun 2022
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 Comment
Wisam Mohammed
Wisam Mohammed on 9 Jun 2022
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

Sign in to comment.


Matt J
Matt J on 9 Jun 2022
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);

Categories

Find more on Elementary Polygons in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!