dobrishk's blog

By dobrishk, history, 12 days ago, translation, In English

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.

  • Vote: I like it
  • +3
  • Vote: I do not like it