Given a computer program generating the Mandelbrot Set - using this one for example, which uses a module called mandel.js - what would be the pseudocode to find the complex coordinates, capable of creating a highlighted point representing the tangent where that co-prime's bulb connects, from two entered p and q values?
Refer to the passage here and the accompanying equation beginning C p/q = ...
So far I have tried:
part1 = (E^(2.0 * PI * i * (p div q))) div 2.0 part2 = 1.0 - (E^(2.0 * PI * i * (p div q))) div 2.0
Where p and q are co-primes, PI and E are the expected constants, and i is set to 1 or -1 (not sure of the correct handling of i in this context).
This simply tries to solve two parts of the equation given p and q, and does not seem to work. I am having trouble (1) programmatically translating the fundamental equation to code, and (2) conceptually relating the resulting parameter solution set for co-primes given p and q in the equation referenced, which I don't fully understand, to the complex plane as the standard screen geometry x,y pixel-painting used in the program, which I can understand.
SOLUTION:
Thanks to Jim's helpfulness, here is the pseudocode I came up with and tested in a working fork of the M-set program mentioned:
1 epower = ((p * 2 * PI)/q) 2 expr = CPLX(COS(epower),SIN(epower)) 3 divBy = CPLX(2,0) 4 subFrom = CPLX(1,0) 5 term1 = CPLX.divide(expr,divBy) 6 term2 = CPLX.subtract(subFrom,term1) 7 result = CPLX.multiply(term1,term2) 8 x = result.real 9 y = result.imag
Line 1 is the complex power of e in the equation. Line 2 required a bit of research - it is apparently an application of de Moivre's formula. I imported and stitched together a custom complex number object from two examples I found on the web. This library is indicated as CPLX. It's constructor takes two parts, a real and imaginary, to create a complex variable. It then supports the basic operations. Lines 3 and 4 are just real numbers turned into complex number form to support the operations in lines 5, 6, 7. Lines 8 and 9 return the resulting complex number parts, which can be translated into the screen geometry of the M-set display.