Home > bioelectromagnetism > Rotate_demo.m

Rotate_demo

PURPOSE ^

rotate_demo - 3D rotation demo using rx,ry,rz

SYNOPSIS ^

This is a script file.

DESCRIPTION ^

 rotate_demo - 3D rotation demo using rx,ry,rz

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 
0002 % rotate_demo - 3D rotation demo using rx,ry,rz
0003 
0004 clear all; close all
0005 
0006 
0007 % Create base square vertices
0008 cube = [ 0 0 0; 1 0 0; 1 1 0; 0 1 0 ];
0009 % Use this base square to create another at z=1;
0010 cube = [cube; cube + repmat([0 0 1],4,1)];
0011 
0012 % multiply Y by 2
0013 %cube = cube .* repmat([1 2 1],8,1);
0014 % multiply Z by 3
0015 %cube = cube .* repmat([1 1 3],8,1);
0016 
0017 faces = [ 1 2 6 5; 2 3 7 6; 3 4 8 7; 4 1 5 8; 1 2 3 4; 5 6 7 8 ];
0018 
0019 facecol = prism(6);
0020 
0021 
0022 figure('name','Cube Rotations')
0023 subplot(2,2,1);
0024 Hp = patch('vertices',cube,'faces',faces,...
0025            'facevertexcdata',facecol,'facecolor','flat');
0026 set(gca,'Xcolor',[0 0 0],'Ycolor',[1 0 0],'Zcolor',[0 0 1]);
0027 set(gca,'Xlim',[-1.5 1.5],'Ylim',[-1.5 1.5],'Zlim',[-1.5 1.5]);
0028 set(gca,'CameraTarget',[0 0 0]);
0029 set(gca,'CameraPosition',[5 2 2])
0030 set(gca,'CameraViewAngle',[35]);
0031 set(gca,'Projection','perspective')
0032 set(gca,'DataAspectRatio',[1 1 1]);
0033 grid on
0034 
0035 
0036 XYZ = rz(cube',pi/4)';
0037 
0038 subplot(2,2,2);
0039 HpX = patch('vertices',XYZ,'faces',faces,...
0040             'facevertexcdata',facecol,'facecolor','flat');
0041 set(gca,'Xcolor',[0 0 0],'Ycolor',[1 0 0],'Zcolor',[0 0 1]);
0042 set(gca,'Xlim',[-1.5 1.5],'Ylim',[-1.5 1.5],'Zlim',[-1.5 1.5]);
0043 set(gca,'CameraTarget',[0 0 0]);
0044 set(gca,'CameraPosition',[5 2 2])
0045 set(gca,'CameraViewAngle',[35]);
0046 set(gca,'Projection','perspective')
0047 set(gca,'DataAspectRatio',[1 1 1]);
0048 grid on
0049 
0050 rz = rz(eye(3),pi/4);
0051 ry = ry(eye(3),pi/6);
0052 
0053 XYZ = [(ry * rz * cube')]';
0054 
0055 subplot(2,2,3);
0056 HpX = patch('vertices',XYZ,'faces',faces,...
0057             'facevertexcdata',facecol,'facecolor','flat');
0058 set(gca,'Xcolor',[0 0 0],'Ycolor',[1 0 0],'Zcolor',[0 0 1]);
0059 set(gca,'Xlim',[-1.5 1.5],'Ylim',[-1.5 1.5],'Zlim',[-1.5 1.5]);
0060 set(gca,'CameraTarget',[0 0 0]);
0061 set(gca,'CameraPosition',[5 2 2])
0062 set(gca,'CameraViewAngle',[35]);
0063 set(gca,'Projection','perspective')
0064 set(gca,'DataAspectRatio',[1 1 1]);
0065 grid on
0066 
0067 XYZ = [(rz * ry * cube')]';
0068 
0069 subplot(2,2,4);
0070 HpX = patch('vertices',XYZ,'faces',faces,...
0071             'facevertexcdata',facecol,'facecolor','flat');
0072 set(gca,'Xcolor',[0 0 0],'Ycolor',[1 0 0],'Zcolor',[0 0 1]);
0073 set(gca,'Xlim',[-1.5 1.5],'Ylim',[-1.5 1.5],'Zlim',[-1.5 1.5]);
0074 set(gca,'CameraTarget',[0 0 0]);
0075 set(gca,'CameraPosition',[5 2 2])
0076 set(gca,'CameraViewAngle',[35]);
0077 set(gca,'Projection','perspective')
0078 set(gca,'DataAspectRatio',[1 1 1]);
0079 grid on
0080 
0081 return
0082 
0083 
0084 figure
0085 nf = shrinkfaces(faces,cube,.3);
0086 Hp = patch('vertices',nf.vertices,'faces',nf.faces,'facevertexcdata',prism(6),'facecolor','flat')
0087 view(3)
0088 
0089 
0090 
0091 
0092 
0093 return
0094 
0095 
0096 angle = [45 90 180];
0097 for i=1:3,
0098     
0099     XYZ = ry(cube',angle(i),'degrees')';
0100     subplot(2,2,i+1);
0101     HpX = patch('vertices',XYZ,'faces',faces,...
0102                 'facevertexcdata',facecol,'facecolor','flat');
0103     set(gca,'Xcolor',[0 0 0],'Ycolor',[1 0 0],'Zcolor',[0 0 1]);
0104     set(gca,'Xlim',[-1.5 1.5],'Ylim',[-1.5 1.5],'Zlim',[-1.5 1.5]);
0105     set(gca,'CameraTarget',[0 0 0]);
0106     set(gca,'CameraPosition',[10 5 5])
0107     set(gca,'CameraViewAngle',[20]);
0108     set(gca,'Projection','perspective')
0109     set(gca,'DataAspectRatio',[1 1 1]);
0110     grid on
0111 end
0112 
0113 return

Generated on Mon 15-Aug-2005 15:36:19 by m2html © 2003