function [L, R] = makepoints(N, Nbad)
% MAKEPOINTS Make data points for assignment 1
%
% [L, R] = makepoints(N) makes a noisy point set L
% and a corresponding clean point set R by generating N
% evenly spaced points on a circle of radius 10 centered
% on the origin and in the plane z = 0.
% The noise is generated from an isotropic Gaussian
% distribution with noise magnitude 2.5.
%
% [L, R] = makepoints(N, Nbad) causes Nbad of the
% points in L to be generated as outliers. It must be
% the case that N > Nbad

if ~exist('Nbad')
  Nbad = 0;
end

if Nbad >= N
  error('Too many outliers!');
end

% make the clean points
theta = linspace(0, 360, N + 1);
theta(end) = [];
R = 50 * [cosd(theta);
          sind(theta);
          zeros(1, N)];

% make the noisy points
L = R;
if Nbad > 0
  % make the outliers before adding the noise
  I = randperm(N);
  I((Nbad + 1):end) = [];
  L(:, I) = 70 * [cosd(theta(I));
                  sind(theta(I));
                  randn(1, Nbad)/5];
end
Sigma = (2.5 * 2.5) / 3 * eye(3);
mu = [0 0 0];
noise = mvnrnd(mu, Sigma, N);
L = L + noise.';

