フィルターのクリア

How to calculate corners based on min and max

4 ビュー (過去 30 日間)
Mats
Mats 2017 年 11 月 2 日
コメント済み: Guillaume 2017 年 11 月 2 日
If i have an n-dimensional space contained by straight walls (distinct max and min in each dimension). I need to find the position of the corner points.
For example in 3D I have the min and max values in each dimension in a 2x3 matrix. Is there any good way from that to calculate the cornerpoints of the shape that encloses that volume?
  2 件のコメント
Adam
Adam 2017 年 11 月 2 日
The maxes and mins are the corner points aren't they?
Mats
Mats 2017 年 11 月 2 日
Hi Adam,
Yes, but a good way to combine the coordinates to get each cornerpoint on one row with (x,y,z)

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

回答 (1 件)

Jos (10584)
Jos (10584) 2017 年 11 月 2 日
For the 3D case, try this:
mm = [0 2 ; 1 3 ; 4 5] % column 1 is minimum, column 2 is maximum, rows are [x y z]
[px,py,pz] = ndgrid(mm(1,:),mm(2,:),mm(3,:))
P = [px(:) py(:) pz(:)] % the 8 corners of a 3D cube
Flexible ND case:
mm = [0 2 ; 1 3 ; 4 5 ; -1 1 ; 10 20] ; % 5D
nd = size(mm,1) ; % number of dimensions
mmC = mat2cell(mm,ones(1,nd), 2) ;
[p{1:nd}] = ndgrid(mmC{:}) ;
P = reshape(cat(nd,p{:}),[],nd) % the 32 corners of a 5D "cube"
  1 件のコメント
Guillaume
Guillaume 2017 年 11 月 2 日
To avoid problems if p already exists and is not a cell array (or a larger cell array than required) I'd use:
p = cell(1, nd);
[p{:}] = ndgrid(mmC{:});

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

カテゴリ

Help Center および File ExchangeFeature Detection and Extraction についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by