按照博友给的代码,进行可视化,发现绘出的图形没有错误,但计算的结果16,32,64.。。居然是错的;哪位知道正确的,敬请指正,或是后续啥时候复习完后再改正吧
主要函数代码
i@c_lay = detail(1,'iteration',0);
//printf("current _lay: %d ",@c_lay);
/*
float wn_r[@len];
float wn_i[@len];
//init wn
for(int k=0;k<@len;k++)
{
wn_r[k] = cos(2*3.14/@len*k);
wn_i[k] = -1*sin(2*3.14/@len*k);
}
*/
int len = @numpt;
i@t_lay = @lays; //log2 8
//printf("%d",@numpt);
i@dist = shl(1,@c_lay); //计算每一级的间隔距离
for( int j=0;j<@dist;j++ )
{
for(int k=j;k<len;k+=(shl(@dist,1))) //k计算的序号1
{
int q = k+@dist; //q计算的序号2
int z = shl(k, (@t_lay - @c_lay -1)); //确定旋转因子的指数
//w = rotation_factor(len,1,z);
f@w_real = cos(2* PI * z / len);
f@w_img = -sin(2* PI * z / len);
f@q_real = point(0,'real',q);
f@q_img = point(0,'img',q);
f@k_real = point(0,'real',k);
f@k_img = point(0,'img',k);
// printf("k_real for %d ",@c_lay);
// printf("%f ",@k_real);
float tmp_real =@k_real;
float tmp_img = @k_img;
//complex_multi x
f@wxq_real = @w_real*@q_real -@w_img*@q_img;
f@wxq_img = @w_real*@q_img + @w_img*@q_real;
f@wxq_real = @wxq_real * @q_real - @wxq_img * @q_img;
f@wxq_img = @wxq_real * @q_img + @wxq_img * @q_real;
//complex_add x[k]
tmp_real = @k_real + @wxq_real;
tmp_img = @k_img + @wxq_img;
setpointattrib(0,'real',k,tmp_real);
setpointattrib(0,'img',k,tmp_img);
//printf("%f",tmp_img);
//complex sub x[q]
tmp_real =@k_real-@wxq_real;
tmp_img = @k_img -@wxq_img;
setpointattrib(0,'real',q,tmp_real);
setpointattrib(0,'img',q,tmp_img);
//printf("%f",tmp_img);
//add prim
int plen = detail(0,"len",0);
v@pk1 = point(0,'P',plen+k);
v@pq1 = point(0,'P',plen+q);
v@pk2 = point(0,'P',k);
v@pq2 = point(0,'P',q);
// i@p1 = addpoint(0,@pk1);
// i@p2 = addpoint(0,@pq1);
addprim(0,'polyline',k,plen+q);
addprim(0,'polyline',q,plen+k);
}
}
每次循环中进行两次计算(一次算两)
8点 = log2(8) = 3?分层? ;32点? 5层,64点 6层
每层点的跨度?dist << n(n代表层)