Why is the origin at the upper left corner?


Via the Suggestion Box, Dirk Declercq asks why the default client-area coordinate origin is at the upper left corner instead of the lower left corner. (I assume he also intends for the proposed client-area coordinate system to have the y-coordinate increasing as you move towards the top of the screen.)

Well, putting the client area origin at the lower left would have resulted in the client coordinate space not being a simple translation of the screen coordinate space. After all, the screen origin is at the upper left, too. Windows was originally developed on left-to-right systems, where the relationship between client coordinates and screen coordinates was a simple translation. Having the y-coordinate increase as you move down the screen but move up the client would have just been one of those things you did to be annoying.

Okay, so why not place the screen origin at the lower left, too?

Actually, OS/2 does this, and DIBs do it as well. And then everybody wonders why their images are upside-down.

Turns out that the people who designed early personal computers didn't care much for mathematical theory. The raster gun of a television set starts at the upper left corner, continues to the right, and when it reaches the right-hand edge of the screen, it jumps back to the left edge of the screen to render the second scan line. Why did television sets scan from the top down instead of from the bottom up? Beats me. You'll have to ask the person who invented the television (who, depending on whom you ask, is Russian or American or German or Scottish or some other nationality entirely), or more specifically, whoever invented the scanning model of image rendering, why they started from the top rather than from the bottom.

Anyway, given that the video hardware worked from top to bottom, it was only natural that the memory for the video hardware work the same way. (The Apple II famously uses a peculiar memory layout in order to save a chip.)

Who knows, maybe if the design of early computers had been Chinese, we would be wondering why the origin was in the upper right corner with the pixels in column-major order.

Bonus chatter: Even mathematicians can't get their story straight. Matrices are typically written with the origin element at the upper left. Which reminds me of a story from the old Windows 95 days. The GDI folks received a defect report from the user interface team, who backed up their report with a complicated mathematical explanation. The GDI team accepted the change request with the remark, "We ain't much fer book lernin."

