In C Moler experiments
chap5 there is a basic example how to animate objects depicted like the box you mention
function wiggler(X)
clf
shg
thetamax = uicontrol('style','slider','max',1.0, ...
'units','normalized','position',[.25 .01 .25 .04]);
delta = uicontrol('style','slider','max',.05, ...
'units','normalized','position',[.60 .01 .25 .04]);
t = 0;
stop = uicontrol('string','stop','style','toggle');
while ~get(stop,'value')
theta = (4*abs(t-round(t))-1) * get(thetamax,'value');
G = [cos(theta) sin(theta); -sin(theta) cos(theta)];
dot_to_dot(G*X);
drawnow
t = t + get(delta,'value');
end
set(stop,'string','close','value',0,'callback','close(gcf)')
the update you did not mention is the command drawnow
the shape
X = [0;1;1;0;0];
Y = [0;0;1;1;0];
Z = [0;0;0;0;0];
the input to a 3D wiggler would be
to run this 2D wiggler
The 3D version of the G matrix in this 2D wiggler is rotation matrix
product of Yaw Pitch and Roll
Rotation
ax = axes('XLim',[-1.5 1.5],'YLim',[-1.5 1.5], 'ZLim',[-1.5 1.5])
view(3); grid on;
axis manual;
[x y z] = cylinder([.3 0])
h(1) = surface(x,y,z,'FaceColor','red')
h(2) = surface(x,y,-z,'FaceColor','green')
h(3) = surface(z,x,y,'FaceColor','blue')
h(4) = surface(-z,x,y,'FaceColor','cyan')
h(5) = surface(y,z,x,'FaceColor','magenta')
h(6) = surface(y,-z,x,'FaceColor','yellow')
t = hgtransform('Parent',ax)
set(h,'Parent',t)
set(gcf,'Renderer','opengl')
drawnow
Rz=eye(4);
Sxy=Rz;
for r = 1:.1:2*pi
Rz = makehgtform('zrotate',r)
Sxy = makehgtform('scale',r)
set(t,'Matrix',Rz)
drawnow
end
Translation, this example does not keep the axis steady, but it's a translation
ax = axes('XLim',[-2 1],'YLim',[-2 1],'ZLim',[-1 1])
view(3); grid on; axis equal
[x y z] = cylinder([.3 0]);
h(1) = surface(x,y,z,'FaceColor','red');
h(2) = surface(x,y,-z,'FaceColor','green');
h(3) = surface(z,x,y,'FaceColor','blue');
h(4) = surface(-z,x,y,'FaceColor','cyan');
h(5) = surface(y,z,x,'FaceColor','magenta');
h(6) = surface(y,-z,x,'FaceColor','yellow');
t1 = hgtransform('Parent',ax);
t2 = hgtransform('Parent',ax);
set(gcf,'Renderer','opengl')
Scaling
ax = axes('XLim',[-1.5 1.5],'YLim',[-1.5 1.5], 'ZLim',[-1.5 1.5])
view(3); grid on; axis equal
[x y z] = cylinder([.3 0])
h(1) = surface(x,y,z,'FaceColor','red')
h(2) = surface(x,y,-z,'FaceColor','green')
h(3) = surface(z,x,y,'FaceColor','blue')
h(4) = surface(-z,x,y,'FaceColor','cyan')
h(5) = surface(y,z,x,'FaceColor','magenta')
h(6) = surface(y,-z,x,'FaceColor','yellow')
t = hgtransform('Parent',ax)
set(h,'Parent',t)
set(gcf,'Renderer','opengl')
drawnow
Sxy=eye(4);
for r = 1:.1:6
Sxy = makehgtform('scale',r/4)
set(t,'Matrix',Sxy)
drawnow
end
pause(1)
for r = 6:-.1:1
Sxy = makehgtform('scale',r/4)
set(t,'Matrix',Sxy)
drawnow
end
set(t,'Matrix',eye(4))
set(h,'Parent',t1);h2=copyobj(h,t2)
Txy=makehgtform('translate',[-1.5 -1.5 0])
set(t2,'Matrix',Txy)
pause(2)
delete(t1)
drawnow
If you find this answer of any help solving your question, please click on the thumbs-up vote link,
thanks in advance
John