我仍然认为,为3D动画(移动点沿曲线)的可能性。我写了下面的code。使用hgtransform命令来尝试,但我不明白为什么不工作。
T = 0:PI / 50:10 * PI;
X = SIN(T);
Y = COS(T);
Z =吨;
啊=轴;
集(啊,'XLIM',[分钟(x)的最大值(X)],YLim',[分钟(Y)最大值(Y)],...
'ZLim',[分钟(z)的最大值(Z)]);
plot3(X,Y,Z,色彩,红色);
坚持住;
图(3);
H对准=行('扩展数据'中,x(1),'YDATA',Y(1),'ZData',Z(1),色彩,黑,标记,...
'O','MarkerSize',10'MarkerFaceColor','黑');
HT = hgtransform(父,啊);
集(H对准,'父',HT);
对于i = 2:长度(X)
TX = X(ⅰ)-x第(i-1);
TY = Y(I)-y第(i-1);
TZ = Z(ⅰ)-z第(i-1);
反= makehgtform(翻译,[TX TY TZ]),
集(HT,'矩阵',反式);
暂停(0.01);
结束
解决方案
您算算 TX
, TY
和 TZ
在你的循环如下:
TX = X(I)-x(1); %#注意1而不是I-1
TY = Y(I)-y(1);
TZ = Z(ⅰ)-z(1);
这是因为变换反
您应用于该点是一个的绝对的变换。换句话说,所述变换应用于所述的原来的位置上每次循环迭代,不向的最近的位置的
I continue to think of the possibilities for the 3d-animation (moving point along a curve). I have written the following code to try it using the hgtransform command but I do not understand why does not work.
t = 0:pi/50:10*pi;
x = sin(t);
y = cos(t);
z = t;
ah = axes;
set(ah,'XLim',[min(x) max(x)],'YLim',[min(y) max(y)],...
'ZLim',[min(z) max(z)]);
plot3(x,y,z,'Color','red');
hold on;
view(3);
hpoint = line('XData',x(1),'YData',y(1),'ZData',z(1),'Color','black','Marker',...
'o','MarkerSize',10,'MarkerFaceColor','black');
ht = hgtransform('parent',ah);
set(hpoint,'Parent',ht);
for i=2:length(x)
tx = x(i)-x(i-1);
ty = y(i)-y(i-1);
tz = z(i)-z(i-1);
trans = makehgtform('translate',[tx ty tz]),
set(ht,'Matrix',trans);
pause(0.01);
end
解决方案
You have to calculate tx
, ty
, and tz
in your loop as follows:
tx = x(i)-x(1); %# Note the 1 instead of i-1
ty = y(i)-y(1);
tz = z(i)-z(1);
This is because the transform trans
that you apply to the point is an absolute transform. In other words, the transform is applied to the original position of the point on each loop iteration, not to the most recent position.