【问题标题】:Converting Screen Coordinates to Complex Coordinates将屏幕坐标转换为复杂坐标
【发布时间】:2023-10-06 10:07:01
【问题描述】:

有人可以告诉我如何将屏幕坐标转换为复数吗?这张图显示了关于转换的具体细节

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

谢谢

【问题讨论】:

  • 这不是编程问题。除此之外,您确定要在左上角使用-2,而不是-1
  • 是的,我确定它是 -2 而不是 -1
  • 探索用户定义的文字
  • system.numerics 中有一个复杂类型
  • 您可以使用线性代数并使用缩放和变换矩阵。您也许可以将它们组合成一个矩阵。

标签: c# c++ fractals mandelbrot


【解决方案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);
}

换一种方式重新排列即可。

【讨论】:

    【解决方案2】:
    屏幕坐标 [0,0] -> 复坐标 [-2, 1] 屏幕坐标 [width,height] -> 复坐标 [1, -1] 屏幕 X 坐标 [x] -> 复坐标 [-2 + 3*x/width] 屏幕 Y 坐标 [y] -> 复坐标 [1 - 2*y/height]

    【讨论】:

    • 使用y/height 而不是x/height