# Cut out a cuboid out of a bigger cuboid and calculate the resulting coordinates

5 ビュー (過去 30 日間)
Nicolas Kaiser 2023 年 3 月 22 日
コメント済み: Nicolas Kaiser 2023 年 3 月 31 日
Hi community,
I describe multiple cuboid objects with alphashape. Now i want to cut out a smaller cuboid out of a bigger cuboid and get the remaining coordinates of the big cuboid.
Is there any easier solution to do so? Like simular to the polyshape function 'subtract' (https://de.mathworks.com/help/matlab/ref/polyshape.subtract.html). I tried it also ones with the polyshape function. For this i used the top of the bigger cuboid and the top of the smaler cubiod, so two 2D-areas, and used the subtract function for polyshape'. Afterwards i repmat the coordinates and added the max and min corresponding z-coordinate. The code:
coordinates_bigCubiod = [-100 -100 -50; -100 -100 50; 100 -100 50; 100 -100 -50;...
100 100 -50; -100 100 -50; -100 100 50; 100 100 50];
coordinates_smallCubiod = [-25 -12.5 -25; -25 -12.5 25; 25 -12.5 25; 25 -12.5 -25;...
25 12.5 -25; -25 12.5 -25; -25 12.5 25; 25 12.5 25];
polyshape_bigCubiod = polyshape(coordinates_bigCubiod([2 7 8 3],[1 2]));
polyshape_smallCubiod = polyshape(coordinates_smallCubiod([2 7 8 3],[1 2]));
%substract cuboid
polyshape_bigCubiod = subtract(polyshape_bigCubiod,polyshape_smallCubiod);
vertices_topPlate = polyshape_bigCubiod.Vertices(~logical(sum(isnan(polyshape_bigCubiod.Vertices),2)),:);
z_values = unique(coordinates_bigCubiod(:,3));
z_values = repelem(z_values,size(vertices_topPlate,1));
coordinates_bigCubiod = [repmat(vertices_topPlate,[2,1]) z_values];
alphashape_bigCubiod = alphaShape(coordinates_bigCubiod);
figure();
plot(alphashape_bigCubiod);
Unfortunatly, if i plot now the alphashape it doesnt look at all how it should look.
Do you have any idea how to solve this problem?
##### 2 件のコメントなしを表示なしを非表示
Matt J 2023 年 3 月 22 日
Your code does not run, see error message above.
As a minor point, you've also spelled cuboid incorrectly throughout your code.
Nicolas Kaiser 2023 年 3 月 23 日
I updated the code :)

サインインしてコメントする。

### 回答 (1 件)

Nikhilesh 2023 年 3 月 31 日
Hi Nicolas,
You can try using " Patch Function " to create the cuboids and then substract them using boolean operation.
##### 1 件のコメント-1 件の古いコメントを表示-1 件の古いコメントを非表示
Nicolas Kaiser 2023 年 3 月 31 日
Is there a function to subtract to patch objects from each other? I can not find any related function for this. Thanks for your help :)

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeBounding Regions についてさらに検索

R2022b

### Community Treasure Hunt

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

Start Hunting!

Translated by