Why Java 2D origin is at the top left corner?

后端 未结 10 803
我寻月下人不归
我寻月下人不归 2021-01-04 23:19

I\'m not complaining, just wonder. Why Java use top left point of the drawing surface as origin? I assume more natural is to choose left bottom corner as origin and increase

相关标签:
10条回答
  • 2021-01-04 23:50

    It always worked like this.

    Back in the assembly days, pixel one has always been on the top left corner. It was the first pixel or character that the user could read.

    This way of numbering things allows you to have a infinitely long image or text. If you started from bottom left and you wanted to add a new line, you'd have to shift all your stuff and recalculate coordinates for everything.

    0 讨论(0)
  • 2021-01-04 23:51

    Could be also due to the CRT monitor, where the electron gun draws the image from left to right and top to bottom.

    0 讨论(0)
  • 2021-01-04 23:53

    Answers like "it was always like this" don't really answer a question of "why", so I'm confused as to why top voted answers are about re-stating the status quo with extra information.

    Eric mentions that “[back] in the assembly days, pixel one has always been on the top left corner”, but he doesn't mention why. He proceeds to explain that if we start from the bottom left corner, and want to add a new line to a body of text, then we'd have to do it by basically overwriting everything on the screen from the bottom upwards (if you started from the bottom left the previous time, then you didn't leave space for this new line; stuff has to be shifted up to add new lines). User Irreputable commented that this makes sense with only some languages (but I don't know any languages that start from the bottom upwards, which is what really matters anyway), and that it doesn't make much sense when it comes to images or graphics; and I concur, he's right about the latter.

    Ubieto gives perhaps the most helpful answer: That it perhaps has to do with how the electron gun of CRT monitors draws the image from top to bottom, left to right.

    However, all these answers perhaps miss one important point: The reason people ask such a question about the top left being the origin of the axes is not just about the point being in the top left, but also because, contrary to the Cartesian coordinate system that all of us are used to all the way from primary school, where the y axis increases upwards, this computer graphics and Java coordinate system increases the y axis downwards! This is one of the most jarring and confusing aspects about this system. If the system had the origin at the top left of the screen but decreased the y axis (and had negative numbers) downwards, then the CRT monitor electron gun would've explained the whole mystery really, at least for me. After all, we would then understand why the (0,0) point is at the top left and everything else works as we would expect from our math education.

    However, that's not the case with the Java and computer graphics 2D coordinate system; the y axis of that system increases downwards, surprisingly enough. Why? I think that's the biggest mystery after we consider the CRT or origins of screen technology. And in an attempt to answer this why question, I can only think of one possibility: Computer scientists wanted the 2D graphics coordinate system to be simpler and avoid the potential confusion of always having the x-axis coordinate positive with a negative y axis. If we assume that the top left origin was a necessity due to the screen technology of the time with its electron gun (avoid screen tearing with that technology), then we realize that computer scientists had the option of:

    1. Treating the screen like its the 4th quadrant, as the Cartesian coordinate system would, with every single pixel in that quadrant (on the screen) having a positive x-axis coordinate and a negative y-axis coordinate, like (5,-5); or

    2. They could flip the y-axis across the x-axis (vertically downwards), bringing the 1st quadrant downwards, and every pixel on the screen thereafter would have both, positive x-axis and positive y-axis coordinates, like (5,5). Perhaps computer scientists simply saw that as a convenience and a way of doing things that minimizes confusion; two positive numbers are perhaps much less confusing and easier to calculate and visualize than a positive and negative number.

    In summary, there are are two aspects to the question: The mystery of the location of (0,0) at the top left instead of bottom left, and the mystery of the y axis increasing downwards. The first mystery is probably best explained by the early monitor technology that worked top to bottom, left to right. And the second mystery is probably best explained by a desire for simplicity and clarity via adopting a coordinate system with two positive numbers for the x and y coordinates, rather than the potentially confusing system that would permanently rely on a positive x-axis coordinate paired with a negative y-axis coordinate.

    0 讨论(0)
  • 2021-01-04 23:54

    I think to be compatible with the frames minimizing and maximizing
    The obvious focusing area is where the first word in a page written in english appears ,namely, the top left witch is the most natural way except when it comes to graphical representation of some math in the first quadrant which became the second with the y axis positive (reflected or rotated 180° about the origin (I came to this while googling the way to solve that) actually the decision was made long time before the computer and crt age

    0 讨论(0)
  • 2021-01-05 00:07

    If you go back far enough, like 1981, you can find some exceptions!
    http://central.kaserver5.org/Kasoft/Typeset/BBC/Ch08.html

    "Imagine a graphics window which has its edges a, b, c and d 'graphics units' away from the bottom left hand corner of the screen (which is always the starting point for graphics)."

    0 讨论(0)
  • 2021-01-05 00:08

    With the right hand coordinate system, when X and Y are placed at the top-left corner, Z goes into the screen. Graphics engine can now know the points which are away from screen ... larger the Z further away the points are .... very useful in rendering multiple objects placed in space and some objects are hiding others ...

    0 讨论(0)
提交回复
热议问题