function [x] = f(pts, domain)

%%%%%
% Helper function f to generate
% DE parameters from the actual points
%
% x : initial points
% domain : 1 for square, 2 for disk, 3 for interval
%
%%%%%


    switch domain

	case 1
    x = [acos(pts(:,1)); acos(pts(:,2))];

	case 2
	[rho,theta] = to_polar(pts(:,1),pts(:,2));
	polar_pts = [rho theta];
	x = [acos(polar_pts(:,1)); polar_pts(:,2)];
	
	case 3
	x = [acos(pts)];

	otherwise
	x = pts;

	end
end

function [r,theta] = to_polar(x,y)

if nargin < 2
	return
end

if length(x) != length(y)
	return
end

for i=1:length(x)
	r(i,1) = sqrt(x(i)^2+y(i)^2);
	if x(i) > 0
		theta(i,1) = atan(y(i)/x(i));
	end
	if x(i) < 0
	    if y(i) >= 0
		    theta(i,1) = atan(y(i)/x(i)) + pi;
	    end
	    if y(i) < 0
		    theta(i,1) = atan(y(i)/x(i)) - pi;
		end
	end
	if x(i) == 0
		if y(i) > 0
			theta(i,1) = pi/2;
		end
	    if y(i) < 0
			theta(i,1) = -pi/2;
	    end
        if y(i) == 0
			theta(i,1) = 0;
		end
	end
end
end
