Info
This question is locked. 请重新打开它进行编辑或回答。
Confusion with triangles, area , perimeter
16 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
回答(1 个)
BhaTTa
2024-10-26,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);
fprintf('The area of the triangle is: %.2f square feet\n', Area);
2 个评论
Walter Roberson
2024-10-26,19:06
We do not recommend posting complete code to answer homework questions.
John D'Errico
2024-10-27,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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!