Comments (32)
  1. Frederik Slijkerman says:

    Actually Cocoa interfaces on Mac OS X, and Quartz as well, use the lower-left coordinate as the origin, which is an unbelievable pain. Perhaps one or two mathematicians were helped by this decision, but it's so incredibly counterintuitive to anyone else. Especially because we think from top to bottom, lay out controls, text etc from top to bottom. Worst decision they ever made.

  2. jmthomas says:

    More History.

    This "origin" issue was the formal pre-text for the great IBM/Microsoft divorce way back when OS/2 was just getting started.  But what I remember most about the divorce was Bill Gates comments in PC Week about being done forever with IBM process development overhead.

    Then there was the story about some famous DEC guy being hired to write MS's new operating system…

  3. R. Bemrose says:

    @jmthomas:

    "Then there was the story about some famous DEC guy being hired to write MS's new operating system…"

    You mean Dave Cutler?

    en.wikipedia.org/…/Dave_Cutler

    [I bet you're also the sort of person who who responds to "That's caused by this bright yellow thing in the sky, I forget its name" by volunteering "You mean the sun?" -Raymond]
  4. Michael says:

    Scanning from top to bottom is obvious, as you don't have to wait for an entire frame to be sent first, you just begin scanning as soon as you begin receiving data.

    [But why does the cathode ray tube scan from top to bottom? Why not from bottom to top? -Raymond]
  5. Robin Williams says:

    It all depends on what you've become accustomed to really.  My first programming steps were on the BBC Micro, which used the bottom left as 0,0.  So when I moved on to a PC later, I had to get used to the way QBASIC did it 'the wrong way' at the top left.

    If you start at the bottom left the GRAPHics work the same as a graph, which makes sense.

    If you start at the top left the graphics work the same as we read, which also makes sense.

  6. Marquess says:

    I'll hazard the guess that our coordinate system was invented by physicists, as mathematicians usually don't care where the positive direction is. (And really, two dimensions? How boring!)

    Much more annoying is the fact that CreateWindow (and many other functions) want their coordinates as two separate parameters instead of a POINT, so you can't just squeeze in a translation function.

    Farnsworth you say? I can just imagine: “Good news, everyone! I've just invented a device that let's you look at <insert the Internet's major purpose here> all day!”

    Bonus question: Had they developed Windows in Fortran, would the screen be addressed in column-major order?

  7. Ivo says:

    I don't think there is much controversy about matrices. They are always top to bottom, left to right. Now vectors are a different story. If you come from computer graphics, you usually think of vectors as rows: (X, Y, Z). If you come from linear algebra, it is most often columns:

    X

    Y

    Z

    Neither is better than the other, you just can't mix the two. I once had to work on a code where the matrix system was assuming vectors as rows, and the quaternion system was assuming vectors as columns. Hilarity ensued! It wasn't long before I went berserk on the code and made it consistent.

  8. Marquess says:

    Unnecessary math background information: Vectors, as such, are neither rows nor columns. They are a set over a field which is closed under addition and scaling. As such, matrices, real numbers, as well as row and column vectors are specific types of vectors in different spaces, and the union of two vector spaces is, in general, not a vector space.

    Let's not get into the difference between points in affine space and vectors.

    And then there are those blasphemous numerical analysts who dare to multiply row and column vectors as if they are matrices to produce the standard scalar product or a symmetrical matrix. Heretics!

  9. David Brooks says:

    The top-down habit may also inherit from the earliest scanners: fax machines, where it seems to be natural to insert the document top-first. The first faxes were so slow that it was useful to be able to start reading the document as it was being generated.

  10. DWalker59 says:

    When you display the contents of computer memory (using the console-mode debugging tools, for example), the values are displayed from top to bottom (and left to right in US English at least).  I suppose that is an artifact of the console mode itself.

    I had trouble when one computer science prof always drew a block of memory with address 0 at the lower left, because it seemed upside-down to me.  It seems that half of the printed diagrams of memory blocks (in books, for exmaple) show address 0 at the lower left and half show 0 at the upper left.

    Yes, an X-Y coordinate system in math (or book lernin') has (0,0) at the lower left, but for historical reasons, we (at least I) think of memory from the "top down".  I have no idea how computer memory, or graphics memory, actually maps onto the chips in the computer or the chips on the graphics card.  Maybe we should map the coordinates of a computer display in the same way that the graphics memory chips hold the memory, if that's even possible.  :-)

    Interestingly, various disk defragmenting tools, which usually show the graphical map of disk blocks as a rectangle, show the "start" of the disk map in either the lower left or upper left corner.  (There is at least one such tool that shows the map of disk blocks arranged in concentric circles just like a physical spinning disk is made…. of course, you have to ignore remapped blocks and the new-fangled solid-state disks.)

    The moral, I suppose, is that there is no consistency; you just have to learn the conventions.

  11. DWalker59 says:

    I forgot about "little endian" and "big endian" too…

  12. Gabe says:

    I learned to program on a Timex/Sinclair 2068 (the US version of the ZX Spectrum), which had top-down coordinates for text and bottom-up coordinates for graphics. To make it even more fun, not only did it have 64:1 interleaving for the bits that said whether any particular pixel was foreground or background, it had a separate block of memory to say what the foreground and background were for each 8×8 pixel block. There was also a generous overscan area to which you could assign one particular color.

    http://www.worldofspectrum.org/…/formats.htm gives a better description, and http://www.zx81stuff.org.uk/…/loadingscreen.html has a Java applet that shows what it looks like to fill in the display file (frame buffer in today's parlance) in byte order (row 0, 8, 16, 24, 32, 40, 48, 56, 1, 9, …, 64, 72, … then all the colors).

  13. Adam Rosenfield says:

    I'm somewhat surprised I didn't see a link to blogs.msdn.com/…/6157507.aspx on the text "We ain't much fer book lernin" (which I coincidentally just read last night while slowly making my way through the archives).

    [Looks like I got my stories confused. Thanks for the correction. -Raymond]
  14. Maurits says:

    Why do Descartes-ian coordinate systems get plotted with y ascending up the page rather than down the page?

    Probably so that "z" can ascend toward the viewer and obey the right-hand rule.

    (Note that plots of 3-D coordinate systems vary in right-hand-rule compliance.)

  15. Marquess says:

    “Why do Descartes-ian coordinate systems get plotted with y ascending up the page rather than down the page?”

    Plot a mountain range. Or the path of a ballistic missile. Would look odd if they were upside-down, wouldn't it?

  16. Adam says:

    With regards to memory being "zero at the top" or "zero at the bottom", consider that the memory starting at 640k is "above" 640k, and is (ok, was…) accessed as "high mem"

  17. ERock says:

    Your app can use any coordinates it damn well pleases. Just fix it in your rendering code. ;)

    On a more serious note, in the bad old days when high resolution displays started coming out, remember the screaming horror that was bank switching on video cards that didn't support a linear frame buffer?

  18. Someone You Know says:

    @Marquess

    Now you're just showing your northern hemisphere-chauvinism. A graph with the Y axis descending down the page would look perfectly natural to someone in the southern hemisphere, where everything is upside-down.

  19. Richard Russell says:

    @Robin

    To be pedantic, when you moved from a BBC Micro to a PC you didn't "have to get used to the way QBASIC did it", you could have run BBC BASIC on the PC (if this was any time after about 1986)! http://bb4w.com/

  20. dalek says:

    Thank god the coordinates are 0 at top left. Imagine a display with 0,0 at lower left corner. Now show a document that doesn't fit on the display. Now the origin of your document depends on the display resolution!  Now implement scrollbars. Good luck trying to make something logical/intuitive :)

  21. Maurits says:

    A graph with the Y axis descending down the page would look perfectly natural to someone in the southern hemisphere, where everything is upside-down.

    Starworthy

  22. James says:

    Additionally, matrix notation uses the first index to indicate the row and the second index to indicate the column, which is backwards from Cartesian (x, y) coordinates.

  23. Medinoc says:

    More confusing was the Amstrad CPC: Text coordinates were top-down, graphic memory was top-down too (with 8:1 interleaving like in the Apple II), but graphic coordinates were bottom-up.

  24. Robin Williams says:

    @Richard Russell

    Ha yes of course, but that option didn't occur to my 12-year old mind in the late 80s.

    Besides, emulation always feels a bit like taking your own beer to someone else's house.

  25. Morten says:

    [But why does the cathode ray tube scan from top to bottom? Why not from bottom to top? -Raymond]

    Could be because that's how you paint a wall using a paintbrush? If you start at the bottom you have to go back and correct runners, if you start at the top the problem takes care of itself. Lots of metaphors in design come from ancient habits. Just take the boosters for the space shuttle, fer'instance… :-)

  26. Another obvious alternative says:

    There is another obvious alternative. Have the origin in the center.

    That is, in a 640×480 screen, coords go from -320,-240 to +320,+240.

  27. Marquess says:

    Of course, the “obvious alternative” combines the disadvantages of the top-down design with the disadvantages of the bottom-up design.

  28. dave says:

    Given a piece of lined paper, where would most people consider "the first line on the page" to be?

    Now generalize to pixels.

  29. Maurits says:

    in a 640×480 screen, coords go from -320,-240 to +320,+240

    That would be a 641×481 screen… using two's complement integer as a precedent I would suggest -320,-240 to +319,+239

  30. Anon says:

    I once worked for a boss who had a strict rule that screens should be updated from top-left to bottom-right.

    This is A Good Thing™ since [in my culture] this is the natural and expected Way Of Things™.  This was not the reason for his rule however….

    Rather, he thought this meant the screen was being updated in the most efficient manner possible as it meant that the screen updates "followed" the path of the CRT gun updating the display.

  31. dave says:

    re Anon:

    I once wrote a block-mode terminal emulator that output to a VT100 character-mode terminal. A major goal was to reduce the number of bytes of output (lines were slow back then), so my 'update' algorithm started wherever the cursor happened to be, wrote to end of screen, then wrote the top half, ending up with the cursor back where it started.  I think I saved a dozen or so bytes of output that way. I was very proud.

    I had so many complaints about the 'weird' update that I eventually gave in and did top-to-bottom writes.

  32. DWalker59 says:

    @dave:  Reminds me…  One old-world multi-user time-sliced system that ran on a mainframe used a swap disk to entirely swap in and out the memory space of the various users.  Half the time, when it switched users, it would bring in the user whose turn was next, and half the time it would bring in whichever runnable user's swapped-out data was closest to where the swap disk's read-write head happened to be at that very instant.  To minimize disk seeking.  The algorithm worked pretty well.  I thought it was an interesting algorithm.

Comments are closed.