As an expansion to my fractal software, I've decided to add center plus width as an image location/definition. Which leads me to the question of how do I convert the complex number given to an x,y coordinate on the screen plane. Obviously, I do this when I calculate the image as I iterate a given function, but I do that in terms that are not applicable to the 'free-standing' number I want to deal with. I can go in the other direction with no problem but have not been able to figure this one out. The downside of doing mathematics without being a mathematician! In short, complex to screen conversion—how? As an example of screen to complex conversion her is the function I use for that:
scr2Pix = (pX, pY, pW, pH, minX, maxX, minY, maxY) ->
xPercent = pX / pW
yPercent = pY / pH
newX = minX + (maxX - minX) * xPercent;
newY = minY + (maxY - minY) * yPercent;
[newX, newY]
The language is coffeescript. The parameters are better shown in this snippet:
x1 = -2.5 #! lower left X—complex
y1 = -1.5 #! lower left Y—complex
x2 = 1.5 #! upper right X—complex
y2 = 1.5 #! upper right Y—complex
console.log scr2Pix(320,240,640,480,x1,x2,y1,y2)
with a return value of [-0.5, 0], in effect asking for the conversion of 320,240 to a complex number. NB pW is screen width, pH is screen height, with pX and pY being the coordinates of the location I'd like to convert.
I believe what I'm looking for is pix2Scr() not so much as code, but as an algorithm that I can add to my collection.
The proposed answer coded inline as:
Sw = 640
w = 4
Sh = 480
x = -0.5
y = 0
nx = (Sw/(2*w)) * x + (-Sw/2)
ny = (Sw/(2*w)) * -y + (-Sh/2)
console.log nx,ny
produces -360 -240 which is correct except for sign so I've put in one too many minus signs somewhere?
https://mrob.com/pub/muency/seahorsevalley.html
– hsmyers Jan 22 '19 at 21:41