简体   繁体   English

在Matlab中为3D绘图数据点添加字母

[英]Adding letters to 3D plot data points in Matlab

I am currently working on a 3D representation of a hand fingers moving. 我目前正在研究手指移动的3D表示。 You can see on the picture below how it looks like, since it would be too complicated to describe otherwise: 您可以在下面的图片中看到它的外观,因为否则很难描述:

手代表

It is an animation, so it's moving constantly. 这是动画,所以它在不断地移动。 There is one dot for each finger, and one dot for the palm. 每个手指有一个点,手掌有一个点。 However, I can't keep track of the fingers. 但是,我无法跟踪手指。 I tried to give them different colors, but it doesn't help a lot. 我尝试给它们提供不同的颜色,但是并没有太大帮助。

So the question is: 所以问题是:

  • Is there a way to replace the circles, or any other symbol, with an actual letter, or even short word (3-4 letters)? 有没有办法用一个实际的字母,甚至是一个简短的单词(3-4个字母)来替换圆圈或任何其他符号?

  • Alternatively (and it is quite a stretch, but why not ask?), would there be a way to draw lines joining these dots together? 另外(这是一个很大的过程,但是为什么不问呢?),是否有办法画出将这些点连接在一起的线? This is optional, and I might open another question regarding it if necessary. 这是可选的,如有必要,我可能会提出另一个问题。

Thanks! 谢谢!

Here is the actual code; 这是实际的代码; I know it is far from being elegant coding, and am sorry about it, but it works, which is already a great step for me: 我知道它远非优雅的编码,对此感到抱歉,但是它有效,对我来说已经迈出了一大步:

clear all
clc

csv=csvread('pilot6/maindroite.csv',1,0); %read the values from a csv
both = csv(:,2:19);

ax=axes;
set(ax,'NextPlot','replacechildren');

Dt=0.1; %sampling period in secs

k=1;
hp1=plot3(both(k,1),both(k,2),both(k,3),'ok'); %get handle to dot object
hold on;
hp2=plot3(both(k,4),both(k,5),both(k,6),'og');
hp3=plot3(both(k,7),both(k,8),both(k,9),'ob');
hp4=plot3(both(k,10),both(k,11),both(k,12),'oc');
hp5=plot3(both(k,13),both(k,14),both(k,15),'om');
hp6=plot3(both(k,16),both(k,17),both(k,18),'or');
hold off;

t1=timer('TimerFcn','k=doPlot(hp1,hp2,hp3,hp4,hp5,hp6,both,t1,k)','Period', Dt,'ExecutionMode','fixedRate');
start(t1);

and the function used: 以及使用的功能:

function k=doPlot(hp1,hp2,hp3,hp4,hp5,hp6,pos,t1,k)

k=k+1;
if k<5000%length(pos)
   set(hp1,'XData',pos(k,1),'YData',pos(k,2),'ZData',pos(k,3));
   axis([0 255 0 255 0 255]);
   set(hp2,'XData',pos(k,4),'YData',pos(k,5),'ZData',pos(k,6));
   set(hp3,'XData',pos(k,7),'YData',pos(k,8),'ZData',pos(k,9));
   set(hp4,'XData',pos(k,10),'YData',pos(k,11),'ZData',pos(k,12));
   set(hp5,'XData',pos(k,13),'YData',pos(k,14),'ZData',pos(k,15));
   set(hp6,'XData',pos(k,16),'YData',pos(k,17),'ZData',pos(k,18));

else
    k=1;
    set(hp,'XData',pos(k,1),'YData',pos(k,2),'ZData',pos(k,3));
   axis([0 255 0 255 0 255]);
end

I just want to mention this is based heavily on Jorge's answer on this question , so thanks to him again 我只想提一下,这很大程度上取决于Jorge对这个问题的回答 ,所以再次感谢他

  1. text(x,y,z,'string') instead of plot3 should work in changing the points to text where [x,y,z] is the coordinate of each point you are plotting. text(x,y,z,'string')代替plot3应该可以将点更改为文本,其中[x,y,z]是要绘制的每个点的坐标。
    Note: calls to set will need to change from set(hp3,'XData',x,'YData',y,'ZData',z) to set(htext,'pos',[x,y,z]) . 注意:set调用需要从set(hp3,'XData',x,'YData',y,'ZData',z)更改为set(htext,'pos',[x,y,z]) Where hp3 is the handle to a plot3-handle object and htext is a handle to a text-handle object. 其中hp3plot3-handle对象的句柄,而htexttext-handle对象text-handle

  2. To connect the points with a line use plot3(X,Y,Z) where X=[x_1,x_2,...,x_n] , Y=[y_1,y_2,...,y_n] and Z=[z_1,z_2,...,z_n] . 要将点与直线连接,请使用plot3(X,Y,Z) ,其中X=[x_1,x_2,...,x_n]Y=[y_1,y_2,...,y_n]Z=[z_1,z_2,...,z_n]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM