- #1
Mutaja
- 239
- 0
Hi.
I've been given an assignment, a starters assignment I should say, for Matlab. This is mostly about learning the basic functions of the program and it's my first ever experience with it.
I hope I'm posting in the correct sub-forum.
We're given a triangle ABC, where A(1,3), B(2,0) and C(2,4). The triangle can be drawn with the following code:
a)
rotate the triangle 30 degrees in negative direction around origo (does this even make sense? Trying to translate it as best as I can). Draw the new triangle in the same coordinate system (as the original triangle I assume) - with another color.
b)
Mirror the rotated triangle around the x-axis. Draw the new triangle in the same coordinate system with a 3rd color.
c)
Scale the rotated triangle to double size. Draw the new triangle in the same coordinate system with a 4th color.
d)
Study how many different triangles you can end up with by changing the order of the three transformations.
Matrices. Rotation, scaling and mirror matrices.
Alright, first things first. I think it's best to start with exercise a, and then move on from there - I might be able to finish them myself when I've learned how to do the first one.
So, for the rotating part.
I will need a matrix to rotate the triangle:
Then I get these values:
Mrot =
0.8660 -0.5000
0.5000 0.8660
This is where I'm stuck. To get my new coordinates, do I multiply my coordinates with this matrix? If this is the answer, how do I do this in matlab?
Any type of input here will be greatly appreciated.
Thanks in advance.
I've been given an assignment, a starters assignment I should say, for Matlab. This is mostly about learning the basic functions of the program and it's my first ever experience with it.
I hope I'm posting in the correct sub-forum.
Homework Statement
We're given a triangle ABC, where A(1,3), B(2,0) and C(2,4). The triangle can be drawn with the following code:
Code:
% triangle_ABC.m
clear all
P = [ 1 -2 2 1
3 0 -4 3 ];
plot(P(1,:),P(2,:),'-b'), axis equal
a)
rotate the triangle 30 degrees in negative direction around origo (does this even make sense? Trying to translate it as best as I can). Draw the new triangle in the same coordinate system (as the original triangle I assume) - with another color.
b)
Mirror the rotated triangle around the x-axis. Draw the new triangle in the same coordinate system with a 3rd color.
c)
Scale the rotated triangle to double size. Draw the new triangle in the same coordinate system with a 4th color.
d)
Study how many different triangles you can end up with by changing the order of the three transformations.
Homework Equations
Matrices. Rotation, scaling and mirror matrices.
The Attempt at a Solution
Alright, first things first. I think it's best to start with exercise a, and then move on from there - I might be able to finish them myself when I've learned how to do the first one.
So, for the rotating part.
I will need a matrix to rotate the triangle:
Code:
theta =30;% degree of rotation counterclockwise
Mrot = [ cosd(theta) -sind(theta)
sind(theta) cosd(theta) ]
Then I get these values:
Mrot =
0.8660 -0.5000
0.5000 0.8660
This is where I'm stuck. To get my new coordinates, do I multiply my coordinates with this matrix? If this is the answer, how do I do this in matlab?
Any type of input here will be greatly appreciated.
Thanks in advance.