Matlab 立方体的边坐标
我有一个矩阵,对应于一个立方体的Matlab 立方体的边坐标,matlab,matrix,3d,Matlab,Matrix,3d,我有一个矩阵,对应于一个立方体的8漩涡 CubeVortex = [3 3 0; 0 3 0; 0 3 3; 3 3 3; 0 0 3; 3 0 3; 3 0 0; 0 0 0]; 现在我想得到在3中划分的所有边的坐标,比如 如您所见,将有12x2=24坐标 写它们会有点难 有没有办法从C
8漩涡
CubeVortex = [3 3 0;
0 3 0;
0 3 3;
3 3 3;
0 0 3;
3 0 3;
3 0 0;
0 0 0];
现在我想得到在3
中划分的所有边的坐标,比如
如您所见,将有12x2=24
坐标
写它们会有点难
有没有办法从CubeVortex计算它们?这应该可以做到:
NewVortex=[];
for i=1:3
NewVortex=[CubeVortex*i/3;NewVortex];
end
NewVortex
一种方法可以是这样-
n = 3; %// number of IDs
m = 3; %// number of columns
combs = dec2base(0:(n+1)^m-1,n+1,m)-'0' %// form repeated combinations
out = c1(sum(ismember(combs,[1 2]),2)==1,:) %// combinations for intermediate points
您可以将其用于N点
情况,并使其更为有效-
N = 3;
[x,y,z] = ndgrid(0:N,0:N,0:N)
combs = [z(:) y(:) x(:)]
out = combs(sum(combs~=0 & combs~=N,2)==1,:)
因此,对于您的3点(即0到3)情况,您将-
out =
0 0 1
0 0 2
0 1 0
0 1 3
0 2 0
0 2 3
0 3 1
0 3 2
1 0 0
1 0 3
1 3 0
1 3 3
2 0 0
2 0 3
2 3 0
2 3 3
3 0 1
3 0 2
3 1 0
3 1 3
3 2 0
3 2 3
3 3 1
3 3 2
一种方法是:
Cube = [
3 3 0;
0 3 0;
0 3 3;
3 3 3;
0 0 3;
3 0 3;
3 0 0;
0 0 0];
% find edges by looking for all combinations of points on cube that
% differ by only one coordinate
sections_per_edge = 3;
weights = ((1:sections_per_edge-1) / sections_per_edge).';
edges = []; % indices into Cube
points = [];
n = size(Cube, 1);
for i = 1:n-1
pointA = Cube(i, :);
for j = i+1:n
pointB = Cube(j, :);
if nnz(pointA - pointB) == 1
edges = [edges; i, j];
% find points along edge as weighted average of point A and B
points = [points; weights * pointA + (1 - weights) * pointB];
end
end
end
% plot corners
plot3(Cube(:,1), Cube(:,2), Cube(:,3), '.r', 'markersize', 20)
hold on
% plot points along edges
plot3(points(:,1), points(:,2), points(:,3), '.b', 'markersize', 20)
% draw edges
line([Cube(edges(:,1), 1), Cube(edges(:,2), 1)].', ...
[Cube(edges(:,1), 2), Cube(edges(:,2), 2)].', ...
[Cube(edges(:,1), 3), Cube(edges(:,2), 3)].', 'color', 'k')
axis([-1,4,-1,4])
结果:
将sections\u per\u edge
增加到10,您将得到
谢谢,但它有一些问题。