Rotation of a set of points

3 次查看(过去 30 天)
I am given 4 points, each is a corner of a plane to a box.
p1=[0;0] p2=[sqrt(3/4);-1/2] p3=[sqrt(3/4);1/2] p4=[0;1]
I want to rotate the plane counterclockwise with 120- and240 degree. so that i get a box of some sort.
-------
what i try to do is to make a matrix of the first plane, give the rows x and y varribles and plot them in.
>> fill(x1,y1,'r')
which works fine.
now i want to rotate it with 120 degree. so i make a rotation matrix
theta= 120
R=[cos(theta) -sin(theta); sin(theta) cos(theta)]
I multiply it with the previously matrix, and put new varriables on the new matrix, like x2 and y2
fill(x1,y1,'r',x2,y2,'g')
for some reason it does not obbey my command :S
any tips and trick?

采纳的回答

Mischa Kim
Mischa Kim 2014-2-25
Rasmus, this should work:
X = [p1 p2 p3 p4];
theta = 120*(pi/180);
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
Xr1 = R*X;
theta = 240*(pi/180);
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
Xr2 = R*X;
hold on
fill(X(1,:),X(2,:),'r')
fill(Xr1(1,:),Xr1(2,:),'b')
fill(Xr2(1,:),Xr2(2,:),'k')
grid; box;
axis square

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Assembly 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by