⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sound2.m

📁 本程序讲述了如何模拟声音在自由空间和介质中的传输
💻 M
📖 第 1 页 / 共 3 页
字号:
end
ind=fliplr(ind);
hw=hw(ind);
hi=hi(ind);
for i=1:length(hw),
 indi((i-1)*2+1)=(ind(i)-1)*2+1;
 indi(2*i)=ind(i)*2;
end
hr=hr(indi);

%set axes layer
hch=[hso' hre hwv' flipud(sort(hav))' hw' hae' hi' hr' hsu' hxa' hya' hgr' ht hmt];
set(ha,'children',hch)

return

%=========================================================================
function [] = saveundo

%get object handle
ha=findobj('tag','acouaxes','parent',gcf);
hw=flipud(findobj('tag','acouwall','parent',ha));
hso=findobj('tag','acousource','parent',ha);

%data
xso=get(hso,'xdata');
yso=get(hso,'ydata');
xw=get(hw,'xdata');
yw=get(hw,'ydata');
for i=1:length(hw),
 xwall(i)=xw{i}(1);
 ywall(i)=yw{i}(1);
end
udf=get(gcf,'userdata');
undo=udf.undo;
if isempty(undo),
 undo.lastxwall=xwall;
 undo.lastywall=ywall;
 undo.lastxso=xso;
 undo.lastyso=yso;
 undo.newxwall=xwall;
 undo.newywall=ywall;
 undo.newxso=xso;
 undo.newyso=yso;
 udf.undo=undo;
 set(gcf,'userdata',udf)
 return
end
undo.lastxwall=undo.newxwall;
undo.lastywall=undo.newywall;
undo.lastxso=undo.newxso;
undo.lastyso=undo.newyso;
undo.newxwall=xwall;
undo.newywall=ywall;
undo.newxso=xso;
undo.newyso=yso;
udf.undo=undo;
set(gcf,'userdata',udf)

return

%=========================================================================
function [] = undolastchange

%get object handle
ha=findobj('tag','acouaxes','parent',gcf);
hw=flipud(findobj('tag','acouwall','parent',ha));

%data
ud=[];
for i=1:length(hw),
 ud=get(hw(i),'userdata');
 alpha(i)=ud.alpha;
end

udf=get(gcf,'userdata');
lastaction=udf.lastaction;
undo=udf.undo;
if isempty(undo) | ~strcmpi(lastaction,'movewallpoint'),
 return
end
xwall=undo.lastxwall;
ywall=undo.lastywall;
xso=undo.lastxso;
yso=undo.lastyso;
undo.lastxwall=undo.newxwall;
undo.lastywall=undo.newywall;
undo.lastxso=undo.newxso;
undo.lastyso=undo.newyso;
undo.newxwall=xwall;
undo.newywall=ywall;
undo.newxso=xso;
undo.newyso=yso;
udf.undo=undo;
set(gcf,'userdata',udf)
prop=[];
prop.xwall=xwall;
prop.ywall=ywall;
prop.xlim=get(ha,'xlim');
prop.ylim=get(ha,'ylim');
prop.xso=xso;
prop.yso=yso;
prop.alpha=alpha;
prop.noaudiencechange=[];
prop.noselectchange=[];
update(prop)

return

%=========================================================================
function [] = movedrawing

%get handles
ha=findobj('tag','acouaxes','parent',gcf);
hw=findobj('tag','acouwall','parent',ha);
hae=findobj('tag','acouaudienceedge','parent',ha);
hso=findobj('tag','acousource','parent',ha);
hbz=findobj('tag','acouzoombutton','parent',gcf);

%get data
xw=get(hw,'xdata');
yw=get(hw,'ydata');
nwall=length(hw);
for i=1:nwall,
 xww(i)=xw{i}(1);
 yww(i)=yw{i}(1);
end
xae=get(hae,'xdata');
yae=get(hae,'ydata');
naedge=length(hae);
for i=1:naedge,
 xa(i)=xae{i}(1);
 ya(i)=yae{i}(1);
end
xso=get(hso,'xdata');
yso=get(hso,'ydata');
xmin=min([xww xa xso]);
xmax=max([xww xa xso]);
ymin=min([yww ya yso]);
ymax=max([yww ya yso]);
dx=xmax-xmin;
dy=ymax-ymin;
udf=get(gcf,'userdata');
height=udf.height;
gsize=udf.gsize;
xlim=udf.xlim;
ylim=udf.ylim;

%offset function of dimensions
zdis=  [ 4   10   20 40 80 160 320 640];
gsizes=[0.1 0.25 0.5  1  2  4   8   16];
dd=max([xmax-xmin ymax-ymin]);
indi=find(zdis >= dd);
if ~isempty(indi),
 ofs=gsizes(indi(1));
else
 ofs=1;
end

%change axis limits
if strcmpi(get(gcbo,'tag'),'acoumoveup'),
 if ylim(2)-ofs >= ymax,
  ylim=ylim-ofs;
 end
elseif strcmpi(get(gcbo,'tag'),'acoumoveright'),
 if xlim(2)-ofs >= xmax,
  xlim=xlim-ofs;
 end
elseif strcmpi(get(gcbo,'tag'),'acoumovedown'),
 if ylim(1)+ofs <= ymin,
  ylim=ylim+ofs;
 end
elseif strcmpi(get(gcbo,'tag'),'acoumoveleft'),
 if xlim(1)+ofs <= xmin,
  xlim=xlim+ofs;
 end
elseif strcmpi(get(gcbo,'tag'),'acoucenter'),
 xm=(xmax+xmin)/2;
 ym=(ymax+ymin)/2;
 dxlim=xlim(2)-xlim(1);
 dylim=ylim(2)-ylim(1);
 xlim=xm+[-dxlim/2 dxlim/2];
 ylim=ym+[-dylim/2 dylim/2];
end
if ~get(hbz,'value'),
 set(ha,'xlim',xlim)
 set(ha,'ylim',ylim)
end
udf.xlim=xlim;
udf.ylim=ylim;
set(gcf,'userdata',udf)
changegrid(udf.gsize)
if get(hbz,'value'),
 acouzoom;
end

return

%=========================================================================
function [] = moveaxis

tol=1e-6;
ha=findobj('tag','acouaxes','parent',gcf);
hxa=findobj('tag','acouXaxis','parent',ha);
hya=findobj('tag','acouYaxis','parent',ha);
ht=findobj('tag','acoutext','parent',ha);
hbu=findobj('tag','acousnapbutton','parent',gcf);
hgr=findobj('tag','acougrid','parent',gca);
hca=gco;
co=get(ha,'currentpoint');
x1=co(1,1);
y1=co(1,2);
if get(hbu,'value'),
 xg=get(hgr,'xdata');
 yg=get(hgr,'ydata');
 d=sqrt((xg-x1).^2+(yg-y1).^2);
 [vmin,imin]=min(d);
 x1=xg(imin);
 y1=yg(imin);
end
ud=get(gcf,'userdata');
height=ud.height;
xlim=ud.xlim;
ylim=ud.ylim;
x1=min([x1 xlim(2)]);
x1=max([x1 xlim(1)]);
y1=min([y1 ylim(2)]);
y1=max([y1 ylim(1)]);
if strcmpi(get(hca,'tag'),'acouXaxis'),
 st=['X axis : distance from bottom border ' num2str(round((y1-ylim(1))*100)/100)];
 set(ht,'string',st)
 set(hxa,'ydata',[y1 y1])
else
 st=['Y axis : distance from left border ' num2str(round((x1-xlim(1))*100)/100)];
 set(ht,'string',st)
 set(hya,'xdata',[x1 x1])
end

return

%=========================================================================
function [] = refreshcoordinates

%get handles
ha=findobj('tag','acouaxes','parent',gcf);
hwv=findobj('tag','acouwallvertex','parent',ha);
hw=findobj('tag','acouwall','parent',ha);
hav=findobj('tag','acouaudiencevertex','parent',ha);
hae=findobj('tag','acouaudienceedge','parent',ha);
hso=findobj('tag','acousource','parent',ha);
hre=findobj('tag','acoureceptor','parent',ha);
hxa=findobj('tag','acouXaxis','parent',ha);
hya=findobj('tag','acouYaxis','parent',ha);

%get data
yor=get(hxa,'ydata');
yor=yor(1);
xor=get(hya,'xdata');
xor=xor(1);

%apply move
for i=1:length(hwv),
 xwv=get(hwv(i),'xdata')-xor;
 ywv=get(hwv(i),'ydata')-yor;
 xw=get(hw(i),'xdata')-xor;
 yw=get(hw(i),'ydata')-yor;
 set(hwv(i),'xdata',xwv)
 set(hwv(i),'ydata',ywv)
 set(hw(i),'xdata',xw)
 set(hw(i),'ydata',yw)
end
for i=1:length(hav),
 xav=get(hav(i),'xdata')-xor;
 yav=get(hav(i),'ydata')-yor;
 set(hav(i),'xdata',xav)
 set(hav(i),'ydata',yav)
 xae=get(hae(i),'xdata')-xor;
 yae=get(hae(i),'ydata')-yor;
 set(hae(i),'xdata',xae)
 set(hae(i),'ydata',yae)
end
xso=get(hso,'xdata')-xor;
yso=get(hso,'ydata')-yor;
set(hso,'xdata',xso)
set(hso,'ydata',yso)
xre=get(hre,'xdata')-xor;
yre=get(hre,'ydata')-yor;
set(hre,'xdata',xre)
set(hre,'ydata',yre)
set(hxa,'ydata',[0 0])
set(hya,'xdata',[0 0])
set(ha,'xlim',get(ha,'xlim')-xor)
set(ha,'ylim',get(ha,'ylim')-yor)
udf=get(gcf,'userdata');
xlim=udf.xlim;
xlim=xlim-xor;
ylim=udf.ylim;
ylim=ylim-yor;
udf.xlim=xlim;
udf.ylim=ylim;
set(gcf,'userdata',udf)
changegrid(udf.gsize)

return

%=========================================================================
function [] = movewallpoint

tol=1e-6;
ha=findobj('tag','acouaxes','parent',gcf);
hso=findobj('tag','acousource','parent',ha);
ht=findobj('tag','acoutext','parent',ha);
hcv=gco;
ud=get(hcv,'userdata');
con=ud.con;
h1=con(1);
h2=con(2);
xw1=get(h1,'xdata');
yw1=get(h1,'ydata');
xw2=get(h2,'xdata');
yw2=get(h2,'ydata');
xso=get(hso,'xdata');
yso=get(hso,'ydata');
co=get(ha,'currentpoint');
x1=co(1,1);
y1=co(1,2);
hbu=findobj('tag','acousnapbutton','parent',gcf);
hbuu=findobj('tag','acouconstrainbutton','parent',gcf);
if get(hbuu,'value'),
 xx1=xw1(1);
 yy1=yw1(1);
 xx2=xw2(2);
 yy2=yw2(2);
 L=sqrt((xx2-xx1)^2+(yy2-yy1)^2);
 if L < 0.1,
  return
 end
 v1=(xx2-xx1)/L;
 v2=(yy2-yy1)/L;
 n1=-v2;
 n2=v1;
 M=[v1 -n1;v2 -n2];
 SM=[x1-xx1;y1-yy1];
 sol=inv(M)*SM;
 t=sol(1)/L;
 if t < 0.001 | t > 0.999,
  return
 end
 x1=xx1+t*v1*L;
 y1=yy1+t*v2*L;
 L1=t*L;
 L2=(1-t)*L;
 L1=round(L1*10)/10;
 L2=round(L2*10)/10;
elseif get(hbu,'value'),
 hgr=findobj('tag','acougrid','parent',gca);
 xg=get(hgr,'xdata');
 yg=get(hgr,'ydata');
 d=sqrt((xg-x1).^2+(yg-y1).^2);
 [vmin,imin]=min(d);
 x1=xg(imin);
 y1=yg(imin);
end
ud=get(gcf,'userdata');
height=ud.height;
xlim=ud.xlim;
ylim=ud.ylim;
x1=min([x1 xlim(2)]);
x1=max([x1 xlim(1)]);
y1=min([y1 ylim(2)]);
y1=max([y1 ylim(1)]);
if get(hbuu,'value'),
 st=['Vertex : ( ' num2str(round(x1*100)/100) ' , ' num2str(round(y1*100)/100) ' )       Wall length : ' num2str(L1) ' / ' num2str(L2) ];
else,
 x0=xw1(1);
 y0=yw1(1);
 x2=xw2(2);
 y2=yw2(2);
 L1=sqrt((x0-x1)^2+(y0-y1)^2);
 if L1 >= tol,
  th1=acos(abs(x1-x0)/L1);
 else
  th1=0;
 end
 L1=round(L1*10)/10;
 th1=round(th1/pi*180);
 L2=sqrt((x2-x1)^2+(y2-y1)^2);
 if L2 >= tol,
  th2=acos(abs(x2-x1)/L2);
 else
  th2=0;
 end
 L2=round(L2*10)/10;
 th2=round(th2/pi*180);
 st=['Vertex : ( ' num2str(round(x1*100)/100) ' , ' num2str(round(y1*100)/100) ' )      Wall length : ' num2str(L1) ' / ' num2str(L2) '      Wall angle : ' num2str(th1) '

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -