alternating rotating and scaling of 6x6 'chessboard effect' of polygons

2 views (last 30 days)
hi.does anybody know how to alternate the rotation and scaling of 36 polygons so that as one polygon rotates clockwise while getting larger the others surrounding it are doing the opposite. i have done most of the work, i.e. creating the shape, the 6x6 of shapes,the rotation,scaling i just need help on alternating. it would be so much help!!!! thanks
  2 Comments
Geoff Hayes
Geoff Hayes on 27 Nov 2015
lym9419 - it may be easier to post a sample of what you have written so that we can best advise on how you may go about doing the rotation and resizing. Are you using a timer to update the graphic every half-second or so?
Walter Roberson
Walter Roberson on 27 Nov 2015
I would appreciate a diagram of what a partly rotated intermediate step should look like.

Sign in to comment.

Answers (1)

Geoff Hayes
Geoff Hayes on 6 Dec 2015
If you know the four vertices of the square (since using a chessboard) that you wish to draw, then you can use the MATLAB fill function to create it
hSquare = fill(X,Y,'k');
where X and Y are the x and y coordinates of the vertices, and hSquare is the handle to the square (polygon) that you have drawn.
Suppose you now want to rotate the square by one degree in a counter-clockwise direction. The rotation matrix is the usual
thetad = 1;
R = [cosd(thetad) -sind(thetad); sind(thetad) cosd(thetad)];
We can get the vertices from the drawn square since we have its handle
V = get(hSquare,'Vertices');
We could multiply V by R to get the rotated set of vertices, but this would only be valid if the centre of the square is (0,0). As that will not be the case, then you will need to translate the square from its current coordinate system to one centred at (0,0). We can do this and the rotation as follows
V = R*(V - C) + C;
where C is an appropriately sized matrix with the centre of the square (use repmat to create this C given the (x,y) coordinates for the centre). So we translate to the coordinate system centred at (0,0) (the subtraction), rotate (the multiplication), and then translate back to the original coordinate system whose origin is the centre of the square (the addition). We can then update the square with the new vertices as
set(hSquare,'Vertices',V);
and the rotation by one degree is complete. To scale (expand or shrink) the square, apply the appropriate factor to R.
Now imagine there is one handle per each square that you have drawn, so you can iterate over each one and apply the above rotation and scaling. Presumably it is known which one should rotate clockwise and expand, so R would be slightly different for this square.

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!