How to calculate corners based on min and max

5 Ansichten (letzte 30 Tage)
Mats
Mats am 2 Nov. 2017
Kommentiert: Guillaume am 2 Nov. 2017
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 Kommentare
Adam
Adam am 2 Nov. 2017
The maxes and mins are the corner points aren't they?
Mats
Mats am 2 Nov. 2017
Hi Adam,
Yes, but a good way to combine the coordinates to get each cornerpoint on one row with (x,y,z)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Jos (10584)
Jos (10584) am 2 Nov. 2017
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 Kommentar
Guillaume
Guillaume am 2 Nov. 2017
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{:});

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Statistics and Machine Learning Toolbox finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by