Question about speeding up line plotting
显示 更早的评论
Hello, thanks for reading this,
What I do currently in some MATLAB code is plot3 a series of lines, defined by a beginning and end point. I have 3d coordinate info stored in a nx3 pt matrix, and the connectivity information stored in a mx2 matrix. The data can look something like:
ptMx = [-0.0004 0.0003 1.9039
-0.0004 0.0003 1.1424
-0.1502 0.0001 0.6856
0.1397 0.0004 0.6853];
faceMx = [1 2
2 3
2 4]
So point 1 is connected to point 2, 2 to 3, and 2 to 4. I plot these with the following code:
for i=1:size(faceMx,1)
hold on
plot3([ptMx(faceMx(i,1),1) ptMx(faceMx(i,2),1)], ...
[ptMx(faceMx(i,1),2) ptMx(faceMx(i,2),2)], ...
[ptMx(faceMx(i,1),3) ptMx(faceMx(i,2),3)])
end
So as you can see, I go through every element and hold on a plot3 line. My problem is this can take a very large amount of time, and it makes rotating/translating the plot very slow. Is there a better/faster way to draw a series of lines this way?
Thanks!
EDIT: I know I can switch plot3 to line to speed this up a little bit, I was hoping if there was a better way available. Sometimes, I can be plotting up to 50k lines, and during these times patches of surface meshes with triangle patches with a similar number is many times faster.
采纳的回答
更多回答(1 个)
Walter Roberson
2016-2-24
You should be using patch() with ptMx as all your vertices, and your first row of your Faces list would be [1 2 3 4] . That would produce a closed face; if you want an open face then add a vertex at nan as the list
ptMx = [nan nan nan
-0.0004 0.0003 1.9039
-0.0004 0.0003 1.1424
-0.1502 0.0001 0.6856
0.1397 0.0004 0.6853];
faces [2 3 4 5 1; .... ]
类别
在 帮助中心 和 File Exchange 中查找有关 Graphics Performance 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!