function [ formations ] = setFormations(scale)
%SETFORMATIONS Creates a list of structs describing the formations
%available to the robot

formations = [];

%% Formation - square
formation.name = 'Square';
formation.robot_pos = [[-1,1,0];[1,1,0];[1,-1,0];[-1,-1,0]];
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
chull = convhull(formation.robot_pos(:,1),formation.robot_pos(:,2));
formation.chull_pos = formation.robot_pos(chull,:) - formation.centroid;
formation.min_distance = sqrt(2);
formation.cost = 1;
formation.robot_pos = formation.robot_pos .* scale;
formation.chull_pos = formation.chull_pos .* scale;
formation.min_distance = Inf;
for i=1:size(formation.robot_pos,1)
    for j=1:size(formation.robot_pos,1)
        if i~=j
            distance = norm(formation.robot_pos(i,:)-formation.robot_pos(j,:),2);
            if distance < formation.min_distance
                formation.min_distance = distance;
            end
        end
    end
end
formations = [formations, formation];

%% Formation - T
formation.name = 'T';
formation.robot_pos = [[0,0,0];[-1,1,0];[0,1,0];[1,1,0]];
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
formation.robot_pos = formation.robot_pos - formation.centroid;
chull = convhull(formation.robot_pos(:,1),formation.robot_pos(:,2));
formation.chull_pos = formation.robot_pos(chull,:);% - formation.centroid;
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
formation.cost = 5;
formation.robot_pos = formation.robot_pos .* scale;
formation.chull_pos = formation.chull_pos .* scale;
formation.min_distance = Inf;
for i=1:size(formation.robot_pos,1)
    for j=1:size(formation.robot_pos,1)
        if i~=j
            distance = norm(formation.robot_pos(i,:)-formation.robot_pos(j,:),2);
            if distance < formation.min_distance
                formation.min_distance = distance;
            end
        end
    end
end
formations = [formations, formation];

%% Formation - diamond
formation.name = 'Diamond';
formation.robot_pos = [[-1,0,0];[0,1,0];[1,0,0];[0,-1,0]];
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
chull = convhull(formation.robot_pos(:,1),formation.robot_pos(:,2));
formation.chull_pos = formation.robot_pos(chull,:) - formation.centroid;
formation.cost = 2;
formation.robot_pos = formation.robot_pos .* scale;
formation.chull_pos = formation.chull_pos .* scale;
formation.min_distance = Inf;
for i=1:size(formation.robot_pos,1)
    for j=1:size(formation.robot_pos,1)
        if i~=j
            distance = norm(formation.robot_pos(i,:)-formation.robot_pos(j,:),2);
            if distance < formation.min_distance
                formation.min_distance = distance;
            end
        end
    end
end
formations = [formations, formation];

%% Formation - line
formation.name = 'Line';
formation.robot_pos = [[0,10^-5,0];[1,0,0];[2,0,0];[3,0,0]];
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
formation.robot_pos = formation.robot_pos - formation.centroid;
chull = convhull(formation.robot_pos(:,1),formation.robot_pos(:,2));
formation.chull_pos = formation.robot_pos(chull,:);% - formation.centroid;
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
formation.cost = 6;
formation.robot_pos = formation.robot_pos .* scale;
formation.chull_pos = formation.chull_pos .* scale;
formation.min_distance = Inf;
for i=1:size(formation.robot_pos,1)
    for j=1:size(formation.robot_pos,1)
        if i~=j
            distance = norm(formation.robot_pos(i,:)-formation.robot_pos(j,:),2);
            if distance < formation.min_distance
                formation.min_distance = distance;
            end
        end
    end
end
formations = [formations, formation];

%% Formation - line
formation.name = 'Vertical Line';
formation.robot_pos = [[0,10^-5,0];[10^-5,0,1];[0,0,-1];[0,0,2]];
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
formation.robot_pos = formation.robot_pos - formation.centroid;
chull = convhull(formation.robot_pos(:,1),formation.robot_pos(:,3));
formation.chull_pos = formation.robot_pos(chull,:);% - formation.centroid;
formation.centroid = sum(formation.robot_pos)/size(formation.robot_pos,1);
formation.cost = 500;
formation.robot_pos = formation.robot_pos .* scale;
formation.chull_pos = formation.chull_pos .* scale;
formation.min_distance = Inf;
for i=1:size(formation.robot_pos,1)
    for j=1:size(formation.robot_pos,1)
        if i~=j
            distance = norm(formation.robot_pos(i,:)-formation.robot_pos(j,:),2);
            if distance < formation.min_distance
                formation.min_distance = distance;
            end
        end
    end
end
formations = [formations, formation];

end

