The distance between any two points (x1,y1) and (x2,y2) is given by:
distance = 
The area of a triangle is:
area = 
where a, b, and c are the lengths of the sides of the triangle, and s is equal to half the sum of the lengths of the three sides of the triangle. Write a script that will prompt the user to enter the coordinates of three points that determine a triangle (e.g. the x and y coordinates of each point). The script will then calculate and print the area of the triangle. It will call one function to calculate the area of the triangle. This function will call a subfunction that calculates the length of the side formed by any two points (the distance between them).
Ch6Ex19.m
% Calculate the area of a triangle given the
% coordinates of the 3 points that determine it
% Prompt the user for the coordinates of the points
x1 = input('Enter the x coordinate of point 1: ');
y1 = input('Enter the y coordinate of point 1: ');
x2 = input('Enter the x coordinate of point 2: ');
y2 = input('Enter the y coordinate of point 2: ');
x3 = input('Enter the x coordinate of point 3: ');
y3 = input('Enter the y coordinate of point 3: ');
% Call a function to calculate the area, then print it
area = triarea(x1,y1,x2,y2,x3,y3);
fprintf('The area of the triangle is %.2f\n', area)
triarea.m
function outarea = triarea(x1,y1,x2,y2,x3,y3)
% Calculates the area of the triangle
% Format of call: triarea(x1,y1,x2,y2,x3,y3)
% Returns the area of the triangle
a = dist(x1,y1,x2,y2);
b = dist(x2,y2,x3,y3);
c = dist(x3,y3,x1,y1);
s = 0.5*(a+b+c);
outarea = sqrt(s*(s-a)*(s-b)*(s-c));
end
function outd = dist(x1,y1,x2,y2)
% Calculates the distance between any two points
% Format of call: dist(x1,y1,x2,y2)
% Returns the distance between the two points
outd = sqrt((x1-x2)^2 + (y1-y2)^2);
end
need an explanation for this answer? contact us directly to get an explanation for this answer