Line rasterization algorithms that satisfy the subset line property

  • Published on

  • View

  • Download

Embed Size (px)



    Line Rasterization Algorithms That Satisfy the Subset Line Property*


    Department of Mathematics and Computing Science, Eidhoven University of Technology, P. 0. Box 513, 5600 MB Eindhoven, The Netherlands

    Received October 10.1986

    In this paper two subset line properties are introduced; the difference concerns the domain of the end points of the line segments under consideration, viz. Q* and Z* respectively. For both properties, a recursive and a nonrecursive algorithm to generate raster line segments are derived. All algorithms use integer arithmetic only. The accuracy of the algorithms in representing lines will be discussed, as well as their time complexity. 0 1988 Academic PXSS, IX


    In raster graphics, where pictures consist of discrete elements (calkd pixels), objects in so-called world space have to be converted into rasterized analogs in screen space. In this paper we deal with the conversion of line segments into pixel sets representing these segments.

    A well-known algorithm for rasterizing line segments is that of Bresenham II]. Some of the properties of lines do not hold for their raster&d analogs. For instance, in R* two different nonparallel lines have exactly one point in common, whereas their rasterizations may have none, one, or more than one pixel in common. Also, in R* exactly one line exists through two given points, whereas two d&rent pixels may be elements of various raster&d lines.

    Another property that holds for line segments in R* is the subset line property, which may be formulated as follows. G iven a line segment L( p, q), where its end points p and q are points in R*, then

    (Ar,s E R: r,s E L(p,q): L(V) c L(p,q)).

    (A is used to denote the universal quarttiGer; (Ad E D: R(d): P(d)) means that for all d in domain D that satisfy restriction R(d), predicate P(d) holds. In the same way E denotes the existential quarttier.)

    The subset line property is of importance for operations such as clipping and hidden line elimination.

    Suppose we have a rasterization algorithm A that raster&s the line segment L( p, q) for any p and q in Z*. We will denote the resulting set of pixels, which is a subset of Z*, as A( p,q). In [2], the following analog of the subset line property for rasterized lines is given.

    *The investigations were partly supported by the Netherlands Technology Foundation (SW). 210

    0734-189X/88 $3.00 Copyright 0 1988 by Academic Press, Inc. All rights of reproduction in any form reserved.


    -- 0 4 8 12 16

    FIG. 1. The Bresenham rasterization of the line segment connecting (0,O) and (16,5), indicated by 0, and of the segment connecting (8,2) and (14,4), indicated by 0.

    DEFINITION (of SPl). Rasterization algorithm A satisfies subset line property SPl if

    @P, 4, r, s E 2*: r, s E A(p, q): A(r, s) c A(p, q)).

    This property is applicable in situations where computations for updating the screen are performed in screen space. For example, if one wants to erase parts of rasterized line segments by overpainting the parts in question with the background color, one needs a rasterization algorithm that satisfies the above property.

    However, if the computations to update the screen are performed in world space, the above definition of SPl is of little use. For example, in programs, the intersec- tion point r of Up,, ql) ami Up2, q2), where pl, ql, p2, ad q2 E z*, is, in general, not an element of 2 *. Indeed, since Q is closed under all operations necessary to compute the intersection point of two line segments with end points in Q*, one would like to have a rasteriz.ation algorithm that allows elements of Q* as end points. We therefore arrive at the following definition.

    DEFINITION (of SP2). Algorithm A satisfies subset line property SP2 if

    (AP, 4, r, s E Q*: r, s E L( P, 4): A(r, s) C A( P, 4)).

    The Bresenham algorithm does not satisfy SPl; in Fig. 1, for example, two Bresenham rasterizations are shown: the first one of the line segment correcting (0,O) and (16,5), the second one of the line segment connecting (8,2) and (14,4). Although (8,2) and (14,4) are elements of the first rasterization, the second raster-ix&on is not a subset of the first one.

    An extended Bresenham algorithm that converts end points in Q* to the nearest elements of Z2 and then applies the original algorithm, does not satisfy SP2, as is illustrated by the line segments of Fig. 1 and r = (8, $) and s = (14, !$), which are converted to (8,2) and (14,4), respectively.

    Notions. Throughout this paper, elements of Q* are referred to as points. If p is a point and p = (x, y), then p.x = x and p.y = y. div b stands for integer division by b, defined by a = b*(adivb)+amodb,forallaEZ,where amod b E {O,l,. . . , b - l}. For denoting intervals we use [a, b] for the interval in R between (and including) u and b, and [a - - - b] for the interval in Z. Parentheses are used for denoting open intervals.

    We consider the screen to have size N, where N = 2, and n E N. N is supposed to contain 0. Furthermore, we consider lines with slopes between 0 and 1 only.


    A line rasterization algorithm A is said to have a deviation of at most i pixels, if for all points p and q E 2 holds that

    (As, s: s E A(p, q) A s E L( p, q) A s.x = s.x: 1d.y - s.yl I i).

    In other words, A has a deviation of at most i pixels if the vertical distance of all points s E A( p, q) to L( p, q) is at most i pixels. The Bresenham algorithm has a deviation of at most $ [3]. Furthermore, a line rasterization algorithm A is said to be translation invariant if for all points p, q, and I E Z2 holds that

    A(p + t, q + t> = A(P, 4) @ t,

    where the operator d is defined by

    S@?= {s+tlsES},

    for all S E Z* and t E Z*. Translation invariance implies that the rasterization depends on the relative

    positions of the end points only (the differences in the X- and y-coordinates), not on the absolute positions. In [2], Franklin suggests that no translation invariant algorithm exists that satisfies SPl and has a deviation of at most :. The algorithms presented in this paper satisfying SPl are translation invariant in the ~-direction only, i.e., A( p + ev, q + e,,) = A( p, q) CB e,,, where eu = (0,l).

    Besides presenting algorithms that satisfy SPl or SP2, and use integer arithmetic only, we want to distinguish between recursive and nonrecursive algorithms. Since recursive algorithms are attractive when parallelism is considered, this latter distinc- tion may be important for hardware implementations.

    In Section 2 algorithms satisfying property SPl are presented: from the recursive algorithm given in Section 2.1, a nonrecursive algorithm is derived in Section 2.2. The algorithms satisfying property SP2 are presented in Section 3: the nonrecursive one in 3.1, the recursive one in 3.2. Finally, in Section 4 the accuracy and time complexity of the algorithms presented in this paper are discussed.


    In this section all points are supposed to be elements of Z2. The algorithms presented in this section are based on the recursive definition of raster line segments with end points (0,O) and (N, 6), where 6 E N and 6 I N. This d&n&ion is then extended to raster line segments with end points (0, ry) and (N, 6 + ty), where ty E Z. These raster segments are called BEFLINES, and are used to define the raster line segment with end points p, q E Z2, where 0 5 p.x 5 q.x s N and 0 I q.y - p.y I q.x - p-x: it is the part between p and q of a REFLINE contain- ing both p and q. More formally, the raster line segment with end points p and q is the intersection of a REFLINE containing p and q, and [p.x . . . q.x] x N. Before this defunition is given, we prove that for all points p and q a BEFLINE exists that contains both p and q, and that for two d&rent REFLINES that both contain p and q, the intersection with [ p.x . . . q.x] X Z is the same. Any algorithm gener- ating such a segment for any n E N, p, q E Z2, will satisfy SPl.


    FIG. 2. The rasterization of the line segment connecting (0,O) and (2, 6) is the union of the rasterizations of the line segment connecting (0,O) and m = (2-l, 6 div2) and the line segment connecting m and (2, 6).

    The raster line segment with end points (0,O) and (N, 6) will be defined by prescribing the y-value as a function of x, where x E [0 . . . N]. Hence, the set of pixels constituting this raster line segment contains N + 1 points. The definition of this function is inspired by the following property of line segments in R:

    (Ap, q, m E R: m E L(p, 4): L(P, q) = L(P, m ) U L(m, 4)).

    Similarly, we consider a raster line segment as a concatenation of two smaller segments, one with end points (0,O) and a well-chosen point m E Z*, the other one with end points m and (ZV, 6). Here, m is delined to have x-coordinate Ndiv 2 and y-coordinate 6 div2, thus approximating the m idpoint of the line segment connect- ing (0,O) and (iV, 8). See Fig. 2. Consequently, the function prescribing the y-values for the original segment will be expressed in terms of the functions prescribing the y-values for the two constituting segments. Since, at this point, only raster segments are considered with one end point in the origin and the other one at x = 2k, we have to translate the segment with end points m = (Ndiv2,S div 2) and (ZV, S) over the vector - m .

    In the following definition, L(n, 6) stands for the raster line segment with end points (0,O) and (2n, 8).

    DEFINITION (of L and Y). For n, 6 E N, with 6 _< 2*, the set L(n, S) c Z* is defined by

    ~(n, 8) := {(x,Y(n, 6; x))Ix E N A x zz 2},

    where the integer function Y is defined by

    0 ifx=O Y(n - 1, Sdiv2; x) if n > 0 A 0 < x 5 2-

    Y(n, 6; x) := Y(n - 1,s - 6 div2; x - 29 + sdiv2 if n > 0 A 2- < x < 2

    6 if x = 2.

    As an example L(4,6) is shown in Fig. 3.

    By mathematical induction on n, the following properties of Y can be proven. Here, n, S, and x are considered to be elements of N, and 6 I 2, x I 2.


    0 4 8 12 16

    FIG. 3. The line segment connecting (0,O) and (16,6), and its rasterization L(4,6).


    l for 6 = 0, the y-value of any point equals 0:

    Y(n,O; x) = 0 (2-l)

    l for S = 2, the y-value of any point equals its x-value:

    Y(n,2; x) = x (2.2)

    l Y is nondecreasing in x and increases with steps of at most 1:

    Y(n, 8; x) - Y(n, 8; x - 1) E {OJ}, where x > 0 (2.3)

    l Y is nondecreasing in 6 and increases with steps of at most 1:

    Y(nJ; x) - Y(n,S - 1; x) E {OJ}, where S > 0 (2.4)

    l the difference in y-coordinates of two subsequent points is nondecreasing in 6 and increases with steps at most 1:

    (Y(n, s; x) - Y(n, 8; x - 1)) -(Y(nJ - 1; x) - Y(n,6 - 1; x - 1)) E {O,l}~

    where x > 0 A S > 0. (2.5)

    Property (2.5) is very strong: it implies that if the y-values for x and x - 1 differ for 6 = d, they differ for every S > d.

    The definition of L is easily extended to support raster line segments with end points (0, Q) and (2n, 8 f ry), by translating L(n, 6) vertically over ty pixels.

    DEFINITION (of REFLINE). For n, S E N, and ty E Z, where 6 I 2, the set REFLINE(n, 6, ty) C_ Z2 is defined by

    REFLINE(n, 6, q) = L(n, 6) CB (0, ty).

    Note that the above definition implies translation invariance in the y-direction. We shall now present some theorems for n E N and points p, q E Z2 with 0 I p.x I q.x I: N = 2 and 0 I q.y - p.y 5 q.x -p-x. The following theorem states that for any two points p and q a REFLINE exists that contaks both p and 4.


    THEOREM 1. There exist numbers ty E Z and 6 E N, such that 6 I 2 and {p, q} c WFLIWn, 4 ty).

    Proof: For 6 E N, S I 2, we define the function h as

    h(S) = Y(n, 8; q-x) - Y(n, 6; p.x>.

    We shall show that the range of h equals [0 . . . q.x - p.x]:

    (a) h(0) = 0, because of property (2.1), (b) h(2) = 4.x - p.x, because of property (2.2), (c) h(6) - h(6 - 1) E (0, l} for 6 > 0, because of properties (2.4) and (2.5).

    Hence, the range of h equals [0 . . * q.x -p.x]. Since q.y -p.y I q.x -p.x, a d exists such that h(d) = q.y - p.y. With v defined as p.y - Y(n, d; p.x), it follows that

    Y(n, d; p.x) + ty = Y(n, d; p.x) +p.y - Y(n, d; P.X) = P.Y,

    Y(n, d; 4.x) + ty = Y(n, d; 4.x) + p.y - Y(n, d; P.X) = P-Y + h(d) = p.y + q.y - p.y = q.y.

    Hence, {p, q} c REFLINE(n, d, ty). 0

    The following theorem states that for any two REFLINES that contain points p and q, the part between p and q is exactly the same.

    THEOREM 2. For all tyl, tyz E Z, and d,, d, E N, such that p and q are both elements of REFLINE(n, d,, vi) and REFLINE(n, d,, tyz), the following holak

    REFLINE(n,d,,ty,) f~ ([p.x 0.. q.x] X Z) = REFLINE(n, d,, ty*) Cl ([p.x *a* q.x] X Z).

    Proof. Let tyi, d,, tyz, and d, be as stated in the theorem. Notice that we only need to prove

    (Ax E N: p-x I x I q.x: Y(n, d,; x) + tyl = Y(n, d,; x) + tyz).

    For x E N, x Z+Z 2, we define the function f by

    f(x) = Y(n, d,; x) + tyl - (Y(n, d,; x) + 0~~).

    We shall show that f(x) = 0 for all x with p.x 5 x < 4.x.

    (a) f(p.x) = 0, because p E REFLINE(n, d,, zjQ (I REFLINE(n, d,, ty*). (b) f(q.x) = 0, because q E BEFLINE(n, d,, tyJ fl REFLINE(n, d,, &). (c) f(x) - f(x - 1) E (O,l}, f or x P- 0, because of property (2.5) and f(x) -

    f(x - 1) = (Y(n, d,; x) - Y(n, d,; x)) - (Y(n, d,; x - 1) - Y(n, d,; x - 1)).

    Because of (c), f is nondecreasing in x, and thus (Ax E N: p.x I x I q.x: f(x) = 0). 0


    0 4 8 12 16

    FIG. 4. REFLINE(4,6,0) (indicated by 0) and REFLINE(4,5,1) (indicated by 0): both contain p = (6,2) and q = (14,5); the parts between p and q are the same.

    As an illustration, in Fig. 4 two different REFLINES are shown that both contain p = (6,2) and q = (14,5): the part between p and q of both RFFLINES is the same. Theorems 1 and 2 give rise to the following definition of the raster line segment connecting points p and q. Informally, it is the part between p and q of a REFLINE containing both p and q.

    DEFINITION (of Line). The set Line(n, p, q) c Z2 is defined by

    Line(n,p,q) = REFLINE(n,a,fy) n ([p.x a.0 q.x] X Z),

    where t and 6 are such that {p, q} c REFLINE(n, 6, ty). In Fig. 5, Line(4, p, q) is shown for p = (6,2) and q = (14,5) (see also Fig. 4).

    With the above definition it is clear that the following theorem holds.

    THEOREM 3. Let A be an algorithm that generates Line(n, p, q) for any n E N, P, 4 E z2, where 0 I p.x -C q.x I 2 and 0 I q.y - p.y < q.x - p.x. Then A satisjies SPl, and A is translation invariant in the y-direction.

    An algorithm based on the definition of Line will consist of two parts:

    (1) the search for a S such that Y(n, 6; q.x) - Y(n, 6; p.x) = q.y - p.y, and (2) the generation of REFLINE(n, 6, ty) n ([ p.x . . . q.x] x Z), where ty =

    p.y - Y(n, 6; p.x).

    For given n, 6, and x, the calculation of Y( n, S; x)...


View more >