How to translate 2d rectangles and rotate them. (new to matlab)

I have a project that requires me to:
1) Draw two rectangles about 3 units wide and .4 units tall. The axis points of the bottom left corner of the first rectangle is (2,3) and (5,3) for the second.
2)Rotate the right axis of both rectangles 30 degrees about the left axes of the left rectangle.
3) Then rotate only the right rectangle about its axis -60 degrees.
Any help would be greatly appreciated, and keep in mind that I have zero Matlab experience prior to this. From my own research and experimentation this is what I have come up with so far but I am still unsure if I am doing it correctly.
axis([0 10 0 10]);
%first rectangle along x axis
rect.Vertices=[2 3;5 03;5 3.4;2 3.4];
rect.faces=[1 2 3 4];
theta = pi/6;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices,'FaceColor',[0 .4 0]);
%second rectangle along x axis
rect.Vertices=[5 3;8 3;8 3.4;5 3.4];
rect.faces=[1 2 3 4];
theta = pi/6;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices,'FaceColor',[0 .4 .4]);
%rotates second rectangle
rect.Vertices=[5 3;8 3;8 3.4;45 3.4];
rect.faces=[1 2 3 4];
theta = pi/6;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 .4 .4]);
%rotates first rectangle
rect.Vertices=[2 3;5 3;5 3.4;2 3.4];
rect.faces=[1 2 3 4];
theta = pi/6;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 0 .4]);
%rotates second rectangle -60 degrees
rect.Vertices=[5 3;8 3;8 3.4;6 3.4];
rect.faces=[1 2 3 4];
theta = -pi/3;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 .4 .4]);

1 Comment

Excuse me, can you rotate it? If you can do it, please explain to me.

Sign in to comment.

Answers (0)

Asked:

on 8 Apr 2012

Commented:

SP
on 13 May 2021

Community Treasure Hunt

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

Start Hunting!