2.5. Coordinate Space

Java 2D objects live in a plane defined by Cartesian coordinates. This plane is called User Coordinate Space, or just User Space. When objects are drawn on a screen or a printer, User Space coordinates are transformed into Device Space coordinates. Device Space corresponds to a particular monitor or printer—usually, one unit in Device Space corresponds to one pixel of a device. By default, User Space and Device Space are aligned, with the x and y axes oriented as shown in Figure 2.7. The x axis increases from left to right, and the y axis increases from top to bottom. The origin is placed at the upper left corner of the drawing surface. This applies for any device, where left, right, top, and bottom are defined in terms of the device itself—the sides of a monitor, for example, or the orientation of a sheet of paper in a printer. Note that the y axis is aligned so that it increases as you go down—this may be the opposite of what you were expecting.

Figure 2.7. Device Space coordinate system

Although User Space and Device Space are aligned by default, some scaling must take place to ensure that objects are drawn the same size, regardless of the output device. Device Space is determined by the resolution of a particular device. A monitor, for example, typically has about 72 pixels per inch, while a laser printer generally has 300 or 600 pixels per inch (or ...

Get Java 2D Graphics now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.