% TriCentroid

close all
figure
set(gcf,'Position',[100 100 700 700])
axis([0 1 0 1])
hold on
% We will house the xy data for t he three points in these vectors..
x = zeros(1,3);
y = zeros(1,3);
% This loops asks fopr the vertices and saves the results..
for k=1:3
   title(sprintf('Click in vertex %1d',k),'Fontsize',18)
   [xk,yk] = ginput(1);
   % Save and display the coordinates...
    x(k) = xk; 
    y(k) = yk;
    plot(x(k),y(k),'.k','MarkerSize',20)
end
title('A Triangle and Its Centroid','FontSize',18)
% Display the triangle
fill(x,y,'y')

% Highlight the centroid...
xc = (x(1)+x(2)+x(3))/3;
yc = (y(1)+y(2)+y(3))/3;
plot( xc,yc,'*k','MarkerSize',20)
plot(xc,yc,'or','MarkerSize',20)

% Add in the linesegments..
lwVal = 2;
plot([xc x(1)],[yc y(1)],'linewidth',lwVal)
plot([xc x(2)],[yc y(2)],'linewidth',lwVal)
plot([xc x(3)],[yc y(3)],'linewidth',lwVal)

% Turn off the hold toggle and bring the current figure to the front
hold off
shg
