Lissajous曲线动画演示(Matlab实现)

在别人的博文里看到 Lissajous曲线的动态图, 感觉还挺帅,于是自己也想玩一下。


最终效果

最终效果


Lissajous曲线

在数学上,Lissajous曲线 [1] (又称Lissajous图形或Bowditch曲线)是由如下参数方程构成的曲线族的图形

{x=Asin(at+φ)y=Bsin(bt)

纳撒尼尔·鲍迪奇(Nathaniel Bowditch)在1815年首先研究了这一曲线族,之后在1857年由朱尔斯·安东尼·利萨如(Jules Antoine Lissajous)进行了更详细的研究。

在物理上,Lissajous曲线可以看作是一个质点同时在X轴和Y轴方向上做简谐运动形成的运动轨迹(以我仅剩的一点物理知识来说,这大概是叫”运动的合成”)。
当这两个相互垂直方向上的简谐振动的频率为任意值时,那么它们合成的运动可能会比较复杂,轨迹是不稳定的,示意图如下。(所谓稳定,我的理解大概就是呈周期性吧)


一个示意图

一个示意图

而如果这两个振动的频率成简单的整数比,就能合成一个规则的、稳定的闭合曲线,这就是Lissajous曲线(示意图如下)。


另一个示意图

另一个示意图

具体实现

  • 环境: Matlab R2017a

Animated Line 实现动画效果

首先用animatedline创建初始动画线条对象 [2] ,接着在循环中动态地向线条中添加点,并使用 drawnow 在屏幕上显示该新添加的点,然后用getframe捕获的当前图像。

%%
% Create a new figure window,
% Background color is white
% MenuBar is hidden
% Image size is 480*480
figure('Color','w','MenuBar','none','InnerPosition',[0 0 480 480]);
co = [65/255, 131/255, 196/255]; % specify the color
% Create animated line object
headMarker = animatedline('LineStyle','none','Marker','o','Color',co,'MarkerFaceColor',co);
body = animatedline('LineStyle','-','LineWidth',1.3,'Color',co); % trajectory
axis([-1,1,-1,1]); axis off; % hide axis

%% 
% Parameters
a = 13;
b = 18;
phi = pi * 0;

% Parametric Equation of Lissajous Curve
t = linspace(0,2*pi,1000); % generate 1000 linearly equally spaced points
x = sin(a*t + phi);
y = sin(b*t);

%%
% Display
for idx = 1:length(t)
    addpoints(headMarker,x(idx),y(idx));
    addpoints(body,x(idx),y(idx));
    drawnow 
    % Capture the current plot
    frame = getframe; % snapshot of the current axes
    im{idx} = frame2im(frame); % write image data to `im`
    % Remove previous head marker except for the last one
    if idx~=length(t)
        clearpoints(headMarker);
    end
end

写入GIF动图

getframe捕获的每一个图像,写入 GIF 动画文件 [3]

%%
% Save images into a GIF file. 
% Because three-dimensional data is not supported for GIF files, 
% call rgb2ind to convert the RGB data in the image to an indexed image A with a colormap map. 
filename = 'Lissajous.gif'; % specify the output file name
for idx = 1:length(t)
    [A,map] = rgb2ind(im{idx},256);
    if idx == 1
        % Set DelayTime = 0 to display next images as fast as your hardware allows
        imwrite(A,map,filename,'gif','LoopCount',Inf,'DelayTime',0);
    else
        % To append multiple images to the first image
        imwrite(A,map,filename,'gif','WriteMode','append','DelayTime',0);
    end
end

完整代码链接

参考

  1. http://www.matrix67.com/blog/archives/6947
  2. https://codepen.io/handsomeone/full/Kgmbqg
  3. https://cn.mathworks.com/matlabcentral/fileexchange/28987-lissajous-curve
  4. https://cn.mathworks.com/examples/matlab/community/22655-lissajous-curves
  5. http://www.baike.com/wiki/%E5%88%A9%E8%90%A8%E5%A6%82%E5%9B%BE%E5%BD%A2

本文作者: 小路
本文链接: http://tinyland.site/posts/2017-07-02-matlab-implementation-for-lissajous-curve-animation-demo.html

  • 2
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值