绘图后改变Matlab的三角形顶点(Change Matlab's trimesh vertices after plotting)

我有Matlab的trimesh函数的问题。

我需要做的是改变通过trimesh功能超时绘制的形状。 我实际上是通过再次绘制转换后的面来做到这一点,这给了我预期的形状。 这是我绘制形状的方式:

hc = trimesh(triangles,candide3(:,1),candide3(:,2),candide3(:,3));

这里candide3是一个113x3双顶点顶点,而三角形是一个184x3双矩阵索引,其中每一行都是一个三角形。 这完全是我想要的。 然后我需要转换面部 - 虽然三角形仍然是相同的矩阵,但是一些candide3需要实时更改(每秒约25次)。 如果我这样做:

candidet = transform(candide3, ...); trimesh(triangles,candide3(:,1),candide3(:,2),candide3(:,3));

我得到了我正在寻找的转变。 这很好,但还不够。 我想避免每秒调用trimesh 25次,而是设置新的顶点。 所以我尝试了set函数,如下所示:

candidet = transform(candide3, ...); set(hc,'XData',candidet(:,1),'YData',candidet(:,2),'ZData',candidet(:,3));

但这并没有给出预期的结果:它描绘了一堆三角形和表面,甚至没有接近我正在寻找的东西,它感觉奇怪和随意。 所以通过文档我也尝试了这个:

candidet = transform(candide3, ...); hc.XData = candidet(:,1); hc.YData = candidet(:,2); hc.ZData = candidet(:,3);

这就像上面的尝试一样废话。

我在Max OS X El Capitan上使用Matlab R2016b。 感谢任何想要帮助我的人。

I have a problem with Matlab's trimesh function.

What I need to do is change a shape plotted through the trimesh function overtime. I actually manage to do that by plotting the transformed face all over again, that gives me the expected shape. This is how I plot my shape:

hc = trimesh(triangles,candide3(:,1),candide3(:,2),candide3(:,3));

Here candide3 is a 113x3 double matrix of vertices, while triangles is a 184x3 double matrix of indexes, where every row is a triangle. This plots what I want, exactly. Then I need to transform the face - while triangles remains always the same matrix, a few entry of candide3 need to change overtime, in real time (approx. 25 times per second). If I do this:

candidet = transform(candide3, ...); trimesh(triangles,candide3(:,1),candide3(:,2),candide3(:,3));

I get exactly the transformation I am looking for. And that's fine, but not enough. I'd like to avoid calling trimesh 25 times per second and set the new vertices instead. So I tried the set function, like this:

candidet = transform(candide3, ...); set(hc,'XData',candidet(:,1),'YData',candidet(:,2),'ZData',candidet(:,3));

But this does not give the expected result: it plots a mess of triangles and surfaces that doesn't even go near to what I'm looking for, it feels weird and random. So looking through the documentation I tried this also:

candidet = transform(candide3, ...); hc.XData = candidet(:,1); hc.YData = candidet(:,2); hc.ZData = candidet(:,3);

And this give the same nonsense as the above try.

I am using Matlab R2016b on Max OS X El Capitan. Thanks to whoever will try to help me.

最满意答案

如果你检查trimesh如何trimesh内部工作,你会注意到它将参数triangles , x , y , z带入一个像这样的patch命令:

h = patch('faces',triangles,'vertices',[x(:) y(:) z(:)],'facevertexcdata',c(:),...);

因此,我建议您尝试以下方法:

hc = trimesh(triangles,candide3(:,1),candide3(:,2),candide3(:,3)); candidet = transform(candide3, ...); set(hc,'vertices',candidet);

If you check how trimesh works internally, you will notice that it takes the arguments triangles, x, y, z into a patch command like this:

h = patch('faces',triangles,'vertices',[x(:) y(:) z(:)],'facevertexcdata',c(:),...);

Therefore, I recommend trying the following:

hc = trimesh(triangles,candide3(:,1),candide3(:,2),candide3(:,3)); candidet = transform(candide3, ...); set(hc,'vertices',candidet);

更多推荐