如何在 MATLAB 中更新/动画复杂图形?

D.拉洛克

我需要为一个复杂的图形制作动画,该图形由一系列矩形组成,形成一个手臂。下面是这个手臂在没有动画时的样子的例子:

静态图

为了动画这个数字,我做了以下代码:

function renderFrame(fig, data)
    hold(ax, 'on'); % Need to hold so that new elements of the arm add themselves
    showMembers(fig, data); % Create patches and rotate them to the right angle to create members
    showJoints(fig, data); % Draw circles at the joints betwwen the members. Use the width of rectangle members  
    drawnow;
    hold(ax, 'off'); % Next rendering will replace this one; No need to hold
end

function rotateMember(fig, data, iMember, rotAngle)
    for iAngle = 1:rotAngle
        updateMemberAngle(data, i, 1); % Change thew data so the i-th member rotates by 1
        renderFrame(fig); % Show frame after the data was changed
    end
end

function main()
    fig = figure;
    ax = gca;
    axis(ax, 'equal');
    setAxis(data); % Set axis limits and create axis arrows with totalLength of the arm
    renderFrame(ax, data);
    rotateMember(fig, data, 3, 90); % Rotate 3rd member by 90 degrees
end

main()

但是我的动画帧根本不清晰。结果是这个图:

动图

我究竟做错了什么 ?有没有办法通过清除框架来绘制具有多个部分的复杂图形并为其设置动画?

我研究过使用newplotand nextplot,但MATLAB 关于该主题的文档一如既往地不完整。我还尝试创建图形对象,然后在每次迭代时设置数据,但每次删除图形时它都会拒绝异常,因为“图形对象已删除”。

D.拉洛克

找到了一种清除轴子项的方法,除了两个轴箭袋(箭头)。

这是一个正常工作的代码:

function renderFrame(renderAxes, data)

    % CHECK IF THERE ARE MORE GRAPHIC OBJECTS THAN ONLY THE QUIVERS
    if ~(length(renderAxes.Children) == 2)

        % DELETE EVERYTHING EXCEPT THE AXIS QUIVERS THAT WERE RENDERED AT THE BEGINNING
        % MATLAB ADDS NEW GRAPHIC OBJECTS TO THE BEGINNING OF AX.CHILDREN
        delete(renderAxes.Children(1:length(renderAxes.Children)-2))
    end

    showMembers(renderAxes, data); % Create patches and rotate them to the right angle to create members
    showJoints(renderAxes, data); % Draw circles at the joints betwwen the members. Use the width of rectangle members  
    drawnow;
end

function rotateMember(ax, data, iMember, rotAngle)
    for iAngle = 1:rotAngle
        updateMemberAngle(data, i, 1); % Change thew data so the i-th member rotates by 1
        renderFrame(ax, data); % Show frame after the data was changed
    end
end

function main()
    fig = figure;
    ax = gca;
    axis(ax, 'equal');

    % HOLD AXES AT THE BEGINNING OF THE SCRIPT
    hold(ax, 'on');

    setAxis(data); % Set axis limits and create axis arrows with totalLength of the arm
    renderFrame(ax, data);
    rotateMember(ax, data, 3, 90); % Rotate 3rd member by 90 degrees
end

main()

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何在Matlab中制作动画情节

来自分类Dev

如何在MATLAB中绘制不同角度的图形

来自分类Dev

如何在MATLAB图形中设置子图大小?

来自分类Dev

如何在Matlab中为非当前图形创建轴?

来自分类Dev

如何在MATLAB图形中的最小点上放置标记?

来自分类Dev

如何在Matlab中绘制图形的背景?

来自分类Dev

如何在Matlab脚本中组合不同的图形?

来自分类Dev

如何在Matlab中绘制图形的重叠区域?

来自分类Dev

如何在Matlab中为非当前图形创建轴?

来自分类Dev

如何在MATLAB中绘制不同角度的图形

来自分类Dev

如何在Matlab中标记图形

来自分类Dev

如何在Matlab中制作动画图

来自分类Dev

如何在Matlab中存储矢量坐标

来自分类Dev

如何在Matlab中检测平滑曲线

来自分类Dev

如何在MATLAB中解析可选输入?

来自分类Dev

如何在MATLAB中划分矩阵的列?

来自分类Dev

如何在MATLAB中设定哨兵值?

来自分类Dev

如何在MATLAB中关闭断言?

来自分类Dev

如何在Matlab中从stdin读取

来自分类Dev

如何在Matlab中模拟按钮单击

来自分类Dev

如何在Matlab中绘制圆?

来自分类Dev

如何在Matlab中绘制箭头?

来自分类Dev

如何在Matlab中对结构进行“引用”?

来自分类Dev

如何在Matlab中捕获警告?

来自分类Dev

如何在Matlab中覆盖帮助功能?

来自分类Dev

嵌套函数如何在MATLAB中工作?

来自分类Dev

如何在Matlab中创建命令别名

来自分类Dev

如何在Matlab uipanel中捕获按键

来自分类Dev

如何在Matlab中更改循环条件?