function [triangles] = generate_env(k)
%GENERATE_ENV Generate an environment comprised of k triangles
% It will look approximately like the example in Derenick Spletzer's paper
% Starting at top left and going to bottom right, with some randomness
% triangles = k*6 matrix of triangle points, each row holds (x1 y1 x2 y2 x3 y3)

triangles = zeros(k, 6);

% Manually specify first triangle
triangles(1,:) = [0 0, -15 0, -5 -12];
flip = 1;
for i = 2:size(triangles)
    % Choose either side to extend, with some randomness
    if flip == 1
        p1 = triangles(i-1,1:2);
        p2 = triangles(i-1,5:6);
        p_away = triangles(i-1,3:4);
        flip = 2;
    else
        p1 = triangles(i-1,3:4);
        p2 = triangles(i-1,5:6);
        p_away = triangles(i-1,1:2);
        flip = randi(2);
    end
   % Extend by placing third point perpendicularly away, with noise
   midpoint = (p1 + p2)/2;
   dir = midpoint - p_away + 2*(rand(1) - [0.5 0.5]);
   dir = dir / norm(dir);
   distance = 7 + 5*rand(1);
   p3 = midpoint + distance * dir;
   triangles(i, :) = [p1 p2 p3];
end

