0

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

Dmitry
  • 13,797
  • 6
  • 32
  • 48
gmoney
  • 51
  • 1
  • 6
  • This is not a programming question. That asside, are you sure you want `-2` in the top left corner, and not `-1` ? – Beta Carotin Apr 24 '15 at 20:39
  • yeh im sure its -2 and not -1 – gmoney Apr 24 '15 at 20:43
  • Explore User Defined Literals – The Vivandiere Apr 24 '15 at 20:46
  • there is a complex type in system.numerics – RadioSpace Apr 24 '15 at 20:48
  • You could use Linear Algebra and use a scaling and transformation matrix. You may be able to combine them into one matrix. – Thomas Matthews Apr 24 '15 at 21:00
  • You should be a lot clearer as to what you really want; sometimes words sound simple but hide the real problems. To transform coordinates you need nothing more than simplest arithmetic, but this will still not transform real 2d into complex numbers.. For a Graphics object G you could use `Matrix M = new Matrix(); M.Scale(1f / this.Width, 1f / this.Height); M.Translate(-2, -1); G.MultiplyTransform(M);` I think writing a few transformation functions will be better; separate the calculation and the display, aka model-view! – TaW Apr 25 '15 at 09:43

2 Answers2

1

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.

Beta Carotin
  • 1,659
  • 1
  • 10
  • 27
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]  
R Sahu
  • 204,454
  • 14
  • 159
  • 270