IN MATLAB The area S of a triangle ABC can be calculated by

IN MATLAB

The area S of a triangle ABC can be calculated by: S= 1/2 |AB X AC| , where AB is the vector from point A to point B and AC is the vector from point A to point C. Write a user-defined function (in a stand-alone script. Cut & Paste the code of the function at the end of the published document when submitting your work) that determines the area of a triangle given its vertices’ coordinates. For the function name and arguments, use       Area = TriArea(A,B,C). The function should work for a triangle in the x-y plane (each vertex is defined by two coordinates) or for a triangle in 3D Cartesian coordinate system (each vertex is defined by three coordinates). Use this function to determine the areas of triangles with the following vertices:

A = (1,2), B = (10,3), C = (6,11)

A = (-1.5, -4.2, -3), B = (-5.1, 6.3, 2), C = (12.1, 0, -0.5)

Solution

function Area = TriArea(A,B,C)
m = length(A);
AB = zeros(1,3);
AC = zeros(1,3);
% vector AB
for i = 1:m
AB(i) = B(i)-A(i);
end

% vector AC
for j = 1:m
AC(j) = C(j)-A(j);
end

% cross product ABxAC
prod = cross(AB,AC);

Area = 0.5*abs(sum(prod));
end

OUTPUT:

>> TriArea([1,2],[10,3],[6,11])

ans =

38

>> TriArea([-1.5,-4.2,-3],[-5.1,6.3,2],[12.1,0,-0.5])

ans =

37.8350

IN MATLAB The area S of a triangle ABC can be calculated by: S= 1/2 |AB X AC| , where AB is the vector from point A to point B and AC is the vector from point A

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site