function geom_finite_disp_2d (wait) % ------------------------------------------------------ % Matlab control program to apply matrix transformation % operators (in homogeneous coordinates) to an arbitrary % 2_d shape & plot it in true shape. % The shape is defined by triangles (in tri_2d.dat) that % are connected to points (in xy.dat). Extra points allowed. % ------------------------------------------------------ % % finite = finite motion transformation matrix, 4 x 4 % Upper left 3 x 3 gives, rotation, scale, reflection, etc. % Upper right 3 x 1 gives translation, if any % Lower left 1 x 3 is zero usually (except for perspective) % finite(4,4) = 1. % hc = homogeneous coordinates of points, 4 x np % = x, y, z, 1 at all points. z = 0 here. % np = Number of Points % nt = Number of triangles % tri_2d = connectivity list for triangles, nt x 3 % wait = seconds of pause time between plots % xy = Coordinates of points, np x 2 % %c denotes future work or debugging aids % fprintf ('\n Begin Finite Displacement Matrix Operations \n') if ( nargin == 0 ) wait = 5; % time in seconds fprintf ('\n Default pause between plots is %g seconds\n', wait) end % if no arguments % % Read coordinate file and connectivity file load xy.dat ; % xy pairs for np points % Set control data: number of points np = size(xy,1) ; % number of rows in xy fprintf ('\n Read %g coordinate pairs \n', np) fprintf (' x y \n') disp ( xy ) % % Set control data: number triangles load tri_2d.dat ; % 3 corners per triangle nt = size(tri_2d,1) ; % number of rows in nodes fprintf ('\n Read %g corner connections \n', nt) fprintf ('Point1 Point2 Point3 \n') disp (tri_2d) % % Establish max array sizes hc(4,np) = 0. ; % pre-allocate array hc %c Check that connectivity data are in range 1 <= k <= np %c check_limits (np, nt, tri_2d) % % Initialize plots points_plot (xy(1:np, 1), xy(1:np, 2), np) triangles_plot (xy(1:np, 1), xy(1:np, 2), tri_2d, nt) title ('Original') pause (wait) % pause between plots % make hardcopy print -dpsc shape_orig % % Initialize homogeneous coordinates hc(1,1:np) = xy(1:np, 1)' ; hc(2,1:np) = xy(1:np, 2)' ; hc(3,1:np) = zeros(1,np) ; hc(4,1:np) = ones(1,np) ; % % Initalize transformation finite = eye(4) ; % default for no change % % Begin transformations % (remember to break following into modules or % a case switch code ) % % 30 degree rotation about z-axis finite = eye(4) ; ang = 30./57.3 ; % degree to radians [rotate] = rot_z (ang) ; finite(1:3, 1:3) = rotate ; hc = finite*hc ; clf % clear graphics frame points_plot (hc(1,:), hc(2,:), np) triangles_plot (hc(1,:), hc(2,:), tri_2d, nt) title ('Rotated about z') pause (wait) % pause between plots print -dpsc shape_rotz % % now translate by vector [ 2., 1., 0. ] finite = eye(4) ; finite(1:3, 4) = [ 2., 1., 0. ]' ; % transposed hc = finite*hc ; clf % clear graphics frame points_plot (hc(1,:), hc(2,:), np) triangles_plot (hc(1,:), hc(2,:), tri_2d, nt) title ('Translated 2 1 0') pause (wait) % pause between plots print -dpsc shape_shift % % zoom to 50% image finite = eye(4) ; ratio = 0.5 ; [zoom] = scale (ratio, ratio, 1.0) ; finite(1:3, 1:3) = zoom ; hc = finite*hc ; clf % clear graphics frame points_plot (hc(1,:), hc(2,:), np) triangles_plot (hc(1,:), hc(2,:), tri_2d, nt) title ('Zoomed to 50%') pause (wait) % pause between plots print -dpsc shape_zoom % % reflect about xz-plane (here x-axis) finite = eye(4) ; [reflect] = refl_xz ; finite(1:3, 1:3) = reflect ; hc = finite*hc ; clf % clear graphics frame points_plot (hc(1,:), hc(2,:), np) triangles_plot (hc(1,:), hc(2,:), tri_2d, nt) title ('Reflected wrt xz-plane') pause (wait) % pause between plots print -dpsc shape_refl % end of geom_finite_disp_2d