Chapter 3. Coordinate System

2 views
Skip to first unread message

Pterodactyl

unread,
Apr 24, 2007, 12:44:54 PM4/24/07
to Dive Into PHP 5: The Graphics
Chapter 3. Coordinate System

Table of Contents

Dimensions
Cartesian Coordinate System
Image Coordinate System

This chapter explains the basic coordinate conception.

Dimensions

2D computer graphics is the computer-based generation of digital
images - mostly from two-dimensional models and by techniques specific
to them. 2D graphics models may combine geometric models (also called
vector graphics - see the section called "Vector Graphics" for
details), digital images (also called raster graphics - see the
section called "Raster Graphics" for details), text, mathematical
functions and equations, and more. These components can be modified
and manipulated by two-dimensional geometric transformations such as
translation, rotation, scaling. [1][file:///home/pterodactyl/
bi01.html#wikipedia]

Figure 3.1. 2D Circle
[http://pterodactyl.l2p.net/images/Circle2D.png]
2D Circle

3D computer graphics are different from 2D computer graphics in that a
three-dimensional representation of geometric data is stored in the
computer for the purposes of performing calculations and rendering 2D
images. Such images may be for later display or for real-time viewing.
In computer graphics software, the distinction between 2D and 3D is
occasionally blurred; 2D applications may use 3D techniques to achieve
effects such as lighting, and primarily 3D may use 2D rendering
techniques. [1][file:///home/pterodactyl/bi01.html#wikipedia]

Figure 3.2. 3D Sphere
[http://pterodactyl.l2p.net/images/Sphere3D.jpg]
3D Sphere

[Note][http://pterodactyl.l2p.net/images/docbook/note.png] Note

Most issues in this book are related to 2D graphics.

Cartesian Coordinate System

In mathematics, the Cartesian coordinate system is used to determine
each point uniquely in a plane through two numbers, usually called the
x-coordinate and the y-coordinate of the point. To define the
coordinates, two perpendicular directed lines (the x-axis or abscissa
and the y-axis or ordinate), are specified, as well as the unit
length, which is marked off on the two axes. Cartesian coordinate
systems are also used in space (where three coordinates are used) and
in higher dimensions. [1][file:///home/pterodactyl/
bi01.html#wikipedia]

The modern Cartesian coordinate system in two dimensions (also called
a rectangular coordinate system) is commonly defined by two axes, at
right angles to each other, forming a plane (an xy-plane). The
horizontal axis is normally labeled x, and the vertical axis is
normally labeled y. In a three dimensional coordinate system, another
axis, normally labeled z, is added, providing a third dimension of
space measurement. The axes are commonly defined as mutually
orthogonal to each other (each at a right angle to the other). [1]
[file:///home/pterodactyl/bi01.html#wikipedia]

Figure 3.3. 2D Cartesian Coordinate System
[http://pterodactyl.l2p.net/images/Cartesian2D.png]
2D Cartesian Coordinate System

The image from Wikipedia, the free encyclopedia.

The point of intersection, where the axes meet, is called the origin
normally labeled O. The x and y axes define a plane that is referred
to as the xy plane. Given each axis, choose a unit length, and mark
off each unit along the axis, forming a grid. To specify a particular
point on a two dimensional coordinate system, indicate the x unit
first (abscissa), followed by the y unit (ordinate) in the form (x,
y), an ordered pair. The three dimensional coordinate system provides
the three physical dimensions of space - height, width, and length.
The coordinates in a three dimensional system are of the form (x, y,
z). [1][file:///home/pterodactyl/bi01.html#wikipedia]

Figure 3.4. 3D Cartesian Coordinate System
[http://pterodactyl.l2p.net/images/Cartesian3D.png]
3D Cartesian Coordinate System

The image from Wikipedia, the free encyclopedia.

Image Coordinate System

PHP uses for images the Cartesian coordinate system (see the section
called "Cartesian Coordinate System" for details) slightly modified in
two dimensions (the origin is in the top left-hand corner, so x-
coordinates extend to the right and y-coordinates extend down).

Figure 3.5. 2D Image Coordinate System

<?php

header("Content-type: image/png");

$o = 0; // origin
$x = 200; // width
$y = 100; // height

$image = imagecreate($x, $y);

$white = imagecolorallocate($image, 0xff, 0xff, 0xff);
$red = imagecolorallocate($image, 0xff, 0, 0);
$green = imagecolorallocate($image, 0, 0xff, 0);

imageline($image, $o, $o, $x, $o, $red); // x-axis
imageline($image, $o, $o, $o, $y, $green); // y-axis

imagepng($image);
imagedestroy($image);

?>

[http://pterodactyl.l2p.net/images/ICS2D.png]
2D Image Coordinate System

x - red; y - green

One unit is usually equal to one pixel or sometimes to other pixel
related measure such as twip (1/1440 of an inch or 1/20 of a pixel).

Reply all
Reply to author
Forward
0 new messages