Quote:
|
Originally Posted by TheBigDog
I...Help me Pyrotex! Help!
|
"Here He comes, to save the day!"
Means that Pyrotex, is on the way!
Sure! Glad to help!
The basics of complex arithmetic:
We do CA on the Complex Plane, where the X-axis is "real"
and the Y-axis is "imaginary". All values up and down the Y-axis are considered to be multiplied by the square root of minus one, or "i".
"Numbers" in the CP correspond to points, with a real component and an imaginary component. For example, (3,4i) or (-17,-i).
Sometimes (often) complex numbers are represented as 3+4i or -17-i.
Assume two complex numbers A and C: (a,b,c,d are all real)
A = a + bi
C = c + di
--------------Complex Arithmetic:
ADDITION
E = A + C
= a + bi + c + di
= (a+c) + (b+d)i
MULTIPLICATION
F = A * C = (a + bi)*(c + di)
= a*c + a*di + bi*c + bi*di
= a*c + (a*d + b*c)i + b*d*(-1)
= a*c - b*d + (a*d + b*c)i
SQUARING
G = A squared = (a + bi)*(a + bi)
= a*a - b*b + (a*b + a*b)i
= a*a - b*b + (2*a*b)i
So, in the code you have trouble with, this is how the math works. We are squaring a complex value and then adding the complex value.
A^2 + A would equal
[a*a - b*b + (2*a*b)i] + [a + bi]
but it is easier to keep the squares in their own variable as you need them again for the iteration test.
Although the algorithm I gave you works just fine, technically you should ADD first THEN square. Starting with initial value zero: 0 + 0i. It works out the same except for calculating the distance of the new point from the origin. If you do it properly (Add, Square) then the distance from the new point A [a+bi] to the origin is:
distance = sqroot[ a*a + b*b ]
But it REALLY speeds up the algorithm if you avoid taking the squareroot!!!
So, instead of testing if distance <2
Rather, test if distance^2 <4
Distance^2 is just a*a + b*b, or in the code, asq + bsq.
Does this help???