<<

ARTICLE IN PRESS

Computers & Graphics 30 (2006) 834–842 www.elsevier.com/locate/cag Chaos and Graphics Spiral packing

Cameron Brownea,Ã, Paul van Wamelenb

aSWiSHzone.com Pty Ltd, The Basement, 33 Ewell Street, Balmain, NSW 2041, Australia bDepartment of , Louisiana State University, Baton Rouge, LA 70803-4918, USA

Abstract

We present a simple method for creating artistic space-filling designs based on spiral packings. Connected spiral sets are generated by successively branching child spirals from parent spirals, constrained to fit nearby neighbors in their environment. The underlying geometry is discussed in detail and a number of color examples generated by the algorithm are given. r 2006 Elsevier Ltd. All rights reserved.

Keywords: ’ spiral; Apollonian ; ; Art

1. Archimedes’ spiral 2. Spiral packing

The Archimedean spiral is a spiral with the polar We wish to pack a given area with connected sets of equation Archimedes’ spiral. This will be achieved by successively

1=n branching child spirals from parent spirals until the target r ¼ ay , (1) area is filled to some desired level of coverage (Fig. 2). The where r is the radial distance, y the polar , and n is a following constraints must be met: constant which determines how tightly the spiral is ‘‘wrapped’’ [1]. When this constant n ¼ 1, the resulting 1. Each child may have at most one parent (though parents spiral is known as Archimedes’ spiral: may have multiple children), r ¼ ay. (2) 2. Each child must meet its parent tangentially, and be rotated such that its end point lies on the line between Archimedes’ spiral (Fig. 1, left) can be defined in cartesian the spiral centers, coordinates by the properties (x, y, w, y, T, o) where (x, y) 3. A child’s width w must never exceed its parent’s width, is the spiral’s center, w is the width of one rotation, y is the and starting angle or phase, T is the total sweep or number of 4. Spirals may touch neighboring spirals tangentially but rotations, and o is the spiral’s orientation (o ¼1 for may not intersect them. clockwise and o ¼ 1 for counterclockwise). Defining functions Other potential constraints are relaxed to allow flex- xsðtÞ¼x þ wt cosðy þ 2potÞ, (3) ibility of design: a child may be of a greater total radius than its parent if T c4Tp, a child need not be the same ysðtÞ¼y þ wt sinðy þ 2potÞ, (4) orientation as its parent, and so on. Archimedes’ spiral was chosen as the most suitable form for both its aesthetic and then the spiral is paramaterized by ðx ðtÞ; y ðtÞÞ for 0 t T. s s p p well-behaved mathematical qualities. We describe the area enclosed by the spiral’s outer 3601 The packing starts with a seed pair of opposed matching sweep as its footprint (Fig. 1, right). spirals S1 and S2 (Fig. 2a) with identical w, T, o, opposed à y, and tangential end points such that x ðTÞ¼x ðT 1Þ, Corresponding author. Tel.: +61 7 3371 1576. s1 s2 y ðTÞ¼y ðT Þ x ðT Þ¼x ðTÞ y ðT Þ¼ E-mail addresses: [email protected] (C. Browne), s1 s2 1 , s1 1 s2 , and s1 1 [email protected] (P. van Wamelen). xs2 ðTÞ. Fig. 2b shows a child spiral branching from a single

0097-8493/$ - see front matter r 2006 Elsevier Ltd. All rights reserved. doi:10.1016/j.cag.2006.07.010 ARTICLE IN PRESS C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842 835 parent. For the sake of clarity, the parent spiral is deemed 3. Numerical solution to remain a complete spiral in subsequent operations even though part of it is clipped by the child spiral. We now consider the solution of case III, the most Next is shown a further child spiral that touches one difficult. We will write down the equations resulting from other spiral (Fig. 2c), and a smaller child that touches two the cartesian coordinates of the relevant intersections and other spirals (Fig. 2d). This process continues within the tangential points, and discuss the solution of the resulting (decreasing) target area until a packing of the desired system of equations. density is achieved. There will be as many distinct We have the following ten variables: connected spiral sets within a packing as there are seed pairs. 1. x, y, w and y describe the spiral we are looking for, and 0 There are therefore three general geometric cases to 2. ti and t i are real numbers such that S at ti touches Si at 0 consider, as shown in Fig. 3: t i, for i ¼ 1, 2, 3.

