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

10

10

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 axis as they go up and right (similar to Quartz).

Wirework answered 15/3, 2011 at 2:41 Comment(3)
so Quartz is following the same idiom as the Cartesian-coordinate system...I mean the normal way we read a simple graph...hmm, what a revelation...Kilah
as everyone commented... To me it always made sense, back when synchronization graphics drawing with the CRT's beam was an art :) The bean goes from top/left to bottom/right. As long as we were copying our backbuffer to (0,0) and as long as that copy was faster than the beam, there was no tearing/no flicking/etc.Lexical
After more than two decades of the Cartesian coordinate system, with (0,0) at the bottom left corner, and more importantly, y positive going up, this top left system with y positive going down confuses and even annoys me. And none of the explanations below really answer the question for me. I think it has to do with convenience or avoiding negative y coordinates, and I'll attempt an answer along these lines.Indus
C
12

Computer graphics has had the origin in the upper left since the dawn of time, with QuickDraw included. Using the lower left (as in math) is a PostScript/PDF thing. Since Quartz is based on PDF, it uses its coordinates, but that is mostly a unique decision among graphics libraries.

Carditis answered 15/3, 2011 at 2:45 Comment(1)
+1 for explaining the difference between standard video device coordinate system (ULO) and Quartz/PostScript/Cartesian coordinate system (LLO)Kilah
W
10

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.

Weiss answered 15/3, 2011 at 2:45 Comment(2)
I concur... it adopts the same idiom used in legacy PC video subsystem's display refresh cycle to this day which performs scanning from left to right, from top to bottom.Kilah
for text this makes sense (except for some languages that have different directions, either horizontally or vertically). but not so much for images and graphics.Commissioner
O
3

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

Otte answered 15/3, 2011 at 2:50 Comment(1)
I concur... it adopts the same idiom used in legacy PC video subsystem's display refresh cycle to this day which performs scanning from left to right, from top to bottom.Kilah
F
3

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)."

Felicefelicia answered 2/1, 2012 at 20:34 Comment(0)
C
1

probably came from television standard, where scan starts from top to bottom.

Commissioner answered 15/3, 2011 at 3:37 Comment(0)
T
1

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 ...

Thickening answered 19/1, 2012 at 9:27 Comment(1)
True and interesting point. It's all just convention though. I can't see an absolute necessity that the Z-axis needs to be directed into (or out of) the screen.Cinch
I
1

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.

Indus answered 8/12, 2015 at 13:12 Comment(2)
I fail to understand your point here. I get that we are all into wild speculation where "It was convenient at the time" / "It is still convenient under some circumstances" seem to be the accepted answer. Limitations of the electron gun can possibly make sense, but I don't get how they could not physically flip the gun to get the axis in any way they wanted. Moreover, those guns are targeted using an electrical field which seems to be trivial to invert from left to right and up to down.Weiss
My point is summarized in the final paragraph: Two aspects to the question, and each explained by a strong possibility. And it's not about flipping or inverting a gun; it's about moving a gun to a completely different location, from top left to bottom left, and movement in the opposite direction; I don't think such a move would've been easy if industry or factory standards, perhaps from before PC monitors, based on older TVs dictated the top left locations.Indus
D
0

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

Disenchant answered 21/5, 2011 at 9:49 Comment(1)
This answer doesn't make much sense. The only comprehensible part is about English starting from the top left, but what this has to do with frames, minimizing and maximizing, or the first quadrant becoming second, I really have no idea. I read the answer about 10 times, and it is still more confusing than clarifying.Indus
D
-2

Just an implementation choice. Screen coordinates in windows and other OS are given the same way, so I am guessing they chose that to be consistent with the OS's choice, which is likely a legacy thing.

Dorsad answered 15/3, 2011 at 2:44 Comment(1)
I concur... it adopts the same idiom used in legacy PC video subsystem's display refresh cycle to this day which performs scanning from left to right, from top to bottom.Kilah
M
-2

It also has the benefit of being similar to 2-D arrays in programs, where [0][0] refers to the upper-left element.

Mississippian answered 23/7, 2012 at 11:38 Comment(1)
Arrays don't really have an "upper-left", unless you write them out with the origin at.. the upper left.Abecedarian

© 2022 - 2024 — McMap. All rights reserved.