在 Matlab 中使用 hgtransform 命令绘制 3D 动画图 [英] 3D-Animation plot with the hgtransform command in Matlab

查看:32
本文介绍了在 Matlab 中使用 hgtransform 命令绘制 3D 动画图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我继续考虑 3d 动画(沿曲线移动点)的可能性.我已经编写了以下代码来尝试使用 hgtransform 命令,但我不明白为什么不起作用.

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

推荐答案

你必须计算 txtytz 在你的循环如下:

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);

这是因为您应用到该点的变换 trans 是一个 绝对 变换.换句话说,变换应用于每次循环迭代中点的原始位置,而不是最近位置.

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.

这篇关于在 Matlab 中使用 hgtransform 命令绘制 3D 动画图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