2016-04-30 10 views
1

NxNxNキューブ(画像)が与えられた場合、NxNxNキューブ内の2x2x2ボックスをすべて見つけるにはどうすればよいですか?もちろん、Nが偶数であれば、2×2×2のボックスが重なり合うことなく見つけることができますが、Nが奇数である場合、より大きなキューブにある2×2×2ボックスの一部に重なりがあります。だから、MATLABのより大きな立方体内の小さな立方体を見つけるには?

1 - どのように私はNがでもある大きなNxNxNキューブ内のすべての非オーバーラップ2×2×2箱を見つけることができますか?

入力:NxNxNキューブ 出力:すべての可能な非オーバーラップ2×2×2の立方体。

2重いNxNxNキューブで重複した2x2x2ボックスをすべて見つけるにはどうすればいいですか?Nはで、奇数です。今回は、2x2x2ボックスの重複領域が2番目(またはそれ以上)の訪問でゼロになるはずです。すなわち、各重なり合った領域は、1回以上訪問(カウント)されるべきである。

入力:NxNxNキューブ 出力:すべての可能な第2回以上訪問で重複ボクセルに対してゼロ値を持つ2×2×2つのキューブを重ね。

+0

あなたはいつもダブル投稿をしていますか? https://de.mathworks.com/matlabcentral/answers/281798-how-to-find-all-possible-small-boxes-e-g-2x2x2-and-their-overlaps-within-a-bigger-nxnxn-cube – tim

答えて

1

Nが偶数の部分については、回答をお送りします。残りの部分は簡単に適合させることができます。私はあなた自身でこれを行うことができます:-)または少なくともそれを試してください - あなたは問題がある場合は、ちょうど私たちに戻ってきてください。

私はもうMATLABをインストールしていないので、これには誤植がないことを願っています。しかし、アイデアは明らかである:

% 
N = 10; 

% First create all possible starting coordinates of 2x2x2 cubes within the big cube: 
coords = 1:2:(N-1); % could easily be adapted to other small-cube sizes like 3x3x3 if you want to... 

% Now create all possible combinations of starting-coordinates in every direction (as it is a cube, the starting points in x, y, z directions are the same): 
sets = {coords, coords, coords}; 
[x y z] = ndgrid(sets{:}); 
cartProd = [x(:) y(:) z(:)]; % taken from here: http://stackoverflow.com/a/4169488/701049 --> you could instead also use this function: https://www.mathworks.com/matlabcentral/fileexchange/10064-allcomb-varargin- which generates all possible combinations 

% Now cartProd contains all possible start-points of small cubes as row-vectors. If you want, you can easily calculate the corresponding vectors of end-points by simply adding +1 to every entry which will effectively yield a small-cube size of 2. If you want to further modify it to support e.g. 3x3x3 cubes, simply add +2 to every dimension. 
endPoints = cartProd+1; 

% E.g.: the first small cube starts at [x,y,z] = cartProd(1,:) and ends at [x_e, y_e, z_e] = endPoints(1,:). 

ヒント:-)楽しもう:奇数大きなキューブのために - >単純に、例えば、として均等にサイズのキューブをそれを扱います9x9x9立方体を10x10x10として扱い、上からアルゴリズムをとり、最も外側の小立方体を1ステップ分中央に移動します。つまり、最大のx、y、z座標を持つ小さな立方体を取り出し、その方向に1を引くことを意味します。したがって、x_max = 9のすべての小さな立方体の開始座標はx = 8に変更されます。 y_max = 9、z_max = 9と同じです。

関連する問題