Understanding the coordinate system is another important part of graphics programming. The coordinate system represents the positions of graphic objects on a display device such as a monitor or a printer.
2.2.1 The Cartesian Coordinate System
The Cartesian coordinate system (shown in Figure 2.2) divides a two-dimensional plane into four regions, also called quadrants, and two axes: x and y. The x-axis is represented by a horizontal line and the y-axis by a vertical line. An ordered pair of x and y positions defines a point in a plane. The origin of the plane is a point with x = 0 and y = 0 values, and the quadrants divide the plane relative to the origin.
Figure 2.2. The Cartesian coordinate system
To find out which point falls in which quadrant, we compare the point's x- and y-positions relative to the origin:
Quadrant I: x > 0 and y > 0
Quadrant II: x < 0 and y > 0
Quadrant III: x < 0 and y < 0
Quadrant IV: x > 0 and y < 0
A point with positive x and y values will fall in quadrant I. A point with +y and x values will fall in quadrant II. A point with x and y values will fall in quadrant III, and a point with +x and y values will fall in quadrant IV. For example, a point at coordinates (2, 3) will fall in quadrant IV, and a point at coordinates (3, 2) will fall in quadrant II.
2.2.2 The Default GDI+ Coordinate System
Unlike the Cartesian coordinate system, the default GDI+ coordinate system starts with the origin in the upper left corner. The default x-axis points to the right, and the y-axis points down. As Figure 2.3 shows, the upper left corner starts with points x = 0 and y = 0. Points to the left of x = 0 are negative values in the x-direction, and points above y = 0 are negative values in the y-direction.
Figure 2.3. The GDI+ coordinate system
Because the default GDI+ coordinate system starts with (x = 0, y = 0) in the upper left corner of the screen, by default you can see only the points that have positive x and y values. Objects with either x or y values will not be visible on the screen. However, you can apply transformations to move objects with negative values into the visible area.
GDI+ provides three types of coordinate systems: world coordinates, page coordinates, and device coordinates.
Figure 2.4. Drawing a line from point (0, 0) to point (120, 80)
We will discuss coordinate systems and transformation in more detail in Chapter 10.
GDI+: The Next-Generation Graphics Interface
Your First GDI+ Application
The Graphics Class
Working with Brushes and Pens
Colors, Fonts, and Text
Rectangles and Regions
Working with Images
Advanced 2D Graphics
Developing GDI+ Web Applications
GDI+ Best Practices and Performance Techniques
Miscellaneous GDI+ Examples
Appendix A. Exception Handling in .NET