0% found this document useful (0 votes)
8 views

Complex Objects, Such As Trees and Terrain or Furniture and Wals, Positioned at

Uploaded by

abdulanish20004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Complex Objects, Such As Trees and Terrain or Furniture and Wals, Positioned at

Uploaded by

abdulanish20004
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

A picture can be described in several ways.

Assuming we have a raster dis-


play, a picture is completely specified by the set of intensities for the pixel
positions in the display. At the other extremne, we can describe a picture as a set
complex objects, such as trees and terrain or furniture and wals, positioned at
specified coordinate locationswithin the scene. Shapes and colors of the objects
can be described internally with pixel arrays or with sets of basic geometric str
tures, such as straight line segments and polygon color areas. The scene is then
displayed either by loading the pixel arrays into the frame buffer or by scan con
verting the basic geometric-structure specifications into pixel patterns. Typically,
graphics programming packages provide functions to describe a scene in terms
of these basic geometric structures, referred to as output primitives, and to
group sets of output primitives into more complex structures. Each output primi
tive is specified with input coordinate data and other information about the way
that object is to be displayed. Points and straight line segments are the simplest
geometriccomponents of pictures. Additional output primitives that can be used
to construct a picture include circles and other conic sections, quadric surfaces,
spline curves and surfaces, polygon color areas, and character strings. We begin
device-level algo
our discussion of picture-generation procedures by examining particular
rithms for displaying two-dimensional output primitives, with empha
chapter, we
sis on scan-conversion methods for raster graphics systems. In this
also consider how output functions can be provided in graphics packages, and
language.
wetake a look at the output functions available in the PHIGS

3-1
POINTS AND LINES
fur
Point plotting is accomplished by converting a single coordinate position
nished by an application program into appropriate operations for the output de.
the electron beam is turned on to i
vice in 115e. With aCRT monitor, for example,
ie
luminate the screen phosphor at the selected location. How the electron beam
random-scan (vector) svste
positioned depends on the display technology. Ali_t,
stores point-plotting instructions in the display and coordinate valves
these instructions are converted to deflection voltages that position the electron
beam at the screen locations to be plotted during each refresh cycle. For a blacl
and-white raster system, on the other hand, a point is plotted by setting the bit
value corresponding to a specified screen position within the frame bufer to 1
Then, as the electron beam sweeps across each horizontal scan line, it emit
burst of elevtrons plots a
rame bufter. With an RGBpoint) whenever a value of 1is encountered in the Section -1
ns for the intensities that system, the frame buffer is loaded with the color Points and iines
are to be displayed at the
Line drawing is
accomplished by calculating screen pixel positions.
the line path between two
specified endpoint internmediate
positions. An outputpositions along
diected fill in these positions between the
to device is then
as a vector pen plotter or a endpoints. For analog devices, such
random-scan
smoothly from one endpoint to the other. Linearlydisplay, a straight line can be drawn
varying horizontal and verti
cal deflection voltages are
generated that are
changes in the x and ydirections to produce the proportional to the required
Digital devices display a straight line segmentsmooth line.
between the two endpoints. Discrete coordinate positions by plotting discrete points
cakulated from the equation of the line. For a raster videoalong the line path are
display, the line color
(intensity) is then loaded into the frame buffer at the corresponding pixel coordi
nates. Reading from the frame buffer, the video controller then
"plots"
pixels. Screen locations are referenced with integer values, so plotted the screen
may only approximate actual line positions between two specified positions
endpoints.
computed line position of (10.48, 20.51), for example, would be converted to pixelA
position (10, 21). This rounding of coordinate values to integers causes lines to be
displayed with a stairstep appearance ("the jaggies"), as represented in Fig 3-1.
The characteristic stairstep shape of raster lines is particularly noticeable on sys
terns with low resolution, and we can improve their appearance somewhat by
displaying them on high-resolution systems. More effective techniques for
smoothing raster lines are based on adjusting pixel intensities along the line
paths.
For the raster-graphics device-level algorithms discussed in this chapter, ob
ject positions are specified directly in integer device coordinates. For the time
being, we will assume that pixel positions are referenced according to scan-line
number and column number (pixel position across a scan line). This addressing
scheme is illustrated in Fig. 3-2. Scan lines are numbered consecutively from o
starting at the bottom of the screen; and pixel columns are numbered from 0.le#
to right across each scan line. In Section 3-10, we consider alternative pixel ad
dressing schemes.
To load a specified color into the frame buffer at a position
corresponding
to column ralong scan line y, we will assume we have available a low-level nr
cedure of the form

setPixel (*, y)

Figure 3-1
Stairstep effect (jaggies) produced
when a line is generated as a series
of pixel positions.
Scan
Line
Number

Figure 3-2
0 1 2 3 4 5 Pixel Column Pixel positions referenced by scan
Number line number and column number.

We sometimes will also want to be able to retrieve the current frame-buffer


intensity setting for aspecified location. We accomplish this with the low-level
function

getPixel (x, y)

3-2
LINE-DRAWING ALGORITHMS

The Cartesian slope-intercept equation for a straight line is


y= m x+b
(3-1)
with mrepresenting the slope of the line and b as the y
two endpoints of a line segment are specihed at intercept. Given that the
on in Fig. 3-3, we can determine positions (x, y) and (x,, y»), as
the following calculations:
values tor the slope m and y intercept b with

