Solved

Compound matrix transformation [code attached]

Posted on 2008-10-09
3
683 Views
Last Modified: 2013-11-25
Hello Experts,

I have the following code which shows the rotation of a 2D polygon and what i want is to modify it using a compound matrix transformation so that the square rotates about an arbitrary point.

Can anyone help me how can i do such a thing ??

Thanks in advance
close all;
clear all;
 
 
% a 2D pologyon 
p=[-1 1 1 -1 -1 ; -1 -1 1 1 -1];
 
% points p = in homogeneous coord
p(3,:)=1;
 
% axes for plotting the animation
figure; 
hold on;
axis([-6 6 -6 6]);
axis equal;
 
for theta=0:0.005:2*pi
 
    R=[cos(theta) -sin(theta) 0 ; sin(theta) cos(theta) 0 ; 0 0 1];
    
    pdash=R*p; 
    
    pdash(1,:)=pdash(1,:)./pdash(3,:);
    pdash(2,:)=pdash(2,:)./pdash(3,:);
    
    cla;
    plot(pdash(1,:),pdash(2,:),'b');   
    drawnow;
    
end

Open in new window

0
Comment
Question by:perdoname_
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 84

Expert Comment

by:ozo
ID: 22694376
0
 
LVL 4

Accepted Solution

by:
SyfAldeen earned 500 total points
ID: 22895982
perdoname_,
Here you are the modified code:
You can learn more here:
Transforming Objects - MATLAB

function rotsquare
close all;
clear all;
 
% a 2D pologyon
p=[-1 1 1 -1 -1 ; -1 -1 1 1 -1];
 
% points p in XY plane
p(3,:)=0;
 
% points p = in homogeneous coord
p(4,:)=1;
 
% axes for plotting the animation
figure;
hold on;
axis([-6 6 -6 6]);
axis equal;
 
%Rotate about the upper right corner (1,1)
Tx1 = makehgtform('translate',[-1 -1 0]);
Tx2 = makehgtform('translate',[ 1  1 0]);
 
for theta=0:0.005:2*pi
    R=makehgtform('zrotate',theta);
    pdash=Tx2*R*Tx1*p;
    cla;
    plot(pdash(1,:),pdash(2,:),'b');
    drawnow;
end

Open in new window

0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Dual bridge protection 18 149
hardness of water, iron in it, and effect on humans.. 6 87
Re-position the objects 7 125
Capture logon name 13 104
This article will show, step by step, how to integrate R code into a R Sweave document
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question