1. Case I: Child spiral S branching from existing parent Each pair of touching spirals give three equations. The x- spiral S1 (Fig. 3a). The child spiral is of a specified width coordinates must agree and the y-coordinates must agree: w, number of turns T, orientation o, and direction 0 relative to the parent. xsðtiÞ¼xsi ðtiÞ, (5) 2. Case II: Child spiral S of a specified width w, number of y ðt Þ¼x ðt0Þ, (6) turns T and orientation o branching from parent S1 to s i si i touch one other spiral S2 (Fig. 3b). and the slopes of touching pairs must be equal: 3. Case III: Child spiral S of a specified number of turns T 0 0 qxsðtiÞ qy ðt Þ qxs ðt Þ qy ðtiÞ and orientation o branching from parent S1 to touch si i i i s 0 ¼ 0 . (7) two other spirals S2 and S3 (Fig. 3c). qti qti qti qti Another equation specifies that the child spiral to be fitted The bottom row of Fig. 3 shows the underlying geometry should be rotated such that its end point lies on the line of these relationships. In each case, S is rotated to lie between the centers of S and S1: to S1 such that its end point T lies on the line between the spiral centers. The child is clipped at the sinðyÞðx1 xÞ¼cosðyÞðy1 yÞ. (8) intersection point U and the parent is clipped along the Note that although the child’s end point lies on the line interval between the tangent point V and intersection point between the centers, the tangent point does not necessarily U. Following clipping, there should be no intersection do so; it does not necessarily occur at precisely Ts1. between any pair of spirals within the packing. In all cases, We therefore have ten equations with ten unknowns. the parent spiral is deemed to remain complete even though Trying to solve this set of equations algebraically is intervals along its sweep may be clipped by children. probably a hopeless endeavor, but there are well-known techniques for solving such systems numerically. We will T describe one of the simplest, Newton’s Method for Systems. w 0 0 0 We define v ¼ðx; y; w; y; t1; t1; t2; t2; t3; t3Þ, a vector con- taining all of our variables, and denote its components by v1, v2 etc. Rewriting the ten equations gives (x,y) O 0 f 1ðvÞ¼xsðt1Þxs1 ðt1Þ, (9)

f ð Þ¼y ðt Þy ðt0 Þ 2 v s 1 s1 1 , (10)

qy ðt0 Þ 0 qxsðt1Þ s1 1 qxs1 ðt1Þ qysðt1Þ f 3ðvÞ¼ 0 0 , (11) Fig. 1. Archimedes’ spiral and its footprint. qt1 qt1 qt1 qt1

(a) (b) (c) (d)

Fig. 2. Spiral packing: (a) a seed pair, (b) simple branch, (c) fitting to one other, and (d) fitting to two others. ARTICLE IN PRESS 836 C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842

S 2 S 2

S S

S

S3 S1 S1 S1

Q Q

W W C C V V V C T T T X

P U P U P U R

(a) (b) (c)

Fig. 3. Branch geometry: (a) simple branch, (b) fitting to one other, and (c) fitting to two others.

