Info

This question is locked. Reopen it to edit or answer.

Confusion with triangles, area , perimeter

16 views (last 30 days)
Dylan
Dylan on 17 Feb 2014
Locked: John D'Errico on 27 Oct 2024 at 1:13
This is the problem I have. I have absolutely no idea where to start.
1. Write a MATLAB script called Triangle to calculate the perimeter P of the triangle A-B-C defined by the x and y coordinates of points A, B, and C as listed below.
The length of triangle side a = sqrt( (Bx – Cx)2 + ( By– Cy)2 ),
Where Bx and Cx are the x-coordinates of points B and C, and By and Cy are the y-coordinates of points B and C.
Therefore for the points shown below, length of side a = sqrt( (220 – 480)2 + ( 320 – 230)2 )
x y Point coordinates in feet: A ( 90 , 130 ) B ( 220 , 320 ) C ( 480 , 230 )
2. Add to the script a formula for calculating the area of the triangle

Answers (1)

BhaTTa
BhaTTa on 26 Oct 2024 at 18:12
Hey @Dylan, I assume that you require a MATLAB script that calculates both the perimeter and the area of a triangle given the coordinates of its vertices, please refer to the code below:
% Define the coordinates of the points
Ax = 90; Ay = 130;
Bx = 220; By = 320;
Cx = 480; Cy = 230;
% Calculate the lengths of the sides using the distance formula
a = sqrt((Bx - Cx)^2 + (By - Cy)^2);
b = sqrt((Ax - Cx)^2 + (Ay - Cy)^2);
c = sqrt((Ax - Bx)^2 + (Ay - By)^2);
% Calculate the perimeter of the triangle
P = a + b + c;
% Calculate the semi-perimeter for Heron's formula
s = P / 2;
% Calculate the area using Heron's formula
Area = sqrt(s * (s - a) * (s - b) * (s - c));
% Display the results
fprintf('The perimeter of the triangle is: %.2f feet\n', P);
The perimeter of the triangle is: 907.97 feet
fprintf('The area of the triangle is: %.2f square feet\n', Area);
The area of the triangle is: 30550.00 square feet
  2 Comments
Walter Roberson
Walter Roberson on 26 Oct 2024 at 19:06
We do not recommend posting complete code to answer homework questions.
John D'Errico
John D'Errico on 27 Oct 2024 at 1:13
You answered a homework question that is now 10 years old. Odds are the person posting the question does not have the least interest in what you did, as their homework assignment is now 10 years overdue.
regardless, please don't do homework questions with no effort made. It does not help the student, beyond teaching them to keep on posting homework questions with no effort made. It does not help the forum, as it convinces other students to also post their homework with no effort made.

This question is locked.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!