- translate your rotation point to the origin
- perform rotation
- reverse translate to original coordinates
Rotating a rectangle about a point other than the origin
5 views (last 30 days)
Show older comments
This is a homework assignment that ive been working on in matlab for a few days but and ive done everything ive needed to do accept that the second rectangle needs to be rotated about an end point on the end of the first rectangle. my professor for this class doesnt care how we do this just as long as we get the right result and since i know literally nothing about matlab and linear algebra ive managed to find some stuff on here that lets me get the job done but i havent found out how to rotate about a point other than the origin. so please keep in mind i have zero matlab experience.
thanks
axis([-1 10 -5 4]);
%first rectangle along x axis
rect.Vertices=[0 0;4 0;4 .5;0 .5];
rect.faces=[1 2 3 4];
theta = pi/9;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices,'FaceColor',[0 .5 0]);
%second rectangle along x axis
rect.Vertices=[4 0;8 0;8 .5;4 .5];
rect.faces=[1 2 3 4];
theta = pi/9;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices,'FaceColor',[0 .5 .5]);
%rotates second rectangle
rect.Vertices=[4 0;8 0;8 .5;4 .5];
rect.faces=[1 2 3 4];
theta = pi/9;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 .5 .5]);
%rotates first rectangle
rect.Vertices=[0 0;4 0;4 .5;0 .5];
rect.faces=[1 2 3 4];
theta = pi/9;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 0 .5]);
%rotates second rectangle -30 degrees
rect.Vertices=[4 0;8 0;8 .5;4 .5];
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 .5 .5]);
%rotates object 10 degrees
rect.Vertices=[4 0;8 0;8 .5;4 .5];
rect.faces=[1 2 3 4];
theta = -pi/18;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 .5 .5]);
rect.Vertices=[0 0;4 0;4 .5;0 .5];
rect.faces=[1 2 3 4];
theta = -pi/18;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 0 .5]);
%rotates second rectangle -30 degrees
rect.Vertices=[4 0;8 0;8 .5;4 .5];
rect.faces=[1 2 3 4];
theta = -2*pi/9;
R=[cos(theta) sin(theta);-sin(theta) cos(theta)];
patch(rect,'Vertices',rect.Vertices*R,'FaceColor',[0 .5 .5]);
0 Comments
Answers (1)
bym
on 7 Dec 2011
you have to do a composite rotation, consisting of:
I will try to dig up something in my old files, but in the mean time you might want to do some research on homogeneous coordinates
0 Comments
See Also
Categories
Find more on Computational Geometry 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!