Question
Problem 1 (Matlab) %%%%%%% This is the function file that you must have in order to proceed. function DrawHouse( m ) %Define points and draw
Problem 1 (Matlab)
%%%%%%%
This is the function file that you must have in order to proceed.
function DrawHouse( m )
%Define points and draw the house
house = [ -0.5 0.5 0.5 0.0 -0.5 -0.5; -0.5 -0.5 0.5 0.75 0.5 -0.5];
window = [ 0.1 0.3 0.3 0.1 0.1; -0.1 -0.1 0.3 0.3 -0.1 ];
door = [ -0.2 -0.2 -0.4 -0.4 ; -0.5 -0.2 -0.2 -0.5 ];
house(3,:) = ones(1, size(house, 2));
window(3,:) = ones(1, size(window, 2));
door(3,:) = ones(1, size(door, 2));
house = m * house;
window = m * window;
door = m * door;
plot(house(1,:), house(2,:), '-b' )
hold on;
plot(window(1,:), window(2,:), '-r' )
plot(door(1,:), door(2,:), '-k' )
end
Use a matrix to move a house around. Translate by (5, 1.5) and rotate by 25 degrees then try both combinations of rotating then translating
Deliverables:
Script to make the four plots
Make a translation matrix and check that it correctly translates
Make a rotation matrix and check that it correctly rotates
Also verify that it is orthogonal
Plot with 4 versions of the house: Translated, rotated, translated then rotated, rotated then translated
You must use your matrices to do this
Step by Step Instructions:
First make four plots and plot the house at the origin in each of them
Call DrawHouse with the identity matrix
Use axis equal to make it the right aspect ratio (not squished)
Put a title on the subplot but you can skip labels
Make a translation matrix
Use eye to make an identity matrix mTrans. Must be a 3x3 matrix
Set dx to be 5, dy to be 1.5
The upper right two elements of mTrans
(refer to lecture notes)
To check that you have the correct matrix, try
mTrans * [0;0;1]
You should get the column vector 5, 1.5, 1
See self check below
Use DrawHouse with mTrans to make the first picture
Make a rotation matrix
Use eye (again) to make an identity matrix mRot. Must also be a 3x3 matrix
Declare a variable for theta
Fill in the matrix; refer to lecture notes.
cos, sin
-sin, cos
Check that you have the correct matrixdot( mRot(1,:), mRot(2,:) ) is zero
as is every other dot product if the rows are different
dot( mRot(1,:), mRot(1,:)) is one
as is every other dot product if the rows are the same
mRot * mRot is the identity matrix (or close enough)
Math fact: This is the matrix multiplied by its transpose. One property of rotation matrices is that their transpose is their inverse i.e., rotating in the opposite direction. Youll notice that mRot is the same as mRot, except the minus sign on the sin is swapped
Note: you only need to check the conditions above for this labs hand-in, but in general, if youre making a rotation matrix you should ALWAYS check all of these.
Use DrawHouse with mRot to make the second picture
Now make the 3rd and 4th picturesNote: The matrix that is on the right is the one that happens first. So
mTrans * mRot
rotates then translates (yes, that seems backwards for those of us who read left to right)
Math fact II: This is a visual demonstration of the fact that matrix multiplication is not communitive A * B is not the same as B * A.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started