ok, i found out that i can import stl files into blender and matlab users can use 'surf2stl' to export figures. But I have no idea how to use this 'surf2stl' function, please help
Matlab figure export to blender or stl [using surf2stl]
19 views (last 30 days)
Show older comments
Hi
Is there anyway to export matlab figures into Blender (3D animation software)
If possible [not necessary] is there anyway to export animations made in matlab also to blender?
Thanks in advance
Following is the full code i am using for the figures and animations:
function [u,x,y,t]= membwave(type,dims,alp,w,tmax)
disp('')
disp('WAVE MOTION IN A RECTANGULAR OR CIRCULAR')
disp(' MEMBRANE HAVING AN OSCILLATING LOAD')
if nargin > 0 % Data passed through the call list
% must specify: type, dims, alp, w, tmax
% Typical values are: a=2; b=1; alp=1;
% w=18.4; x0=1; y0=0.5; tmax=5;
if type==1
a=dims(1); b=dims(2); x0=dims(3); y0=dims(4);
[u,x,y,t]=memrecwv(a,b,alp,w,x0,y0,tmax);
else
r0=dims(1);
end
else % Interactive data input
disp(' '), disp('Select the geometry type:')
type=input(['Enter 1 for a rectangle, ',...
'2 for a circle > ? ']);
if type ==1
disp(' ')
disp('Specify the rectangle dimensions:')
s=input('Give values for a,b > ? ','s');
s=eval(['[',s,']']); a=s(1); b=s(2);
disp(' ')
disp('Give coordinates (x0,y0) where the')
s=input('force acts. Enter x0,y0 > ? ','s');
s=eval(['[',s,']']); x0=s(1); y0=s(2);
disp(' '), alp=input('Enter the wave speed > ? ');
N=40; M=40; pan=pi/a*(1:N)'; pbm=pi/b*(1:M);
W=alp*sqrt(repmat(pan.^2,1,M)+repmat(pbm.^2,N,1));
wsort=sort(W(:)); wsort=reshape(wsort(1:42),6,7)';
disp(' ')
disp(['The first forty-two natural ',...
'requencies are:'])
disp(wsort)
w=input(...
'Input the frequency of the forcing function ?');
else
disp(' '), disp(...
'The circle radius equals one. Give the radial')
disp(...
'distance r0 from the circle center to the')
r0=input('force > ? ');
disp(' '), alp=input('Enter the wave speed > ?');
% First 42 Bessel function roots
wsort=alp*[...
2.4048 3.8317 5.1356 5.5201 6.3801 7.0156
7.5883 8.4173 8.6537 8.7715 9.7611 9.9362
10.1735 11.0647 11.0864 11.6199 11.7916 12.2251
12.3385 13.0152 13.3237 13.3543 13.5893 14.3726
14.4755 14.7960 14.8213 14.9309 15.5898 15.7002
16.0378 16.2234 16.4707 16.6983 17.0037 17.2412
17.6159 17.8014 17.9599 18.0711 18.2876 18.4335];
disp(' '), disp(['The first forty-two',...
'natural frequencies are:'])
disp(wsort)
w=input('Input the frequency of the forcing function ? ');
end
disp(' ')
disp('Input the maximum solution evaluation time.')
tmax=input(' > ? ');
end
if type==1
[u,x,y,t]=memrecwv(a,b,alp,w,x0,y0,tmax);
else
th=linspace(0,2*pi,81); r=linspace(0,1,20);
[u,x,y,t]=memcirwv(r,th,r0,alp,w,tmax);
end
% Animate the solution
membanim(u,x,y,t);
function [u, x, y, t]=memrecwv (a, b, alp, w, x0, y0, tmax)
if nargin==0
a=2; b=1; alp=1; tmax=3; w=13; x0=1.5; y0=0.5;
end
if a<b
nx=31; ny=round(b/a*21); ny=ny+rem(ny+1,2);
else
ny=31; nx=round(a/b*21); nx=nx+rem(nx+1,2);
end
x=linspace(0,a,nx); y=linspace(0,b,ny);
N=40; M=40; pan=pi/a*(1:N)'; pbm=pi/b*(1:M);
W=alp*sqrt(repmat(pan.^2,1,M)+repmat(pbm.^2,N,1));
wsort=sort(W(:)); wsort=reshape(wsort(1:30),5,6)';
Nt=ceil(40*tmax*alp/min(a,b));
t=tmax/(Nt-1)*(0:Nt-1);
mat=sin(x0*pan)*sin(y0*pbm)./(w^2-W.^2);
sxn=sin(x(:)*pan'); smy=sin(pbm'*y(:)');
u=zeros(ny,nx,Nt);
for j=1:Nt
A=mat.*(cos(w*t(j))-cos(W*t(j)));
uj=sxn*(A*smy); u(:,:,j)=uj';
end
function [u,x,y,t,r,th]=memcirwv(r,th,r0,alp,w,tmax)
if nargin==0
r0=.4; w=15.5; th=linspace(0,2*pi,81);
r=linspace(0,1,21); alp=1;
end
Nt=ceil(20*alp*tmax); t=tmax/(Nt-1)*(0:Nt-1);
lam=besjroot(0:20,20,1e-3);
[nj,nk]=size(lam); r=r(:)'; nr=length(r);
th=th(:); nth=length(th); nt=length(t);
N=repmat((0:nj-1)',1,nk); Nvec=N(:)';
c=besselj(N,lam*r0)./(besselj(N+1,lam).^2.*(lam.^2-w^2));
c(1,:)=c(1,:)/2; c=c(:)';
lamvec=lam(:)'; wlam=w./lamvec;
c=cos(th*Nvec).*repmat(c,nth,1);
rmat=besselj(repmat(Nvec',1,nr),lamvec'*r);
u=zeros(nth,nr,nt);
for k=1:nt
tvec=-cos(w*t(k))+cos(lamvec*t(k));
u(:,:,k)=c.*repmat(tvec,nth,1)*rmat;
end
u=2/pi*u; x=cos(th)*r; y=sin(th)*r;
function rts=besjroot(norder,nrts,tol)
if nargin<3, tol=1e-5; end
jn=inline('besselj(n,x)','x','n');
N=length(norder); rts=ones(N,nrts)*nan;
opt=optimset('TolFun',tol,'TolX',tol);
for k=1:N
n=norder(k); xmax=1.25*pi*(nrts-1/4+n/2);
xsrch=.1:pi/4:xmax; fb=besselj(n,xsrch);
nf=length(fb); K=find(fb(1:nf-1).*fb(2:nf)<=0);
if length(K)<nrts
disp('Search error in function besjroot')
rts=nan; return
else
K=K(1:nrts);
for i=1:nrts
interval=xsrch(K(i):K(i)+1);
rts(k,i)=fzero(jn,interval,opt,n);
end
end
end
function membanim(u,x,y,t)
if nargin==0;
[u,x,y,t]=memrecwv(2,1,1,15.5,1.5,.5,5);
end
xmin=min(x(:)); xmax=max(x(:));
ymin=min(y(:)); ymax=max(y(:));
xmid=(xmin+xmax)/2; ymid=(ymin+ymax)/2;
d=max(xmax-xmin,ymax-ymin)/2; Nt=length(t);
range=[xmid-d,xmid+d,ymid-d,ymid+d, 3*min(u(:)),3*max(u(:))];
while 1 % Show the animation repeatedly
disp(' '), disp('Press return for animation')
dumy=input('or enter 0 to stop > ? ','s');
if ~isempty(dumy)
disp(' '), disp('All done'), break
end
for j=1:Nt
surf(x,y,u(:,:,j)), axis(range)
xlabel('x axis'), ylabel('y axis')
zlabel('u axis'), titl=sprintf('MEMBRANE POSITION AT T=%5.2f',t(j));
title(titl), colormap([1 1 1])
colormap([127/255 1 212/255])
drawnow, shg, pause(.1)
end
end
If you want to run the simulation use the following parameters after the question is asked in the command window
WAVE MOTION IN A RECTANGULAR OR CIRCULAR MEMBRANE HAVING AN OSCILLATING LOAD
Select the geometry type: Enter 1 for a rectangle, 2 for a circle > ? 1
Specify the rectangle dimensions: Give values for a,b > ? 10, 10
Give coordinates (x0,y0) where the force acts. Enter x0,y0 > ? 5, 5
Enter the wave speed > ? 1
The first forty-two natural requencies are: Columns 1 through 5
0.4443 0.7025 0.7025 0.8886 0.9935
1.1327 1.1327 1.2953 1.2953 1.3329
1.4050 1.5708 1.5708 1.6019 1.6019
1.6918 1.7772 1.8318 1.8318 1.9110
1.9869 1.9869 2.0116 2.0116 2.1074
2.2214 2.2214 2.2214 2.2654 2.2654
2.2871 2.3926 2.3926 2.4537 2.4537
Column 6
0.9935
1.4050
1.6918
1.9110
2.1074
2.2871
2.5328
Input the frequency of the forcing function ?5
Input the maximum solution evaluation time. > ? 10
Press return for animation or enter 0 to stop > ?
Accepted Answer
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!