![]() |
by Adrian Porter |
![]() |
cis(x) = cos(x) + i*sin(x)
atanb(y, x) = { 0 y=0 and x>=0
pi y=0
pi/2 x=0 and y>=0
3pi/2 x=0
atan(y/x) x>=0 and y>=0
2pi+atan(y/x) x>=0
pi+atan(y/x) else
|x| = sqr(real(x)^2 + imag(x)^2)
a * b = (real(a) * real(b) - imag(a) * imag(b)) + i(imag(a) * imag(b) + real(a) * real(b))
(foil)
here is the c++ code to do the iterations:
Zx = double(i)/(screenw-1)*curw+ax;
Zy = double(j)/(screenh-1)*curh+ay;
for(n = 1;n<= maxiterations; n++) {
ZN=pow(distance(0,0,Zx,Zy), power);
theta=atanb(Zy, Zx);
Fx1 = ZN * cos(power * theta) - 1;
Fy1 = ZN * sin(power * theta);
ZN=pow(distance(0,0,Zx,Zy), power - 1);
Fx2 = power * ZN * cos((power - 1) * theta);
Fy2 = power * ZN * sin((power - 1) * theta);
ZN=pow(distance(0,0,Fx2,Fy2), -1);
theta=atanb(Fy2, Fx2);
Fx3 = ZN * cos(-1 * theta);
Fy3 = ZN * sin(-1 * theta);
Fx4 = Fx1 * Fx3 - Fy1 * Fy3;
Fy4 = Fy1 * Fx3 + Fx1 * Fy3;
rad=distance(Zx, Zy, Zx - Fx4, Zy - Fy4);
if(rad <= .01) break;
Zx -= Fx4; Zy -= Fy4;
}
for more information on that stuff: search altavista for "Eric's Treasure
Trove"