Elsevier

Computers & Graphics

Volume 30, Issue 2, April 2006, Pages 207-212
Computers & Graphics

Technical section
Drawing lines by uniform packing

https://doi.org/10.1016/j.cag.2006.01.026Get rights and content

Abstract

In this paper, we introduce a new approach to line drawing that attempts to maintain a uniform packing density of horizontal segments to diagonal segments throughout the line. While the conventional line drawing algorithms perform linear time computations to find the location of the pixels, our algorithm takes logarithmic time. Also, experimental results show that the quality of line is acceptable and comparable to the well-known Bresenham's line-drawing algorithm.

Introduction

Line is a very important primitive in computer graphics. Sometimes designs contain hundreds of lines that are to be refreshed or redrawn in a fraction of a second. This is why it is so important to draw these lines as efficiently as possible. This importance warranted development of a number of line algorithms. The first such algorithm was devised by Bresenham [1], [2] that avoided real numbers and division operations in computation for fast generation of line segments. Later on, Kappel [3] developed midpoint algorithm for drawing line segments. Parallel methods for generating lines have been discussed in Pang [4] and Wright [5]. In addition, a recursive bisection method was also developed in order to reduce computational complexity. But quality of line produced by this algorithm was inferior. This paper presents a new line-drawing algorithm for graphics systems based on the idea of uniform packing. Analysis shows that it is computationally more efficient than commonly used Bresenham's line drawing algorithm. The trade-off here is the slight degradation of the quality of lines drawn, measured in terms of quantitative measures such as the sum of squared errors of the plotted pixels, with respect to the mathematical line. Experimental results suggest that the sum of squared errors for our algorithm is quite comparable to that for Bresenham's algorithm, which produces probably minimum sum of squared errors.

Section snippets

Bresenham's algorithm

Bresenham developed an elegant line drawing algorithm in Ref. [1]. His algorithm uses only integer arithmetic and allows incremental calculations for finding next pixel coordinates. For lines with arbitrary real valued endpoint coordinates, a floating point version of the same algorithm can be adopted. Furthermore, Bresenham's incremental technique can be applied to integer computation of circles as well.

Pitteway [6] proposed a slightly different formulation of Bresenham's algorithm. This

New algorithm

If two consecutive pixels are put along the same horizontal line 1 unit apart, we define it to be a horizontal move. Similarly when two consecutive pixels are put along the diagonal of a unit square, we define it to be a diagonal move. Any straight line drawn on a computer display is a sequence of these two types of segments. The algorithm presented here depends on the idea of packing horizontal and diagonal moves uniformly.

We have considered only lines with slope from 0 to 1. The algorithm can

Time complexity analysis

To determine the number of iterations of the loop at line 3, we compare our algorithm with Euclid's algorithm for finding greatest common divisor(gcd). The recurrence for finding gcd of two numbers a and b where ab is gcd(a,b)=gcd(b,a mod b).

It is known (see pp. 852–853 in Ref. [10]) that number of iterations to find the gcd using this recurrence is O(log b). In our algorithm, we have used the following recurrence to obtain our iterative implementation: line(h,d)=line(h – d mod h, d mod h).

Experimental results

Much of our experiments are dedicated to the comparison of our algorithm to the widely used Bresenham's algorithm both in terms of efficiency and quality of rendered lines.

Conclusion

We have introduced a new approach for line drawing that attempts to maintain a uniform packing density of horizontal segments and diagonal segments throughout the line. Experimental results show that the quality of lines drawn is comparable to the ones drawn by Bresenham's algorithm. Also, the computational effort in making decision as to the location of the pixels is logarithmic in number of segments in the line, rather than linear as in Bresenham's algorithm. However, the memory requirement

References (10)

  • J.E. Bresenham

    Algorithm for computer control of a digital plotter

    IBM Systems Journal

    (1965)
  • J.E. Bresenham

    A Linear algorithm for incremental digital display of circular arcs

    CACM

    (1977)
  • Kappel M.R. An ellipse-drawing algorithm for faster displays. in: Fundamental algorithms for computer graphics,...
  • A.T. Pang

    Line-drawing algorithms for parallel machines

    IEEE Computer Graphics and Applications

    (1990)
  • W.E. Wright

    Parallelization of bresenham's line and circle algorithms

    IEEE Computer Graphics and Applications

    (1990)
There are more references available in the full text version of this article.

Cited by (6)

View full text