When I first studied graphics programming, I was traumatized that the coordinate system on a computer’s screen is upside down. The positive x-axis starts on the far left and points to the right as normal coordinates should do, but the y-axis has its 0 at the top of the screen and nosedives straight down to hell from there. Imagine that you have all your graphics worked out beautifully on paper, and then when you try to program it in a computer, you have to flip all the figures and re-calculate all the coordinates. Why can’t computer scientists be normal for once and respect the centuries-old Math? Cartesian coordinates were invented in the 17th century, while the first electronic general-purpose computer (ENIAC) didn’t come out until 1946.
After countless sleepless nights, today I decided to grow up and google it. As it turned out, computer scientists are not the one to blame. Computers inherit their coordinates from early analog cathode-ray tube (CRT) televisions. A CRT television displays an image by scanning a beam of electrons across the screen in a pattern of horizontal lines from left to right, top to bottom.
Nobody seems to know exactly why the first TVs were made to work that way, and the people who invented TVs are a little bit too dead for us to ask. However, there are a few plausible theories:
– It is consistent with the convention people read and write in some Western countries: from left to right, top to bottom.
– It allows the right-handed coordinate system to have the positive Z axis going into the screen rather than coming out of it. Why they need the positive Z axis to go into the screen, I don’t know.
According to Window Dev Center, “the system and applications specify the position of a window on the screen in screen coordinates“. Interestingly, not all systems have their screen coordinates’ origin start from upper left corner. OpenGL, an API for rendering 2D and 3D vector graphics, puts its origin at the bottom left corner because it’s easier to imagine 3D objects this way. Apple’s Cocoa framework for building software programs to run on iOS has its origin at the bottom left corner because it’s Apple and they can do whatever they please. The BMP file format, also known as bitmap image file or device independent bitmap (DIB) file format, lets users choose where to put the origin: bottom-up or top-down. Then everybody wondered why their images were upside-down.
If you think that computer scientists are confusing, mathematicians are not any better. They get their coordinates messed up sometimes too. Matrices have their first index (1,1) (not (0,0) — duh) starting from the upper left.
3 thoughts on “Why computer coordinates start from the upper left corner”
I could have saved 2 hours of debugging if I read this earlier !
LikeLiked by 1 person
the math assholes are prob the reason why. i remember the first time messing with opencv i figured this all out, so dumb but since the math guys started CS, they prob drug that shit on over, bc in image processing, you consider a 2D array (or whatever struct you use) of 8-bit intensity values as a matrix, and a video being a sequence of 2D matrices. So thanks math guys! haha