Transition from the screen coordinate system to the Cartesian one.

Revision en2, by dobrishk, 2024-12-10 18:17:35

Many tasks require working with coordinate systems. Most often, we are used to the Cartesian coordinate system, where

  • the x-axis is directed to the right,

  • the y-axis is up.

  • the origin of the coordinates is in the center.

However, a different system is used in computer graphics and data processing tasks on the screen:

  • x is pointing downwards,

  • y is directed to the right,

  • the origin is in the upper left corner.

This approach is due to the peculiarities of screens and two-dimensional arrays. Sometimes tasks require converting this system to a Cartesian one, where the center of the screen becomes the origin. Suppose we have a screen with a height of n and a width of m pixels. The center of the screen is at the point (n / 2, m / 2).

To switch from screen coordinates (x0,y0) to Cartesian coordinates (x,y), the following formula is used:

$$$x=y0-m/2$$$

$$$y=-(x0-n/2)$$$

It is important to keep in mind that the division in this case is an integer.

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
ru4 Russian dobrishk 2024-12-10 18:26:15 2
ru3 Russian dobrishk 2024-12-10 18:17:55 55
en2 English dobrishk 2024-12-10 18:17:35 55 Tiny change: 'is used:\n$x=y0-m/' -> 'is used:\n\n$x=y0-m/'
en1 English dobrishk 2024-12-10 18:11:50 1198 Initial revision for English translation
ru2 Russian dobrishk 2024-12-10 18:08:28 52
ru1 Russian dobrishk 2024-12-10 18:07:53 1151 Первая редакция (опубликовано)