0
votes

I have a problem with fast plotting of a simple 3D model which I read from a .dxf file. The hole object is defined by points and the lines between them.

I have a matrix with coordinates. Every row is a unique point and every column is one coordinate.

Then I have an index matrix of size Nx2, where N is the number of rows in the model and on every row there are 2 points indexed from the coordinate matrix which should be connected by a line.

So the structure of the data is very similar to that of the data after triangulation and I need a function similar to trimesh or trisurf, though not for triangles, but for lines.

I can do that by letting a for loop cycle through the index matrix and plot every row separately, but it is very slow as compared built-in functions like trimesh.

Brief example:

%Coordinate matrix
NODES=[
  -12.76747  -13.63075   -6.41142
  -12.76747   -8.63075   -6.41142
  -8.76747  -13.63075   -6.41142
  -16.76747  -13.63075   -6.41142
  -11.76747  -7.63075   -2.41142
];

%index matrix
LINES=[
  1 2
  3 4
  1 4
  3 5
  1 5
];

%The slow way of creating the figure
figure(1)
    hold on

    for k=1:length(LINES)
      plot3(NODES(LINES(k,:), 1), NODES(LINES(k,:), 2), NODES(LINES(k,:), 3), '.-')

    end
    view(20, 20)
    hold off

I want to find a better and faster way to produce this figure

1
Please add a minimal reproducible example so we can look at the problem and try to fix it. - Adriaan
I add a simple example - nithiel

1 Answers

1
votes

I think the code is self-explanatory (it assumes that NODES and LINES are already defined):

%'Calculated: edge coordinates and line specs'
TI = transpose(LINES);
DI = 2*ones(1,size(TI,2));
X  = mat2cell(NODES(TI,1), DI);
Y  = mat2cell(NODES(TI,2), DI);
Z  = mat2cell(NODES(TI,3), DI);
L  = repmat({'.-'}, size(X));

%'Output: plot'
ARGS = transpose([X,Y,Z,L]);
plot3(ARGS{:});