Can someone please show me how to convert from screen coordinates to complex? This picture shows the specific details about conversion
Providing with the steps of how you get a relationship between the two would be really appreciated.
Thanks
Can someone please show me how to convert from screen coordinates to complex? This picture shows the specific details about conversion
Providing with the steps of how you get a relationship between the two would be really appreciated.
Thanks
Screen -> Complex
Conversion:
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
Example C++
implementation:
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);
}
Just rearrange for the other way around.
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]