0 f 4ðvÞ¼xsðt2Þxs2 ðt2Þ, (12) column vector y and then setting v1 ¼ v0+y. It is known that this iteration converges quadratically to a solution for f ð Þ¼y ðt Þy ðt0 Þ 5 v s 2 s2 2 , (13) our system, provided that our initial guess is good enough. Note that the system can also be written in the form qy ðt0 Þ 0 qxsðt2Þ s2 2 qxs2 ðt2Þ qysðt2Þ f 6ðvÞ¼ , (14) 1 0 0 v þ ¼ v Jðv Þ Fðv Þ, (20) qt2 qt2 qt2 qt2 i 1 i i i which makes its similarity to the usual one-dimensional f ðvÞ¼x ðt Þx ðt0 Þ, (15) 7 s 3 s3 3 Newton’s Method more apparent. 0 The functions occurring in the Jacobian matrix are f 8ðvÞ¼ysðt3Þys ðt Þ, (16) 3 3 simple enough that their derivatives can be determined qy ðt0 Þ 0 symbolically, hence the Jacobian matrix can be precom- qxsðt3Þ s3 3 qxs3 ðt3Þ qysðt3Þ f 9ðvÞ¼ 0 0 , (17) puted explicitly. The implementation of a method to solve qt3 qt qt qt3 3 3 this set of equations numerically should be relatively straightforward. The solutions of the simpler cases I and f 10ðvÞ¼sinðyÞðx1 xÞcosðyÞðy1 yÞ. (18) II involve similar, but simplified, applications of this ð Þ¼ð ð Þ ð Þ ð ÞÞT Let F v f 1 v ; f 2 v ; ...; f 10 v be the column vector process. containing our functions. We are looking for a v such that FðvÞ¼0. Define the 10 10 Jacobian matrix: 4. Apollonian packing 0 1 qf 1ðvÞ qf 1ðvÞ qf 1ðvÞ B qx1 qx2 qx10 C We turn now to the related study of circle packing. The B qf ðvÞ qf ðvÞ qf ðvÞ C B 2 2 2 C Greek geometer (3rd century BC) B qx1 qx2 qx10 C JðvÞ¼B C. (19) studied the problem of drawing a circle tangent to three B . . .. . C @ . . . . A other objects, each of which may be a point, line or circle. qf 10ðvÞ qf 10ðvÞ qf 10ðvÞ There are a total of ten cases, the tenth being fitting a circle qx qx qx 1 2 10 tangent to three other circles, hence this problem is known Now suppose that we have as initial guess v0 for the values as Apollonius’ Tenth Problem. of the variables. Then we can obtain a better guess, v1,by There are eight total solutions to this problem [1], but we solving the linear set of equations Jðv0Þy ¼Fðv0Þ for the are only interested in one: the circle of minimum radius ARTICLE IN PRESS C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842 837

Fig. 4. Apollonian circle packing and the Apollonian gasket.

(Fig. 4, left). Note that for each touching pair of circles the 3. If 2. fails or there is only one intersecting spiral, then try tangent point lies on the line between the circles’ centers. to fit a spiral with the same width as S0 to the spiral with If the three bounding circles are mutually tangent, then the greatest intersection with S0. If the resulting spiral is the minimal fitted circle is called the interior Soddy circle not too far from S0 then use it. [1]. The three interstitial gaps formed by such a placement 4. If all else fails fit the biggest spiral in the direction of S0 can themselves be fitted with interior Soddy circles; to the parent. continuing this process to a specified depth results in a fractal structure called the Apollonian gasket [1], Apollo- This algorithm, explained in more detail in Listing 1, nian fractal [2] or Apollonian packing [3,4], as shown in assumes that we can solve the spiral fitting Cases I, II and Fig. 4 (right). III outlined in Section 2. We use the following iterative Kasner and Supnick [3] prove that the porosity of a full approximation algorithm for all three cases: Apollonian packing (the ratio of vacant area to the area covered by circles) is zero; the packing is an area-filling set. 1. Approximate the spirals by circles, The of the simplest Apollonian packing 2. Solve the circle fitting problem, and has been calculated to be 1.30568470.00001 [4]. 3. Use the solution to make better circle approximations to Despite the obvious similarities between Apollonian the spirals. packing and the packing of spirals that we aim to achieve, there are also significant differences that make the case of Pseudocode for this procedure is given in Listing 2. spiral packing more difficult. However, this comparison Listing 1. Description of the general fitting algorithm. provided the impetus for an intuitive solution to the spiral packing problem due to the second author. This solution was tried mostly out of curiosity but proved more than Input: A spiral, S, indicated by the user, branching from adequate for our purposes, and is discussed in the next S_P, the parent spiral. section. Output: A spiral, as close to S as possible, but not intersecting any non-parent spirals. 5. Iterative spiral fitting Step 1: Return an error if S has its center inside S_P.

