Hi Toluwalope Akindokun,
I understand that you want to create square patches along an axis, apply transformations, and display them using a for loop.Below is a revised version of your code. This script sets up the environment, iterates over grid points to create square patches, and applies rotation and translation transformations. It also includes an animation effect to visualize the transformations:
whitebg('g')
axis on
axis([0 30 0 30])
shg
% Define the square patch points relative to an origin
square_size = 1;
square_pts = [0 0 square_size square_size 0; 0 square_size square_size 0 0];
% Transformation parameters
theta = 0;
dx = 0.5;
dy = 0.5;
% Loop over grid points on the axis
for x = 0:5:25
for y = 0:5:25
translated_pts = square_pts + [x; y];
patch_handle = patch(translated_pts(1, :), translated_pts(2, :), 'b*-');
for step = 1:20
rot = [cosd(theta) sind(theta); -sind(theta) cosd(theta)];
trans = [1 0 dx; 0 1 dy; 0 0 1];
homogeneous_pts = [translated_pts; ones(1, size(translated_pts, 2))];
homogeneous_rot = eye(3);
homogeneous_rot(1:2, 1:2) = rot;
trans_pts = trans * homogeneous_rot * homogeneous_pts;
set(patch_handle, 'XData', trans_pts(1, :), 'YData', trans_pts(2, :));
% Update transformation parameters
theta = theta + 5;
dx = dx + 0.1;
dy = dy + 0.1;
% Pause to create animation effect
pause(0.1);
end
end
end
Here’s a link to the related documentation:
Hope this helps!