Вы находитесь на странице: 1из 14

Chapter 3 Principles of Computer graphics

INTRODUCTION
Traditionally drawings are prepared on plane drawing sheets This
has several limitations. The sketches have to be made only in two
dimensions. Though the depth can be represented by pictorial
projections like isometric and perspective projections, the
projections have to be necessarily reduced to two dimensions.
Use of computer graphics has opened up tremendous
possibilities for the designer. Some of them are listed below:

Chapter 3 Principles of Computer graphics


The object is represented by its geometric model in three dimensions (X, Y and Z).
The mathematical representation reduces creation of views like orthographic,
isometric, axonometric or perspective projections into simple viewing
transformations.
Though the size of the screen is limited, there is no need to scale the drawings.
Drawings can be made very accurate.
The geometric models can be represented in color and can be viewed from any
angle.
Sections can be automatically created.
The associatively ensures that any change made in one of the related views will
automatically reflect in other views.
Revision and revision control are easy.
Drawings (geometric models) can be modified easily.
More important than all, drawings can be reused conveniently.
Storage and retrieval of drawings are easy.

Chapter 3 Principles of Computer graphics


Modern computer graphics displays are simple in construction. They
consist of basically three components.
i. Monitor
ii. Digital Memory or Frame Buffer
iii. Display Controller
Most of the computer graphics displays use raster CRT which is a
matrix of discrete cells each of which can be made bright. A graphic
entity like line or circle is represented as a series of points or dots
on the screen. Therefore, it is called as a point plotting device.

Chapter 3 Principles of Computer graphics


The video display screen is divided into very small rectangular
elements called a picture element or pixel. This happens to be the
smallest addressable screen element. Graphic images are formed by
setting suitable intensity and color to the pixels which compose the
image. Depending upon the resolution screens may have varying
number of pixels. For example, an SVGA monitor with a resolution
of 1024 x 768 will have 1024 pixels in every row (X - direction) and
768 pixels in every column (Y-direction). Monitors of larger size
will have resolution of 1024 x 1024 or more. A raster scan system
displays the image on a CRT in a certain fixed sequence

3.2 GRAPHIC PRIMITIVES


A drawing is created by an assembly of points, lines, arcs, circles.
For example, drawing shown in Fig 3.1 consists of several entities.
In computer graphics also drawings are created
in a similar manner. Each of these is called an entity. The drawing
entities that a user may find in a typical CAD package include :
point
line
constructi
on line,
multi-line,
polyline
circle
spline
arc
ellipse
polygon
rectangle

3.2 GRAPHIC PRIMITIVES

3.2 GRAPHIC PRIMITIVES


3.3 POINT PLOTTING
The frame buffer display is an example of a point plotting device. The smallest unit
accepted by such displays is a single pixel. To construct a useful picture on a point
plotting device, a picture must be built out of several hundreds of pixels.
3.4 DRAWING OF LINES
Straight line segments are used a great deal in computer generated pictures. The
following
criteria have been stipulated for line drawing displays :
i. Lines should appear straight
ii. Lines should terminate accurately
iii. Lines should have constant density
iv. Line density should be independent of length and angle
v. Line should be drawn rapidly
The process of turning on the pixels for a line segment is called vector generation. If
the end points of the line segment are known, there are several schemes for selecting
the pixels between the end pixels. One method of generating a line segment is a
symmetrical digital differential analyzer (DDA).

3.2 GRAPHIC PRIMITIVES


3.4.1 DDA ALGORITHM
The digital differential analyzer generates lines from their differential equations.
The DDA works on the principle that X and Y are simultaneously incremented by
small steps proportional to the first derivatives of X and Y. In the case of a
straight line the first derivatives are constant and are proportional to DX and DY,
where D is a small quantity.
The symmetrical DDA generates reasonably accurate lines since a
displayed pixel is
never away from a true line by half the pixel unit. A Pascal
procedure for a simple DDA is given below :

3.2 GRAPHIC PRIMITIVES


Procedure DDA (X1, Y1, X2, Y2 : integer) ;
length : var ;
i : integer;
X, Y, X-incr, Y-incr : real ;
begin
length : = abs (X2 X1) ;
if abs (Y2Y1) < length then length: = abs (Y2Y1);
X - incr : = (X2 X1) /length ;
Y - incr : = (Y2 Y1) /length ;
X : = X1 + 0.5 ; Y = Y1 + 0.5 ;
for i : = 1 to length do
begin
plot (trunc (X) ; trunc(Y) ;
X : = X + X - incr ;
Y : = Y + Y - incr ;
end;
end

3.2 GRAPHIC PRIMITIVES


EXAMPLE
To draw a straight line from connecting two points (2, 7) and (15,
10)
X1 = 2, X2 = 15 abs(X2 X1) = 13
Y1 = 7, Y2 = 10 abs(Y2 Y1) = 3
Length = 13
X incr = X2X1 13 1
Length 13
==
Y incr = Y2Y1 3 0.23
Length 13
==
Initial values of X and Y are
X = 2.5 Y = 7.5
The X and Y are tabulated in Table 3.1 and Fig. 3.2 shows a plot
of the line.

3.2 GRAPHIC PRIMITIVES

3.2 GRAPHIC PRIMITIVES

3.2 GRAPHIC PRIMITIVES


01 /* Program create in Linux O S
02 * cadcam haui
03 */
04
05 # include < graphics.h>
06 # defi
ne Round(a) (int)(a+ 0.5) // lam tron so
07 # defi
ne D ELAY 10
08 int color = RED ;
09
10 void lineD D A(int x1, int y1, int x2, int y2){ // thuat toan D D A
11 int x_unit = 1, D x = x2 - x1, D y = y2 - y1; // Khoitao cac gia triban dau
12 int x = x1;
13 fl
oat y = y1;
14 fl
oat m = (fl
oat)D y/D x; // he so goc m
15 putpixel(x, Round(y), color);
16
17 w hile(x < x2){
18 delay(10); // thoigian tre khive 1 diem anh
19 x + = x_unit;
20 y + = m ;
21 putpixel(x,Round(y), color);
22 }
23 }
24 int m ain(){
25 int gd,gm = VG AM AX; gd= D ETECT;
26 initgraph(& gd,& gm ,N U LL); // khoitao cua so do hoa
27 setbkcolor(W H ITE);
28 lineD D A(50,150, 300, 200); // ve duong thang
29 getchar();
30 return 0;
31 }

3.2 GRAPHIC PRIMITIVES


3.4.3 DRAWING OF CIRCLES
Circle is another important entity like line. Several circle drawing algorithms have been
described in literature. A simple procedure for drawing a circle is described in this
section.
This procedure calculates points on the circle centred about the origin and then adds
co-ordinates of the centre (X ,Y ) to the X and Y values respectively.
program mcircle;
var xc, yc, radius : integer;
($I GRAPH.P)
Procedure dcircle
(xc, yc,
radius: integer) ;
var
dtheta,
cdtheta, sdtheta,
x, y,
xtemp: real ;
z: integer ;