Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MATLAB code:::::: The area S of a triangle ABC can be calculated by: S = 1/2 |AB

ID: 3573811 • Letter: M

Question

MATLAB code::::::

The area S of a triangle ABC can be calculated by: S = 1/2 |AB times 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 = Tri Area (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)

Explanation / Answer

function [ A ] = triarea( p1, p2, p3 ) % [ A ] = triarea( p1, p2, p3 ) % area of triangle defined by 3 points u = p2 - p1; v = p3 - p1; % 3D formula %A = 0.5 * vmag( cross(u,v) ); % n-D formula from [Meyer02] eq 13 A = 0.5 * sqrt( dot(u,u)*dot(v,v) - dot(u,v)^2 ); end