close all;clearvars;clc;
wn = [1 , 1/2 , 1/4 , 1/8 , 1/16 , 1/32 , 1 / 64 , 1/128 , 1/256];
wn_angle = atan(wn);
datax = 3535;
datay = 1965;
datax1 = datax;
datay1 = datay;
if(datax < 0)
datax1 = -datax;
end
if(datay < 0)
datay1 = -datay;
end
anglereal = angle(datax + 1i*datay);
sumangle = 0;
sign = 1;
allsing = 0;
for i = 1 : length(wn)
x2 = datax1 + datay1 * sign * wn(i);
y2 = datay1 - datax1 * sign * wn(i);
datax1 = x2;
datay1 = y2;
sumangle = sumangle + sign * wn_angle(i);
if(datay1 > 0)
sign = 1;
end
if(datay1 < 0)
sign = -1;
end
end
if(datax > 0 && datay > 0)
sumangle = sumangle;
elseif(datax > 0 && datay < 0)
sumangle = -sumangle;
elseif(datax < 0 && datay > 0)
sumangle = pi - sumangle;
elseif(datax < 0 && datay < 0)
sumangle = sumangle - pi;
end
wn = [1 , 1/2 , 1/4 , 1/8 , 1/16 , 1/32 , 1 / 64 , 1/128 , 1/256];
wn_angle = atan(wn);
datax = 3535;
datay = 1965;
datax1 = datax;
datay1 = datay;
if(datax < 0)
datax1 = -datax;
end
if(datay < 0)
datay1 = -datay;
end
anglereal = angle(datax + 1i*datay);
sumangle = 0;
sign = 1;
allsing = 0;
for i = 1 : length(wn)
x2 = datax1 + datay1 * sign * wn(i);
y2 = datay1 - datax1 * sign * wn(i);
datax1 = x2;
datay1 = y2;
sumangle = sumangle + sign * wn_angle(i);
if(datay1 > 0)
sign = 1;
end
if(datay1 < 0)
sign = -1;
end
end
if(datax > 0 && datay > 0)
sumangle = sumangle;
elseif(datax > 0 && datay < 0)
sumangle = -sumangle;
elseif(datax < 0 && datay > 0)
sumangle = pi - sumangle;
elseif(datax < 0 && datay < 0)
sumangle = sumangle - pi;
end