Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
3D points representing cubes to 3D surface?

Subject: 3D points representing cubes to 3D surface?

From: Francisco Seixas

Date: 23 Nov, 2012 13:33:07

Message: 1 of 4

Hi there,

I have a Nx3 matrix where each row has x,y,z coordinates of points.

The points come from a 3D map and were generating by reading obstacle positions via a laser sensor, which were then approximated to the nearest cube center in a 3D cubic grid. This gives me the coordinates of the center of occupied cubes.

How can I transform these points into cubes that can be visualized in 3D? The cubes have a 1 unit side, so two consecutive cubes may have coordinates (20,20,20) and (20,20,21).

Thanks,
Francisco Seixas

Subject: 3D points representing cubes to 3D surface?

From: Roger Stafford

Date: 24 Nov, 2012 00:11:07

Message: 2 of 4

"Francisco Seixas" wrote in message <k8ntuj$aii$1@newscl01ah.mathworks.com>...
> How can I transform these points into cubes that can be visualized in 3D?
- - - - - - - - - -
  If it's of any help, this demonstrates how you can plot a single cube.

 A = [0 0 0];
 B = [1 0 0];
 C = [0 1 0];
 D = [0 0 1];
 E = [0 1 1];
 F = [1 0 1];
 G = [1 1 0];
 H = [1 1 1];
 P = [A;B;F;H;G;C;A;D;E;H;F;D;E;C;G;B];
 plot3(P(:,1),P(:,2),P(:,3))
 axis equal

Roger Stafford

Subject: 3D points representing cubes to 3D surface?

From: Bruno Luong

Date: 24 Nov, 2012 09:12:08

Message: 3 of 4

Here is a function that build edge topology for any dimension. Using this code we can see the number of edge hypercube in a 13th dimensional space is 53248.
  
n=3

c = repmat({[0 1]},[1 n]);
[c{:}] = ndgrid(c{:});
c = cat(n+1,c{:});
c = reshape(c,[],n);
[i, d] = ndgrid((1:2^n)',2.^(0:n-1));
j = (1-c) .* (i+d);
b = j>0;
e = [i(b) j(b)];

xyz = c(e',:);
xyz = reshape(xyz, 2, [], n);
xyz = num2cell(xyz,[1 2]);

if n==2
    plot(xyz{:});
elseif n==3
    plot3(xyz{:});
end

% Bruno

Subject: 3D points representing cubes to 3D surface?

From: Adam A

Date: 29 Nov, 2012 10:56:08

Message: 4 of 4

If A is your Nx3 matrix, then the following code should plot it:

B = zeros(max(A,[],1));
for loopR = 1:size(A,1)
  B(A(loopR ,1),A(loopR ,2),A(loopR ,3)) = 1;
end
PATCH_3Darray(B)

This uses the following function from the file exchange:
http://www.mathworks.co.uk/matlabcentral/fileexchange/28497-plot-a-3d-array-using-patch

Hope this helps,
Adam

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us