Given a parent spiral S1 and a preferred location for a Step 2: child spiral S0, specified by the user with known number of If S has width more than its parent, reduce the width turns T and orientation o, we wish to find the child spiral S to that of the parent and adjust the center so that the branching from S1 as close to S0 as possible, and fitted to spiral still branches in the same direction as indicated any potentially intersecting spirals S2, S3, etc. The by the user. algorithm must be robust enough to handle ambiguous Step 3: child placements by the user. If S does not intersect any non-parent spirals, Our algorithm consists of the following steps: return S. Step 4:

1. If S0 does not intersect other spirals let S ¼ S0. If the indicated spiral intersects 2 or more spirals do 2. If S0 intersects two or more spirals, try to fit S to the the following: (at many points things might fail closest two without being too far from S0. below, if so go to Step 5) ARTICLE IN PRESS 838 C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842

Step 4a: locate the two spirals S2 and S3 closest to S0 (not Approximate all existing spirals by discs. including S1) For each existing non-parent spiral (approximated c0 ¼ circle with center equal to S0 and unknown radius as a disc) determine the radius of the disc that r0 touches this disc and the parent disc and has its do center on the line connecting the centers of S_P { and S. Let S_1 and S_2 be the two spirals with the for (each spiral Si ¼ {1,2,3} to be fitted to) smallest such associated radius (the "bounding { spirals"). ri ¼ radius of Si in the direction of the S Step 4b: rsi ¼ radius of S in the direction of the Si Fit a spiral S_3 to S_1 and S_2 (branching from // for S1 this is the radius of S at T1 S_P). ci ¼ circle with center equal to Si and radius Step 4c: ri(rsirso) While S_3 intersects existing (non-parent) spirals: } Let S_4 be the spiral with the biggest intersec- solve the appropriate circle fitting problem: tion with S_3. Case I: Fit c0 to c1 (if no intersection) Let S_5 be the spiral fitted to S_1 and S_4. Case II: Fit c0 to c1 and c2 (if intersect S2) Let S_6 be the spiral fitted to S_2 and S_4. Case III: Fit c0 to c1, c2 and c3 (if intersect S2 Select S_5 or S_6 with the smallest width and let and S3) this be the new S_3. D ¼ discrepancy between c0’s new and previous If this increases the width of S_3, go to Step 5. centers Let the new S_1, S_2 be S_1, S_4 or S_2, S_4 S center ¼ c0 center depending on whether S_5 or S_6 was selected. S width ¼ r0/(T1)// radius at T1 equals the Fit a spiral S_3 to S_1 and S_2. radius of c0 End while } while (D4threshold) Step 4d: return S. If the angle from S_P’s center to S_3’s center is within 12.5 degrees of the angle to S’s center, Replacing spirals by circles makes the fitting problem return S_3. easy to solve for each case. Simply take the equations for Step 5: (Step 4 fails or just one spiral intersects S). the various circles: If just one spiral intersects S, let it be denoted S_1. 2 2 2 Otherwise let S_1 be the bounding spiral with ðx cxÞ þðy cyÞ ¼ r , (21) smallest bounding radius, as in Step 4a. and solve the system of simultaneous equations. This Try to find a spiral S_2 with the same width as S reduces to at most a quadratic equation which can branching from S_P and touching S_1. be solved with the quadratic formula, and the best of the Step 6: two resulting solutions picked (if necessary). The best If S_2 does not intersects non-parent spirals, and it’s solution will generally be the closest to the preferred angle isn’t off (as in 4d) by more than 12.5 degrees, placement. return S_2. Step 7: We cannot prove that our spiral fitting algorithm will Set S_2 ¼ S. always converge (and in fact for very bad initial guesses it Repeat until S_2 does not intersect any non-parent will not) but in practice it works well. Note that if the spirals: algorithm does converge, then it will not give the exact Let S_1 be the spiral with the biggest intersection geometric solution outlined in Section 3 due to the with S_2. assumption that spirals touch tangentially on the line Let (the new) S_2 be the spiral branching from connecting their centers, and in general this is not the case. S_P, touching S_1 and with its center on the line However, the error introduced by this assumption is on the connecting the centers of S_P and S. order of one part in one thousand and is negligible for our End repeat purposes. Step 8: Fig. 5 shows a portion of a spiral packing gene- Return S_2. rated from a single seed pair using this iterative algo- rithm. The overall effect of this design is similar in Listing 2. Pseudocode for the iterative solution of Cases I, nature to the Apollonian packing, however there is II and III. one major difference: every interior point within a spiral set is connected to every other. There will be as many Input: parent spiral S1 and preferred child position S0 self-connected spiral sets in a design as there are seed Output: fitted child spiral S pairs. ARTICLE IN PRESS C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842 839

Fig. 5. Zoomed views of a sparsely packed area.

6. Implementation This last point leads to some approaches for automating the spiral packing process. Given an area to be packed, two The algorithms described above form the basis of a spiral obvious approaches are: design editor implemented in Visual C++. There are two basic operations: 1. Image based: Draw the area as an image. Place a seed pair then successively grow children, removing from the 1. Nominate a seed pair, and image the footprint of each new spiral. A distance map 2. Nominate a child. of the image will indicate the most suitable placement for the next spiral (the highest point within range of a The user interactively specifies the preferred location of potential parent), and the records of existing spirals can each seed pair or child using the mouse, and the program be accessed to determine its exact fit. Continue until the adds the correctly fitted result if possible. The preferred largest remaining image area falls below a given spiral’s degrees of freedom (width, turns, orientation and threshold. so on) are described by a master spiral template that may 2. Triangulation: Coarsely polygonize the boundary area be edited by the user. Similarly, any placed spiral may be and determine its Constrained Delaunay Triangulation. deleted or its color scheme edited. Place a seed pair then successively grow children, re- Boundary shapes were implemented in the program as triangulating with each new spiral’s center added as a sets of small, closely spaced spirals laid at regular intervals vertex. The largest current triangle adjacent to a along the boundary path. Boundary spirals have small potential parent will contain the preferred location for width but a large number of turns (100) to give them the next spiral. Continue until the largest triangle falls reasonably constant exterior and make them below a given threshold. circle-like in nature; this is another attractive feature of Archimedes’ spiral. Boundary spirals participate in the fitting process but are excluded from the final output. 7. Results Boundary shapes with smooth flowing curves such as spirals, teardops and Paisleys were found to give the best Drawing the outlines of the final design is a simple results. matter of clipping each parent along the intervals at which Seamless tiles that replicate to fill the plane may be children attach, and clipping each child at the point of achieved by repeating each spiral periodically based on tile intersection with its parent. Coloring the interior of spirals width, and taking ‘‘wrapped’’ spirals into account when is less straightforward. fitting children. Each tile will contain at least one seed pair. The most attractive color schemes were found to involve When using the spiral editor, it was found that flipping color blends around the spiral sweep such that there is orientation with each level of nesting gave best results, as some contrast between concentric layers. A number of children then generally followed their parents’ direction of dominant colors are specified for each spiral, and the fill outward flow. This can be seen in Fig. 5. When branching brush blends from one color to the next along its sweep. children, it is best to branch from the spiral with width However, care must be taken to avoid the pronounced closest to the expected child width. Packing to the same optical illusion of three-dimensional ridges that may occur depth in all areas was found to give uneven coverage; a if alternating light and dark color shifts fall into phase more uniform coverage is achieved by packing each along concentric layers. Fig. 6 (left) shows a 7201 sweep successive spiral in the largest remaining gap. blending from white at 01 to black at 3601 to white at 7201. ARTICLE IN PRESS 840 C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842

Fig. 6. The spiral ridge illusion caused by concentric color gradients in phase.

Fig. 8. Under the spreading curly tree (Ficus archimedea).

Another subtlety of coloring is that children must exactly match their parent’s color along the branch interval. If a Fig. 7. A single connected set of spirals. child branches midway between two dominant parent colors, then its color scheme may benefit from some tweaking (such as a cycling of its colors) to avoid the The right side of the resulting spiral shows no effect, propagation of a diluted color mix. For instance, if the however the left side shows a pronounced ridged effect parent is red and blue, then some of its descendants will be due to the fortuitous combination of color gradients. Fig. 6 predominantly purple unless adjusted. (right) shows how distracting this effect can become Fig. 7 shows a connected set of spirals generated from a for larger designs. This problem may be avoided by single seed pair constrained to a Paisley shape, with ensuring that color cycles occur out of phase at say 2701 exterior flourishes added after the removal of the bound- rather than 3601 intervals, so that any residual effect is ary. Each spiral’s color palette covers the spectrum. distributed across the design at various and This image was exported in PostScript format, then diminished. treated in Photoshop with a ‘‘glass’’ filter that suggests a ARTICLE IN PRESS C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842 841

Fig. 9. Intertwined arms in red, green and blue palettes. Each arm is a single connected spiral set. three-dimensional meniscus through judicious shading and highlights. Fig. 8 shows a tree-like design generated from a single seed pair, one of which was excised from the final design and replaced manually with the trunk silhouette. This figure shows the footprint of the spiral set (black) minus its outline (white) attenuated for width according to spiral size. The three distinct spiral sets in Fig. 9 themselves follow spiral paths. The spirals within each set have color palettes based on brightness variations of that set’s primary color: red, green or blue. This figure shows unmodified PostScript output from the spiral design editor. Fig. 10 shows four distinct spiral sets, each constrained to a disjoint area of the Yin Yang shape. The spiral sets were mapped onto a hemisphere, then POV-Ray sphere primitives generated at regular intervals along each spiral path with radii based on spiral width. The end result was four polyspheres, which were renderd using the POV-Ray ray tracer. Each of these designs were generated interactively using the spiral design editor and took from half an hour to two hours to complete. Fig. 10. Four connected spiral sets exported as polyspheres mapped onto a hemisphere. 8. History motif in the history of art. There are many precedents, an The idea of spiral packing for space-filling artistic early example being the tri-spiral stone carvings from the designs occurred to the first author during a plane flight Newgrange tomb in Ireland (Fig. 11, right). These carvings to Istanbul. However, seeing the very same principles in were made circa 3100 BC, predating the Celtic style of action the next day on the walls of the 6th century Aya artwork—which is replete with interlocking rather than Sofia mosque (Fig. 11, left) indicated the prevalence of this branching spirals—by over 1500 years. ARTICLE IN PRESS 842 C. Browne, P. van Wamelen / Computers & Graphics 30 (2006) 834–842

Fig. 11. A mural in the Aya Sofia mosque (Istanbul) and the Newgrange tri-spiral (Ireland). Photos by Helen Gilbert and Jorge Tutor r /www.jorgetutor.comS.

It is interesting to note that after placing a seed pair to allow accurate packing to as yet untried levels, and the start a spiral packing, the tri-spiral is the most natural step automation of the packing process using the techniques to take next. Four-sided placements are generally less suggested. elegant and more difficult to work into a design, as can be seen in Fig. 2. Hargittai and Pickover [5] give an excellent overview of References spirals in art, nature and science. [1] Weisstein E. Concise encyclopedia of mathematics. Boca Raton: CRC 9. Conclusion Press; 1999. [2] Bourke P. An introduction to the Apollonian fractal. /http:// astronomy.swin.edu.au/pbourke/papers/apollony/apollony.pdfS This paper describes a method for creating connected [3] Kasner E, Supnick F. The Apollonian packing of circles. Proceedings spiral sets which may be used to fill given boundary shapes of the National Academy of Sciences of the United States of America to a given density, for artistic purposes. A numerical 1943;29:378–84. solution for exact fitting is given, as well as an iterative [4] Manna S, Herrmann H. Precise determination of the fractal dimensions of Apollonian packing and various space-filling bearings. method based on the approximation of spirals by circles. Journal of Physics A: Mathematical and General 1991;24:L481–90. Future work might include the implementation of the [5] Hargittai I, Pickover C, editors. Spiral symmetry. Singapore: World exact geometric solution for the spiral fitting problem to Scientific; 1992.