2
COMPUTER ORA1)mcs AND~tAOn PrtocEssn~o 15,401-402 (1981) NOTE Algorithm for Generating a Digital Circle on a Triangular Grid KENSUKE SHIMIZU Department of Computer Science, Gunma Utlioersily, Kiryu 376, Japan Received March 12, 1980 An algorithm for determining the node-to-node movements to generate a digital circle on a triangular grid is given. At each step, we choose the one of three directions which minimiTcs If(u, v)l wheref(u, v) ffi 0 is the circle equation. It was pointed out by Freeman [1] that the use of a hexagonal coordinate system is attractive for certain specialized applications because the distance to the six nodes surrounding a given node is unity and it permits rotation by any multiple of 60 ~ without recomputation of the plotting sequence. We shall here derive an algorithm for determining the node-to-node movements to generate a digital circle on the triangular grid with (u, v) coordinate system shown in Fig. 1. The positive vaxis makes an angle of 120 ~ with the u axis. On a Cartesian coordinate system, the equation for a circle centered at the origin with radius R is f(x,y) ~ x 2 +y2 _ R 2 _ 0. If the u axis is consistent with the x axis, (i) x=u-v/2 y=V3v/2. Substituting (2) into (1), we obtain f(U,V) ~tt 2 -- UV + V 2- R 2 ffi 0. (2) (3) The function f(u, v) is positive outside the circle and is negative inside the circle. As shown in Fig. 1, if we assume the current node is P(ut, vi), the candidate point is A or B, and the decision criterion is whether the distance d a is larger than d B or not. It is known that if R is large enough, d4 and d s are nearly proportional to [ f(u i, vi + 1)1 a n d [f(u i + 1, v~ + 1) I, respectively: d._..~A ~ If(u,, v, + I)1 (4) d,, l-f(",+I,~,+ I)I" In the first sextant, there are three candidate directions for step i + 1: l-link move (60~ 2-1ink move (120~ 3-1ink move (180~ following the notation of Freeman [1]. 401 0146-664X/81/040401-02502.00/0 Copyright 1981 by Academi~ Preas, Inc. All dght~ of rcproductinn in any form reserved.

Algorithm for generating a digital circle on a triangulargrid

Embed Size (px)

Citation preview

Page 1: Algorithm for generating a digital circle on a triangulargrid

COMPUTER ORA1)mcs AND ~tAOn PrtocEssn~o 15,401-402 (1981)

NOTE

Algorithm for Generating a Digital Circle on a Triangular Grid

KENSUKE SHIMIZU

Department of Computer Science, Gunma Utlioersily, Kiryu 376, Japan

Received March 12, 1980

An algorithm for determining the node-to-node movements to generate a digital circle on a triangular grid is given. At each step, we choose the one of three directions which minimiTcs

If(u, v)l wheref(u, v) ffi 0 is the circle equation.

I t was pointed out by F reeman [1] that the use of a hexagonal coordinate system is attractive for certain specialized applications because the distance to the six nodes surrounding a given node is unity and it permits rotation by any multiple of 60 ~ without recomputat ion of the plotting sequence.

W e shall here derive an algorithm for determining the node-to-node movements to generate a digital circle on the triangular grid with (u, v ) coordinate system shown in Fig. 1. The positive vax i s makes an angle of 120 ~ with the u axis.

O n a Cartesian coordinate system, the equation for a circle centered at the origin wi th radius R is

f ( x , y ) ~ x 2 + y 2 _ R 2 _ 0.

I f the u axis is consistent with the x axis,

(i)

x=u-v/2 y=V3v/2.

Substituting (2) into (1), we obtain

f ( U , V ) ~ t t 2 - - UV + V 2 - R 2 ffi 0.

(2)

(3)

T h e function f (u , v) is positive outside the circle and is negative inside the circle. As shown in Fig. 1, if we assume the current node is P(ut , vi), the candidate

po in t is A or B, and the decision criterion is whether the distance d a is larger than d B or not. It is known that if R is large enough, d4 and d s are nearly proportional to [ f ( u i, vi + 1)1 and [ f (u i + 1, v~ + 1) I, respectively:

d._..~A ~ If(u,, v, + I)1 (4) d,, l-f(",+ I,~,+ I)I"

In the first sextant, there are three candidate directions for step i + 1: l-link m o v e (60~ 2-1ink move (120~ 3-1ink move (180~ following the notation of F r e e m a n [1].

401 0146-664X/81/040401-02502.00/0 Copyright �9 1981 by Academi~ Preas, Inc. All dght~ of rcproductinn in any form reserved.

Page 2: Algorithm for generating a digital circle on a triangulargrid

4 0 2 KENSUKE SHIMIZU

FIo. 1. Circle on a triangular grid with coordinate system u, v.

The f (u , v) corresponding to each move are given as follows.

Z, = f ( u , + 1,v i + 1) =f(u l , v , ) + u i + v, + 1,

Z 2 - - f ( u i ,v i+ 1)- - - - f (u i ,v , ) - - u t + 2 v i+ 1,

Z 3 - - f ( u i - 1,vi) = f ( u i , v i ) - - 2 u i + v i+ 1.

(5) (6) (7)

Note that the operations involved in (5), (6), and (7) are addition, subtraction and shifting. Furthermore, if the initial point is exactly on the triangular grid, f (u o, Vo) equals zero. Then we arrive at the following algorithm.

A1. [Initialize] Set i ~ 0, u ~-- u o, v ~ v 0, and f (u , v) ~ 0 if the initial point is on the triangular grid.

A2. Obtain Z1, Z2, Z 3 f rom (5), (6), or (7), respectively. A3. Obtain Zj ( j = 1, 2 or 3) which gives minimum absolute value among Z 1, Z 2

and Z 3. A4. Make a j - l ink move, replace f(ui, vi)with Zj, and return to step A2.

The extension to sextants other than the first is straightforward. For example, in the second sextant, it is only necessary to interchange the .blink move in the first sextant with a ( j + 1)-link move.

REFERENCE

1. H. Freeman, Algorithm for generating a digital straight line on a triangular grid, I E E E Trans. Computers C-28, 1979, 150-152.