Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
38 views

Algorithm

The document discusses three basic elements in geometry - scalars, vectors, and points. It describes how these elements are used to define mathematical operations and primitives like lines and points. It also outlines how coordinate reference frames are used to describe objects and scenes in 2D and 3D computer graphics. Bresenham's line algorithm is an efficient method for rasterizing lines that uses only incremental integer calculations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
38 views

Algorithm

The document discusses three basic elements in geometry - scalars, vectors, and points. It describes how these elements are used to define mathematical operations and primitives like lines and points. It also outlines how coordinate reference frames are used to describe objects and scenes in 2D and 3D computer graphics. Bresenham's line algorithm is an efficient method for rasterizing lines that uses only incremental integer calculations.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 22

Basic Elements

Three basic elements


– Scalars
– Vectors
– Points
• Develop mathematical operations among them
• Define basic primitives:
– Points
– Line segments
Basic Elements

• Points are associated with locations in space


• Vectors have magnitude and direction
– represent displacements between points, or directions
• Points, vectors, and operators that combine them are the
common tools for solving many geometric problems that
arise in
– Geometric Modeling,
– Computer Graphics,
– Animation,
– Visualization, and
– Computational Geometry.
3.1 COORDINATE REFERENCE FRAMES
To describe a picture, we first decide upon

• A convenient Cartesian coordinate system, called the world-coordinate


reference frame, which could be either 2D or 3D.

• We then describe the objects in our picture by giving their geometric


specifications in terms of positions in world coordinates.
– e.g., we define a straight-line segment with two endpoint positions,
and a polygon is specified with a set of positions for its vertices.
– These coordinate positions are stored in the scene description along
with other info about the objects, such as their color and their
coordinate extents
• coordinate extents are the minimum and maximum x, y, and z values for
each object.
• A set of coordinate extents is also described as a bounding box for an
object.
– For a 2D figure, the coordinate extents are sometimes called its
bounding rectangle.
3.1 COORDINATE REFERENCE FRAMES

• Objects are then displayed by passing the scene


description to the viewing routines
• which identify visible surfaces and map the objects to the
frame buffer positions and then on the video monitor.
• The scan-conversion algorithm stores info about the scene,
such as color values, at the appropriate locations in the
frame buffer, and then the scene is displayed on the output
device.
• locations on a video monitor
• are referenced in integer screen coordinates, which
correspond to the integer pixel positions in the frame buffer.
3.1 COORDINATE REFERENCE FRAMES

• Scan-line algorithms for the graphics primitives use the coordinate


descriptions to determine the locations of pixels
– E.g., given the endpoint coordinates for a line segment, a display
algorithm must calculate the positions for those pixels that lie
along the line path between the endpoints.
• Since a pixel position occupies a finite area of the screen
– the finite size of a pixel must be taken into account by the
implementation algorithms.
– for the present, we assume that each integer screen position
references the centre of a pixel area.
3.1 COORDINATE REFERENCE FRAMES

• Once pixel positions have been identified the color values must be
stored in the frame buffer
• Assume we have available a low-level procedure of the form

setPixel (x, y);


stores the current color setting into the frame buffer at integer position
(x, y), relative to the position of the screen-coordinate origin

getPixel (x, y, color);


retrieves the current frame-buffer setting for a pixel location;
• parameter color receives an integer value corresponding to the
combined RGB bit codes stored for the specified pixel at position (x,y).
• additional screen-coordinate information is needed for 3D scenes. For
a two-dimensional scene, all depth values are 0.
3.1 Absolute and Relative Coordinate
Specifications

• So far, the coordinate references discussed are


given as absolute coordinate values
– values are actual positions wrt origin of current
coordinate system
• some graphics packages also allow positions to
be specified using relative coordinates
– as an offset from the last position that was
referenced (called the current position)
3-5 LINE-DRAWING ALGORITHMS

A straight-line segment in a scene is defined by the


