Geometry and Light Generations
- The smallest element which can be shown on a graph is a point. A point may be illustrated as following figure.
As we can see, A point A has been positioned in XY-plane and (x1, y1) is the position of a point A. This means that point A is at distance x1 in X-direction and it is at distance y1 in Y-direction from origin (0, 0). The ordered pair (x1, y1) is known as the coordinates of point A. The values of x1 and y1 are the horizontal and vertical distance respectively of the point A from the origin.
Straight Line and Line Segment
Any two points specified in a plane will define a line. This means, to define a line one needs at least two points. In following figure, two points P1(x1, y1) and P2(x2, y2) define a line l1.
Now, to define a line we need an equation:
- A point (xi, yi) is said to be on the line if and only if it satisfy the equation of line. The equation of a straight line can be derived with the help of slope of concept of a straight line, which measures the steepness of it.
- The slope is the rate at which an ordinate of point of a plane changes with respect to a change in the horizontal coordinate. This can be measured by the ratio between the differences of vertical coordinates of two points on the line to that of horizontal coordinates of those two points. Generally the notion slope is denoted by m. Thus,
- m=Vertical distance between two points / Horizontal distance between two pints.
- Assume two points P1(x1, y1) and P2(x2, y2) on a line l1. For this line slope is,
- m= y2 – y1 / x2 – x1
- Slope of any line can be of four types: the straight line with positive slope, the straight line with negative slope, the line with zero slope and the line with undefined slope.
These types are illustrated by following figures.
- To derive an equation of a line the concept of slope is used. The slope between any two points of a line always remains constant. Let us consider two points P1(x1, y1) and P2(x2, y2) on a line and also assume point (x, y) on the same line. According to the equation of a straight line, the slope between any two points is constant. The slope is
m= y2– y / x2 – x and also m= y2 – y1 / x2– x1
y = mx + b —— Equation (2.1)
- The general form of a straight line is,
ax + by + c = 0
Pixels and Frame Buffer
- The pixel is a smallest addressable screen element. It is the smallest piece of the display screen which we can control. Each pixel has name and address. The name which identify pixel corresponding to the coordinates which identify the points.
- Computer Graphics images are made by setting the intensity and color of pixel which compose the screen. We draw line segment by setting the intensity that is the brightness of pixels between starting pixel and ending pixel. The coordinate will be (I, j) that gives column and row of a pixel. Each pixel will be centered at the coordinate. We can place the inter values of all the pixels into an array of our computer memory that is called as frame buffer.
- So frame buffer is used to collect and store the pixel value for the use by a display device.
There are four different types of lines:
- Thick Line
- Line Caps
- Thick Line Joints
- Pens and Brushes
1. Thick line
A line or a line segment generated by the standard DDA algorithm is of a single pixel width. Let us assume that a line with a gentle slope, that is, a slope less than one. If u need such a line segment with a thickness of three pixels, you need to put there a vertical span of three pixel for each value of x. Thus a line with any width w, can be generated just by putting a vertical span of (w/2) pixels on both the side of the central line. See below figure:
Let P1(x1, y1) and P2(x2, y2) be the end points of a line segment with width w, which is to be drawn. Here two parallel line segments will be drawn from a central line (x1, y1) and (x2, y2) at distance (w/2).
As shown in above figure, the coordinate of end points of the upper and lower line boundaries are (x1, y1 + wy)(x2, y2 + wy) and (x1, y1 – wy)(x2, y2 – wy) respectively. The value of wy is given as below.
wy= w – 1 (Sqrt(x2 – x1)2 + (y2 – y1)2) / 2 |x2 – x1|
In the above equation, w – 1 is taken instead of w. the reason being, on both sides the line boundaries are drawn which are of 1 pixel in length. Therefore, from both the sides half of the pixel width will be deducted to get the exact width w.
2. Line Caps
There is an issue with the thick line generated by the concept discussed here. When the thick line is generated it ends are the horizontal or vertical. This effect becomes even more prominent with thicker lines. To remove this effect, line caps can be used. There are 3 main such line caps used in graphics applications. They are butt cap, round cap and projecting square cap as illustrated in following figure.
- The butt cap is one with which the end position of the thick lines are adjusted in such a way that the line segment appears with a square ends. The ends of such thick line are perpendicular to the original line segment.
- Below figure shows the construct of butt cap.
- In a round cap, the upper and lower line boundaries are joined by a circular arch or with a semi-circle of diameter of width same as the width of line segment.
- Below figure shows the construct of round cap.
In projecting square cap, the portion of line segment is just extended to give a line segment an effect of square.
Below figure shows the construct of project square cap.
3. Thick Lines Joint
- When two thick line segments are connected with each other, they create problems at the joining point. When two thick line segments are joined an angel is created at the joining point, as shown in the circle of figure below, because of the thickness.
The discreetness that occurs while joining two thick lines can be removed from the polylines by adding some additional portion to the joint as some specific type of joining process. These joints are miter joint, round joint and bevel joint as shown in following figure.
- The miter joint is one in which the exterior boundaries of two thick line segments are extended upto their intersection point-the point where these two line segments meet each other, if they are extended.
- In round joint, the exterior boundaries are connected with a circular arch with a diameter of total thickness of two thick lines, which are joined.
- The bevel joint is one where butt cap is used to draw line segment and the little triangle that is created at the joint is filled with color of these two line segments.
The following figure shows the construct of above three joints.
4. Pens and Brushes
- There are many graphics applications, which make use of different pens and brushes of different shapes. Different color is also used with different shapes of pens and brushes. Some of the brush shapes are shown in following figure.
- Character almost built into the graphics display device usually as hardware but sometimes through software.
- There are two primary methods for character generation.
1. Stroke Method
We could build our own stroke method of character generation by calling the VECGEN line drawing algorithm. We could decide what line segments are needed for each character and setup the calls to the VECGEN line drawing algorithm for each character we wish to draw.
The stroke method itself changes the scale means if you want to twice a character length then in simply increase the length of each segment.
2. Dot Matrix Or Bitmap Method
It is also called as dot matrix because in this method characters are represented by an array of dots. It is a two dimensional array having columns and rows. An 5 X 7 array is commonly used to represent a character as shown in the following figure.
However 7 X 9 and 9 X 13 arrays are also used. High resolution devices such as inject printer or laser printer may use character array that are over 100 X 100.
Each dot in matrix is a pixel. The character is placed on the screen by copying the pixel values from the character array into some portion of the screen’s frame buffer.
The dot patterns for all characters are stored in the hardware device called a charactergenerator chip. The character generator chip accepts address for the character and gives a bit pattern as an output.
Aliasing and Anti-aliasing
We have seen the method bitmap which is used to draw the image. The bitmap method is a method in which an array of individual pixels is used. These pixels have some shapes and dimensions too. When a line segment of an image is enlarged, the image is looked with zaggy boundaries as shown in following figure.