How to calculate corners based on min and max

조회 수: 7 (최근 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 CenterFile Exchange에서 Feature Detection and Extraction에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by