A Motion Visualization Method for Floating Bodies by ParaView

Motion visualization is useful for analyzing the numerical simulation results. In this post, I will demonstrate a method using MATLAB and paraview. The motion data, the stl files of water surface and object (boat) are prepared. In addition, the ‘stlwrite.m’ and ‘stlread.m’ are required.

stl file of boat

Next, stl files at each time step should be generated according to the elevation of water and the position/attitude of the object. The MATLAB codes are given as follows:

load motion.mat

% wave elevation
[f,v]=stlread('waterSurf.stl');
A=1;
T=8;
w=2*pi/T;
g=9.80665;
k=w^2/g;
indx=v(:,2)>10;
v(indx,2)=50;
indx=v(:,2)<-10;
v(indx,2)=-50;
indx= v(:,3)<0.05;
v(indx,3)=-70;
indx=v(:,3)>0.05;
for i=1:length(t)
    v_n=v;
    v_n(indx,3)=A*cos(w*t(i)-k*v(indx,1));
    filename=['waterSurf',num2str(i,'%03d'),'.stl'];
    stlwrite(filename,f,v_n);
end

%boat
[fb,vb]=stlread('boat.stl');
for i=1:length(t)
    R=Rzyx(eta(i,4),eta(i,5),eta(i,6));
    vb_n=repmat(eta(i,1:3),size(vb,1),1)+vb*R';
    filename=['boat',num2str(i,'%03d'),'.stl'];
    stlwrite(filename,fb,vb_n);
end

The source files can be found here. The generated stl files can then be opened by ParaView. The use of paraview may be introduced by other posts.

Leave a Comment

Your email address will not be published. Required fields are marked *