将屏幕坐标转换为复杂坐标

时间:2015-04-24 20:29:03

标签: c# c++ fractals mandelbrot

有人可以告诉我如何从屏幕坐标转换为复杂吗?此图显示了有关转换的具体细节

提供如何在两者之间建立关系的步骤将非常感激。

由于

2 个答案:

答案 0 :(得分:1)

屏幕 - >复杂的

转换:

screenPointX .. X coordinate on the screen  
screenPointY .. Y coordinate on the screen  
screenWidth  .. width of the screen  
screenHeight .. height of the screen  
re           .. real component of resulting complex
im           .. imaginary component of resulting complex

re = 3 * screenPointX / screenWidth - 2
im = 1 - 2 * screenPointY / screenHeight

示例C++实施:

template<class T>
std::complex<T> screenToComplex(
    T screenPointX,
    T screenPointY,
    T screenWidth,
    T screenHeight)
{
    T re = 3 * screenPointX / screenWidth - 2;
    T im = 1 - 2 * screenPointY / screenHeight;
    return std::complex<T>(re, im);
}

重新安排反过来。

答案 1 :(得分:0)

Screen coordinate [0,0]          -> Complex coordinate [-2, 1]  
Screen coordinate [width,height] -> Complex coordinate [1, -1]

Screen X coordinate [x]          -> Complex coordinate [-2 + 3*x/width]  
Screen Y coordinate [y]          -> Complex coordinate [1  - 2*y/height]