Solved

Compound matrix transformation [code attached]

Posted on 2008-10-09
3
681 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_
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
countX 22 132
wordmultiple challenge 12 141
Interview question Javascript, database 12 82
Calculating bins of different widths using a summery plot in a Nspire CX Cas 2 25
We are taking giant steps in technological advances in the field of wireless telephony. At just 10 years since the advent of smartphones, it is crucial to examine the benefits and disadvantages that have been report to us.
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This video teaches viewers about errors in exception handling.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

809 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