% usage: triangle
% query the user for 3 coordinate pairs to find area of triangle and plot
% the triangle
%
% call 2 functions triangleDist.m and triangleArea.m

clear all
close all
clc

% collect coordinates from user
x1 = input('x1: ');
y1 = input('y1: ');
x2 = input('x2: ');
y2 = input('y2: ');
x3 = input('x3: ');
y3 = input('y3: ');

% get lengths of triangle sides
a = triangleDist(x1,y1,x2,y2);
b = triangleDist(x1,y1,x3,y3);
c = triangleDist(x2,y2,x3,y3);

% gets area of triangle
area = triangleArea(a,b,c);

% display area to user
fprintf('The area of your triangle is %.2f square units.\n',area);

% format colmn vectors for patch plot
X = [x1;x2;x3];
Y = [y1;y2;y3];

% draw triangle
figure
patch(X,Y,'red')
title(['Area = ' num2str(area) ' square units']);