next up previous adam-math, MATmatcc, MMKOMP MMkomp2 Adam WILEY-VCH MATLAB-Filme Projekte und M-Files Stefan Adam privat Mail to stefan.r.a.adam@gmail.com MMkomp ed1 Adam
Nächste Seite: 3D Lissajous-Figuren Aufwärts: MMkomp2 Filmserie Vorherige Seite: Fadensterne zwischen den Szenen

Reguläre Polygone

Ein Spiel mit regulären Polygonen vom Dreieck bis zum Achteck.

% newpolygonfilms
%  Kombination von Poygonmandala und Polygon Extruder
% polygonfilms -  Aufbau von regulaeren Dreiecken bis zu Achtecken
% und anschliessend drehend Verschwinden der Polygone
%  uses simpbezier und simplinipo
figure(1); clf;
ntot=9; colvar = ['r','g','b','m','c','r'];
w = zeros(1,ntot);
r=9.8; sgen = 2*r*sin(pi/8); rn = zeros(1,8);
voidbk = 0;
t = (0:0.005:1)*2*pi;
for ne = 3:8
  rn(ne) = sgen/2/sin(pi/ne);   
end
%
hdtx(1) = text(-9.6,9.5,'Polygon', ...
    'FontUnits','points','FontSize',20 , ...
   'Fontweight','demi');
%
  axis([-12 12 -12 12]); axis equal
  axis off ; hold on;
  hdtx(2) = text(2.6,9.5,'- Reigen', ...
    'FontUnits','points','FontSize',20 , ...
   'Fontweight','demi');
we = zeros(8,9);
for ne = 3:8   
  xk = rn(ne)*cos(t); yk = rn(ne)*sin(t);
  krhdl(ne) = plot(xk,yk,'k','LineWidth',1);    
  k=1; kbeg = 0;
  wn = 0;
  for wn = 0:0.005:1
    we(ne,ntot) = wn ;
    if wn > k/ne
      we(ne,ntot-k-1+(1:k)) = (1:k)/ne;
      k=k+1;
    end
    if kbeg>0
      delete(plhd(ne))
    end
    if ne > 3
        delete(krhdl(ne-1))
    end
    kbeg=1;
    x=rn(ne)*sin(2*pi*we(ne,:));
    y=rn(ne)*cos(2*pi*we(ne,:));
    plhd(ne) = plot(x,y,colvar(ne-2),'LineWidth',4);
    pause(0.008)
  end
end
delete(krhdl(8))
% Verdrehen
hvals = [0.28 0.42 0.55 0.7 0.85 1];
xpt = [0 0.65 0.7 1];
for lev = 1:6
    [xbez(lev,:),ybez(lev,:)] = simpbezier(hvals(lev),0.02);
end
wend = 5;
for wd = 0:0.005:wend
  u = wd/wend;
  for nro = 3:8
    delete(plhd(nro))
    rf = simplinipo(xbez(nro-2,:),ybez(nro-2,:),u);
    x=rf*rn(nro)*sin(2*pi*(wd/nro+we(nro,:)));
    y=rf*rn(nro)*cos(2*pi*(wd/nro+we(nro,:)));
    plhd(nro) = plot(x,y,colvar(nro-2),'LineWidth',4);
  end
  pause(0.005)
end
delete(plhd);
   delete(hdtx);

Diese Filmproduktion benötigt die Funktionen simplinipo und simpbezier.

function [ yipo ] = simplinipo( xarr, yarr, xn )
%function [ yipo ] = simplinipo( xarr, yarr, xn )
% simple linear interpolation
yipo = 0*xn;
for k = 1:length(xn)
  xac = xn(k);
  % always search from below
  if xac < xarr(1)
    yipo(k) = xarr(1);
  else
      for n = 1:length(xarr) 
          if xac < xarr(n)
              fr = (xac-xarr(n-1))/(xarr(n)-xarr(n-1));
              yipo(k) = yarr(n-1)*(1-fr)+ yarr(n)*fr;
              dia = [k,n,fr,yarr(n-1),yarr(n),yipo(k)];
              break
          end
      end
      if xac >= xarr(end)
          yipo(k) = yarr(end);
      end
  end
end

function [ xbez,ybez ] = simpbezier( h1, h2 )
%function [ ybez ] = simpbezier( xpos, h1, h3 )
  t = 0:0.005:1;
  xp1 = 0; xp2 = 0.65; xp3 = 0.7; xp4 = 1;
  yp1 = 1; yp4 = 0; yp2 = h1; yp3 = h2;
  xbez = xp1*(1-t).^3 + 3*xp2*t.*(1-t).^2 ...
        + 3*xp3*t.^2.*(1-t) + xp4*t.^3; 
  ybez = yp1*(1-t).^3 + 3*yp2*t.*(1-t).^2 ...
        + 3*yp3*t.^2.*(1-t) + yp4*t.^3; 
 % plot(xbez,ybez)
end



2018-09-15