Solved

Compound matrix transformation [code attached]

Posted on 2008-10-09
3
677 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
Comment Utility
0
 
LVL 4

Accepted Solution

by:
SyfAldeen earned 500 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now