coordinate positions for the endpoints of the segment.
1. To display the line on a raster monitor, the graphics
system must
– first project the endpoints to integer screen coordinates and
– determine the nearest pixel positions along the line path
between the two endpoints.
2. Then the line color is loaded into the frame buffer at the
corresponding pixel coordinates.
3. Reading from the frame buffer, the video controller
plots the screen pixels.
– This process digitizes the line into a set of discrete integer
positions that, in general, only approximates the actual line
path.
3-5 LINE-DRAWING ALGORITHMS

• On raster systems, lines are plotted with pixels, and step


sizes in the horizontal and vertical directions are
constrained by pixel separations.

• That is, we must "sample" a line at discrete positions and


determine the nearest pixel to the line at sampled
position.
– Sampling is measuring the values of the function at equal
intervals

• Idea: A line is sampled at unit intervals in one


coordinate and the corresponding integer values nearest
the line path are determined for the other coordinate.
Towards the Ideal Line
• We can only do a discrete approximation

• Illuminate pixels as close to the true path as


possible, consider bi-level display only
– Pixels are either lit or not lit
• In the raster line alg.,
– we sample at unit intervals and
– determine the closest pixel position to the specified
line path at each step
What is an ideal line
• Must appear straight and continuous
– Only possible with axis-aligned and 45o lines
• Must interpolate both defining end points
• Must have uniform density and intensity
– Consistent within a line and over all lines
– What about anti-aliasing ?
• Aliasing is the jagged edges on curves and diagonal lines in a
bitmap image.
• Anti-aliasing is the process of smoothing out those jaggies.
– Graphics software programs have options for anti-aliasing text and
graphics.
– Enlarging a bitmap image accentuates the effect of aliasing.

• Must be efficient, drawn quickly


– Lots of them are required
Simple Line

The Cartesian slope-intercept


equation for a straight line is :
y = mx + b
with m as the slope of the line
and b as the y intercept.
Simple approach:
• increment x, solve for y
Line-Drawing Algorithms:

DDA

Bresenham’s Midpoint
Algorithm
Algorithms for displaying lines are based on the Cartesian
slope-intercept equation
y = m.x + b
where m and b can be calculated from the line endpoints:
m = (y1-y0) / (x1-x0)
b = y0 - m. x0

For any x interval x along a line the corresponding y interval


y = m.x

y1

y0

x0 x1
Simple Line

Based on slope-intercept
algorithm from algebra:
y = mx + b
Simple approach:
increment x, solve for y
Floating point arithmetic
required
Does it Work?

It works for lines with a slope of


1 or less,
but doesn’t work well for lines
with slope greater than 1 – lines
become more discontinuous in
appearance and we must add
more than 1 pixel per column to
make it work.
Solution? - use symmetry.
Modify algorithm per octant

OR, increment along x-axis if dy<dx else increment along


y-axis
DDA Algorithm

• The digital differential analyser (DDA) is a scan-conversion line


algorithm based on using x or y.

• A line is sampled at unit intervals in one coordinate and the


corresponding integer values nearest the line path are determined for
the other coordinate.
Bresenham's line algorithm

• Accurate and efficient


• Uses only incremental integer calculations

The method is described for a line segment with a


positive slope less than one
The method generalizes to line segments of other slopes
by considering the symmetry between the various
octants and quadrants of the xy plane
Bresenham's line algorithm

• Decide what is
the next pixel
13 Specified position
line path
– (11,11) or
12
(11,12)
11

10

10 11 12 13
Illustrating Bresenham’s Approach

• For the pixel position


xk+1=xk+1, which one
yk+3 we should choose:
yk+2
• (xk+1,yk) or (xk+1, yk+1)
y=mx+b

yk+1

yk

xk xk+1 xk+2 xk+3


Bresenham’s Approach

• y=m(xk + 1)+b
yk+1
dupper
y
• dlower=y-yk
dlower =m(xk + 1)+b-yk
yk

• dupper=(yk+1)-y
xk+1 = yk+1 -m(xk + 1)-b
• dlower- dupper= 2m(xk + 1)+2yk+2b-1
• Rearrange it to have integer calculations:
m=Δy/Δx
Decision parameter: pk= Δx(dlower- dupper)=2Δy.xk - 2Δx. yk + c

You might also like