m= 2 y
(3-2)
b=y1- m
x1
(3-3)
Algorithms for displaying straight lines
the calculations given in Eqs. 3-2 and 3-3. are based on the line
For any given xinterval Ar along a equation 3-1 and
y interval Ay from Eq. 3-2 as line, we can
compute the
een endpoint Ay = m Ax corresponding
) and (z, yal. Similarly, we can obtain the xinterval Ax (3-4)

corresponding to
Ar = y
a
specified Ay as
These equations form the basis for (3-5)
determining deflection voltages in
analog de
ViKes. For lines with
small slope magnitudes
then set horizontal delection vollage and m<1, Ar can be set proportional to a Section 3-2

have proportional Ay as
to the
corresponding vertical deflection is Line DrawIg AigIithes
magnitudes |m
tion voltage with the 1, Ay can calculated from Eq. 3-4. For lines whose slopes
be set Proportional to asmall vertical deflec-
tional t Av corresponding horizontal
calculated from Eq. 3-5/For lines withdeflection
zontal and vertical voltage set prophori-
skope mis generated deflections m= 1, Ar = Ay and the
voltages are equa). In each case, a smooth line with
On raster between
systenms,
the
lines arespecified endýoints.
zontal and
vertical plotted with pixels, and step sizes in the hori-
must "sample" alinedirections are
constrained by pixel separations. That is, we
line at each sampled at discrete positions and determine the nearest pixel to the
lustrated in Fig. 34,position. This scan-conversion process for
for a near horizontal line with discrete straight ines i5 1
along the xaxis. sample positions
DDA Algorithm
The digital differential analyzer (DDA) is a
calculat1ng either Ay or ArAsing Eq. 3-4 scan-conversion
or Eq. 3-5. We
line algorithm based on Figure 3-4
sample the line at unit in- Straight line segment with
tervals in one coordinate ánd determine
line path for the other coordinate. corresponding integer values nearest the fivesampling positions alon
the r axis between z and I
Consider first a Jine with positive slope,jas shown in Fig, 3-3.Ifthe slope is
less than or equal to 1)we sample at unit *ntervals (Ax = 1) ànd compute each
successive yvalue as

= yk t m (3-6)

Subscriptk takes integer values starting from 1, for the first point, and increases
by 1 until the final endpoint is reached Since mcan be any real number between
0and Tyfhe calculated y values mustbe rounded to the nearest integer.
Fgt lines with apositive slope greater than 1,we reverse the roles of x and
y. That is, we sample at unit y intervals (Ay = 1) and calculate each succeeding r
value as

(3-7)
The abeve e,ns a
Equations 3-6 and 3-7 are based on the assumption that lines are to be
processed frÍm the left endpoint to the right endpoint (Fig. 3-3). Ifthis processing Jty9
is reversed, so that the starting endpoint is at the right, then either we have
Ar = -1and
Yk+1y m (3-S)
have Ay =-1 with
or (when the slope is greater than 1)we
1 1 39)
Ishe abeve eons
Euations 3-6 through 3-9 can also be used to calculate pixel positions aloms
absolute value of the slope is less than iand
aline with negative slope. If the set
is at the left, we
Ar = 1 and calculate y values
start endpoint withjEq. 3-6.
Chapter 3 we set r=-1 and
the same slope),
When the start endpoint is at the right (forwhen
Primitives obtain the absolute value of a
negative
Eg. 3-8. Similarly,
POShonsfrom
= -l and Ea. 3-9 or we use Ay = 1'and q. 3-7.
T5eater than 1, we use Ay following procedure, which accepts as
This algorithm is summarizedintheHorizontal and vertical differences be
t e two endpoint pixel positions. and dy. The differ
ne endpoint positions are assigned to parameters dx steps. Start
e ith the greater magniude determines the value of paramneter
8With pixel position (r.. u). we determine the offset needed at each step to
eiterate the next pixel position along the line path. We loop through thus process
steps times. If the magnitude of dxis greater than the magnitude of dy and xa
osnan xb, the values of the increments in the xand y directions are Iand m,
respectively. If the greater change is in the x direction, but xa is greater than xb,
then the decrements -1and -n are used to generate each new point on the line.
OnerwiSe, we usea unit increment (or decrement) in the y direction and an x in
crement (or decrement)of 1/m.

#include "device.h"
#define ROUND(a) ((int) (a+0.5))
void lineDDA (int xa, int ya, int xb, int
yb)
int dx = xb - xa, dy = yb - ya,
float xIncrement, steps, k;
y(nCrement, x = xa, y = ya;
if (abs (dx) > abs (dy))
steps = abs (dx);
else steps = abs (dy);
xIncrement = dx / (float) steps;
yIncrement = dy / (float ) steps;
setPixel (ROUND (x) , ROUND (y) );
for (k=0; k<steps; k++) {
X += xIncrement;
y += yIncrement;
set Pixel (ROUIND(:X), ROUND (Y))

The DDA algorith is a faster


the direct use of Eq. 3-1/ It
eliminates method for calculating pixel
of raster characteristics, so that
the
multiplication positions than
in Eq. 3-1 by
direction to step to pixel positionsappropriate increments are
along the line path. The making use
applied in the x or y
roundoff error in successive
additions the
of
can cause the calculated pixel positions to drift
floating-point accumulation
away from theincrement,
true line however,
of
long line segmernts.
Furthermore, the
arithmetic in procedure lineDD are rOunding
still operations, and path for
performance of the DDA algorithm by
time-consuming floating-point
integer and fractional parts so that all separating the
We can
innprove
tions. A method for calculating 1/m calculations areincrementsto and 1/m into
m
the
in reduced integer opera
tai
dures that can be applied to both lines
increment
Section 3-11. In the following sections, we s integer steps is discussed in
consider more
and curves. general

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy