- #1
_N3WTON_
- 351
- 3
Homework Statement
Generate a triangle. For this problem, generate a triangle at a grid of points that are finely spaced in the x dimension. The triangle is defined as follows:
-Side 1: y = 0 for x = 0 to 2
-Side 2: x = 0 for y = 0 to 1
-Hypotenuse: y = 1-0.5x for x = 0 to 2
Alternatively, the triangle can be defined as:
-Side 1: y = 0 for x = 0 to 2
-Side 2: x = 0 for y = 0 to 1
-Hypotenuse: x = 2 - 2y for y = 0 to 1
You will need both definitions to successfully complete this assignment.
3.1
Generate a [itex] 1 \hspace{1 mm} x \hspace{1 mm} n[/itex] array [itex] x [/itex] containing the values of 0 to 2 in steps of 0.1. Then, using (0.1), generate the corresponding array [itex] y [/itex]. This gives you the hypotenuse. Next create a [itex] 2 \hspace{1 mm}x \hspace{1 mm} (n+2) [/itex] array [itex] {Triangle} [/itex] that contains the points necessary to plot the triangle, with the x-coordinates in the first row and the y-coordinates in the second row.
3.2
Plot your triangle to show that you have defined things correctly.
3.3
Compute the centroid in the x-direction
3.4
Generate an array [itex] Y [/itex] containing the values of 0 to 1 in steps of 0.05. Then, using (0.2), generate the corresponding [itex] x [/itex] array. This gives you the hypotenuse. Create a [itex] 1 \hspace{1 mm} x \hspace{1 mm} (n+2) [/itex] array [itex] {Triangle} [/itex] that contains the points necessary to plot the triangle, with the x-coordinates in the first row and the y-coordinates in the second row.
3.5
Plot the triangle to show that you have defined things correctly and show that the triangle overlaps the triangle given in 3.2
3.6
Compute the centroid in the y-direction
3.7
Using the triangle generated in either of the previous sections, rotate the triangle around a full circle. At each step of the rotation, plot the resultant triangle.
3.8
Translate every point in the triangle by the coordinates [itex] (x_{c}, y_{c}) [/itex] prior to rotation. Then rotate the offset triangle in the same manner as in 3.1. Is the rotated triangle the same as or different from the triangle in 3.2. If different, what is the difference?
Homework Equations
Mass and first moment equations from basic calculus .
The Attempt at a Solution
Hello all, currently, I am having some trouble getting my first triangle plot correct, I will post my code. The code is running fine, but it is just generating a line rather than a triangle. I am hoping that once I sort out the first part of the problem and find out what I am doing wrong the rest will come easy (wishful thinking perhaps). I was hoping someone could help me debug my code and let me know what's wrong. Thanks and I will keep working to see if I can solve this problem too. :)
Code:
Code:
clc
clear
line = ['r', 'g', 'k', 'b']; %Line colors
Triangle = [0 0.5 1 1.5 2; %X coordinates
0 0.4 0.6 0.8 1] %Y coordinates
plot(Triangle(1,*:*, Triangle(2,*:*, 'bs-', 'LineWidth',2);
axis([0 2 0 2]);
axis('square');
axis off
title('Basic Triangle');
figure(1)
Edit: for the "plot" command, I have added ** around my semicolon so that it doesn't appear as an emoticon, the * does not appear in my actual code
Last edited: