Application Center - Maplesoft

# Sierpinski Gasket with Control Points

You can switch back to the summary page by clicking here.

Wieslaw Kotarski (kotarski@math.us.edu.pl) & Agnieszka Lisowska (alisow@ux2.math.us.edu.pl)
Institute of Computer Science
Silesian University
Bedzinska 39
41-200 Sosnowiec, Poland

(Abstract)

In this worksheet we show how one can easily change the shape of the well-known Sierpinski gasket.. The method is based on relationship between subdivision schemes and IFS (Iterated Function System) that contains information needed for fractal rendering. We present examples of deformed Sierpinski gaskets obtained using differet subdivision matrices and differently placed control points. The worksheet is the eighth one in the series of  the authors' works published earlier on Maplesoft web page.

1. Introduction

It is well known fact that even small changes in coefficients of IFS usually causes that a fractal, simply speaking "scatters". So, it is not possible to control the fractal shape via IFSs coefficients. But we show that using subdivision matrices and the possibility of introducing control points to fractal, one can  smoothly change the fractal shape. The method will be presented on the example of the well-known Sierpinski gasket. However, it is possibly to apply  the presented method to other fractals. Examples show that one can control the  fractal shape similarly as eg. in Bezier curve case.

2. IFS via subdivision matrices

Following  [9] one can find IFS for fractal rendering of Sierpinski gasket using subdivision matrices. We show how they can be derived. Let's take into account a curvelinear triangle with vertices denoted by P1, P2 and P3, respectively. Additionally, we introduce three further points: the first P4 lying between P1, P3, the second P5 lying between P1,P2 and the third P6 lying between P2,P3, respectively, as shown in Fig. 1.

Fig. 1. Curvelinear triangle and its subdivision on subtriangles.

The triangle with vertices P1,P2,P3 can be transformed  into three smaller ones: the first triangle T1 with vertices P1,P5,P4, the second triangle T2 with vertices P4,P6,P3 and the third one T3 with vertices P5,P2,P6. Dependencies between large triangle and three smaller ones may be expressed eg. with the help of three following subdivision matrices:

Then, we have P'=B1*P, P''=B2*P, P'''=B3*P, where P is a matrix of control points completed by arbitrary elements to the non-singular one and P', P'' P''' are points of smaller triangles. It should be pointed out that for all triangles the same points enumerating rule was applied. Next, following [1],[9] one can derive IFS for generating fractal triangle in the form:

It should be stressed that very many subdivision matrices may be proposed to obtain fractal objects of Sierpinski gasket types. But, to get  IFS consisting of contractive transformations subdivision matrices should be Markov ones, what means that their elements in rows are summing up to 1. Some further details concerning modeling different fractal objects using subdivision matrices and explanations concerning  used maple procedures can be found in [2]-[8]. To render fractally Sierpinski gasket we used probabilistic fractal algorithm, sometimes called Chaos Game.

3. Maple programs

 > restart;

 > with(plots):

 Warning, the name changecoords has been redefined

 > with(linalg):

 Warning, the protected names norm and trace have been redefined and unprotected

1. Procedure for generating Sierpinski gasket. Parameters: n - number of iterations, B1,B2,B3 - subdivision matrices, P - matrix of control points.

 > IFSierp := proc(n,B1,B2,B3,P)    local j, l, s, f1,f2,f3,f,seqpoints:    seqpoints := [[1,1,1,1,1,1]];    s := NULL;      f1:=evalm(inverse(P)&*B1&*P);    f2:=evalm(inverse(P)&*B2&*P);

 > f3:=evalm(inverse(P)&*B3&*P);

 > f:=[f1,f2,f3]; for j to n do   seqpoints:=[s,seq(evalm(seqpoints[ii]&*f[1]),ii=1..nops(seqpoints)),   seq(evalm(seqpoints[ii]&*f[2]),ii=1..nops(seqpoints)),   seq(evalm(seqpoints[ii]&*f[3]),ii=1..nops(seqpoints))]: od;   l:=seqpoints;     pointplot([seq([l[i][1],l[i][2]],i=1..nops(l))],scaling=constrained,axes=none); end:

 >

2. Procedure for generating Sierpinski triangle depending on parameter k related to subdivision matrices, n - number of iterations, P - matrix of control points.

 > IFSierp_k := proc(n,P,k)    local j, l, s,B1,B2,B3, f1,f2,f3,f,seqpoints,sierp,pts,ctrpts:    seqpoints := [[1,1,1,1,1,1]];    s := NULL;   B1:=matrix([[1,0,0,0,0,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[k/16,0,0,k/16,(16-2*k)/16,0], [k/16,0,0,(16-2*k)/16,k/16,0],[(16-2*k)/16,0,0,k/16,k/16,0]]); B2:=matrix([[0,0,0,1,0,0],[0,0,0,0,0,1],[0,0,1,0,0,0],[0,0,k/16,k/16,0,(16-2*k)/16], [0,0,(16-2*k)/16,k/16,0,k/16],[0,0,k/16,(16-2*k)/16,0,k/16]]); B3:=matrix([[0,0,0,0,1,0],[0,1,0,0,0,0],[0,0,0,0,0,1],[0,(16-2*k)/16,0,0,k/16,k/16], [0,k/16,0,0,k/16,(16-2*k)/16],[0,k/16,0,0,(16-2*k)/16,k/16]]); f1:=evalm(inverse(P)&*B1&*P);

 > f2:=evalm(inverse(P)&*B2&*P);

 > f3:=evalm(inverse(P)&*B3&*P);

 > f:=[f1,f2,f3];

 > for j to n do     seqpoints:=[s,seq(evalm(seqpoints[ii]&*f[1]),ii=1..nops(seqpoints)),     seq(evalm(seqpoints[ii]&*f[2]),ii=1..nops(seqpoints)),     seq(evalm(seqpoints[ii]&*f[3]),ii=1..nops(seqpoints))]:   od;      l:=seqpoints;        sierp:=pointplot([seq([l[i][1],l[i][2]],i=1..nops(l))],scaling=constrained,axes=none);                               pts:=[seq([P[i,1],P[i,2]],i=1..6)];                  ctrpts:=pointplot(pts,scaling=constrained,axes=none,symbol=circle,color=red,      symbolsize=30,thickness=15):

 > display(sierp,ctrpts);

 > end:

3.1. Example I

The first set of subdivision matrices

 > B1:=matrix([[1,0,0,0,0,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[7/16,0,0,7/16,2/16,0],[7/16,0,0,2/16,7/16,0],[2/16,0,0,7/16,7/16,0]]);

 (3.1.1)

 > B2:=matrix([[0,0,0,1,0,0],[0,0,0,0,0,1],[0,0,1,0,0,0],[0,0,7/16,7/16,0,2/16],[0,0,2/16,7/16,0,7/16],[0,0,7/16,2/16,0,7/16]]);

 (3.1.2)

 > B3:=matrix([[0,0,0,0,1,0],[0,1,0,0,0,0],[0,0,0,0,0,1],[0,2/16,0,0,7/16,7/16],[0,7/16,0,0,7/16,2/16],[0,7/16,0,0,2/16,7/16]]);

 (3.1.3)

Control points

set 1

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,5/8,1,0,1,0],[3/4,1/2,1,0,0,1]]);

 (3.1.4)

 > IFSierp(7,B1,B2,B3,P);

set 2

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.1.5)

 > IFSierp(7,B1,B2,B3,P);

set 3

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.1.6)

 > IFSierp(7,B1,B2,B3,P);

3.2. Example II

The second set of subdivision matrices

 > B1:=matrix([[1,0,0,0,0,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[30/64,0,0,30/64,4/64,0],[30/64,0,0,4/64,30/64,0],[4/64,0,0,30/64,30/64,0]]);

 (3.2.1)

 > B2:=matrix([[0,0,0,1,0,0],[0,0,0,0,0,1],[0,0,1,0,0,0],[0,0,30/64,30/64,0,4/64],[0,0,4/64,30/64,0,30/64],[0,0,30/64,4/64,0,30/64]]);

 (3.2.2)

 > B3:=matrix([[0,0,0,0,1,0],[0,1,0,0,0,0],[0,0,0,0,0,1],[0,4/64,0,0,30/64,30/64],[0,30/64,0,0,30/64,4/64],[0,30/64,0,0,4/64,30/64]]);

 (3.2.3)

Control points

set 1

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,5/8,1,0,1,0],[3/4,1/2,1,0,0,1]]);

 (3.2.4)

 > IFSierp(7,B1,B2,B3,P);

set 2

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.2.5)

 > IFSierp(7,B1,B2,B3,P);

set 3

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.2.6)

 > IFSierp(7,B1,B2,B3,P);

3.3. Example III

The third set of subdivision matrices

 > B1:=matrix([[1,0,0,0,0,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[3/4,0,1/4,0,0,0],[3/4,1/4,0,0,0,0],[1/2,1/4,1/4,0,0,0]]);

 (3.3.1)

 > B2:=matrix([[0,0,0,1,0,0],[0,0,0,0,0,1],[0,0,1,0,0,0],[1/4,0,3/4,0,0,0],[1/4,1/4,1/2,0,0,0],[0,1/4,3/4,0,0,0]]);

 (3.3.2)

 > B3:=matrix([[0,0,0,0,1,0],[0,1,0,0,0,0],[0,0,0,0,0,1],[1/4,1/2,1/4,0,0,0],[1/4,3/4,0,0,0,0],[0,3/4,1/4,0,0,0]]);

 (3.3.3)

Control points

set 1

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,5/8,1,0,1,0],[3/4,1/2,1,0,0,1]]);

 (3.3.4)

 > IFSierp(7,B1,B2,B3,P);

set 2

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.3.5)

 > IFSierp(7,B1,B2,B3,P);

set 3

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.3.6)

 > IFSierp(7,B1,B2,B3,P);

3.4. Example IV

The fourth set of subdivision matrices

 > B1:=matrix([[1,0,0,0,0,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[3/8,0,-1/8,3/4,0,0],[3/8,-1/8,0,0,3/4,0],[0,0,0,1/2,1/2,0]]);

 (3.4.1)

 > B2:=matrix([[0,0,0,1,0,0],[0,0,0,0,0,1],[0,0,1,0,0,0],[-1/8,0,3/8,3/4,0,0],[0,0,0,1/2,0,1/2],[0,-1/8,3/8,0,0,3/4]]);

 (3.4.2)

 > B3:=matrix([[0,0,0,0,1,0],[0,1,0,0,0,0],[0,0,0,0,0,1],[0,0,0,0,1/2,1/2],[-1/8,3/8,0,0,3/4,0],[0,3/8,-1/8,0,0,3/4]]);

 (3.4.3)

Control points

set 1

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,5/8,1,0,1,0],[3/4,1/2,1,0,0,1]]);

 (3.4.4)

 > IFSierp(7,B1,B2,B3,P);

set 2

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.4.5)

 > IFSierp(7,B1,B2,B3,P);

set 3

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,1/8,1,1,0,0],[1/4,3/8,1,0,1,0],[3/4,3/8,1,0,0,1]]);

 (3.4.6)

 > IFSierp(7,B1,B2,B3,P);

3.5. Example V

Subdivision matrices parametrized by k.

 > B1:=matrix([[1,0,0,0,0,0],[0,0,0,0,1,0],[0,0,0,1,0,0],[k/16,0,0,k/16,(16-2*k)/16,0],[k/16,0,0,(16-2*k)/16,k/16,0],[(16-2*k)/16,0,0,k/16,k/16,0]]);

 (3.5.1)

 > B2:=matrix([[0,0,0,1,0,0],[0,0,0,0,0,1],[0,0,1,0,0,0],[0,0,k/16,k/16,0,(16-2*k)/16],[0,0,(16-2*k)/16,k/16,0,k/16],[0,0,k/16,(16-2*k)/16,0,k/16]]);

 (3.5.2)

 > B3:=matrix([[0,0,0,0,1,0],[0,1,0,0,0,0],[0,0,0,0,0,1],[0,(16-2*k)/16,0,0,k/16,k/16],[0,k/16,0,0,k/16,(16-2*k)/16],[0,k/16,0,0,(16-2*k)/16,k/16]]);

 (3.5.3)

Control points

 > P:=matrix([[0,0,1,0,0,0],[1/2,1,1,0,0,0],[1,0,1,0,0,0],[1/2,-1/8,1,1,0,0],[1/4,5/8,1,0,1,0],[3/4,1/2,1,0,0,1]]);

 (3.5.4)

 > IFSierp_k(7,P,8);

Animation

 > display(seq(display(IFSierp_k(6,P,i),title=cat(`k = `,i)),i=1..10),insequence=true);

4.Conclusions

In the worksheet we demonstrated how to introduce control points to Sierpinski triangle to obtain possibility of changing  its shape. We presented an ample collection of deformed Sierpinski triangles using different subdivision matrices. Of course, it is possible to introduce control points to other fractals. Also one can try to obtain similar results in 3D eg. for Sierpinski pyramid.

5.References

[1] R. Goldman, The Fractal Nature of B?zier Curves, Proceedings of the Geometric Modeling  and Processing, April 13-15, Beijing, China, 2004, pp.3-11.
[2] W. Kotarski, and A. Lisowska.,On Fractal Modeling of Contours, Maplesoft, 2005,

[3] W. Kotarski and A. Lisowska, Probabilistic Approach to Fractal Modeling of Shapes,  Maplesoft, 2005, http:/www.maplesoft.com/applications/app_center_view.aspx?AID=1657.
[4] W. Kotarski and A. Lisowska, Fractal Rendering of 3D Patches, Maplesoft 2006,
http://www.maplesoft.com/applications/app_center_view.aspx?AID=1955.

[5] W. Kotarski and A. Lisowska, Fractal Teapot from Utah, Maplesoft 2006, http://www.maplesoft.com/applications/app_center_view.aspx?AID=1956.
[6] W. Kotarski and A. Lisowska, On B?zier-Fractal Modeling of 2D Shapes, International Journal of Pure and Applied Mathematics, vol. 24, no. 1, 2005, pp.123-134.
[7] W. Kotarski and A. Lisowska, Chaikin's Approach to Fractal Modeling of 2D Contours, Proceedings of EUROCON 2005, Belgrade, Nov. 21-24, 2005, pp. 21-24.
[8] W. Kotarski and A. Lisowska, Fractal Rendering of 3D Shapes, Proceedings of IECON'06, Paris, Nov. 8-10, 2006, pp. 3391-3396.
[9] S. Schaefer, D.Levin and R. Goldman, Subdivision Schemes and Attractors,  Eurographics Symposium on Geometry Processing, 2005, pp. 171-180.

Legal Notice: The copyright for this application is owned by the author(s). Neither Maplesoft nor the author are responsible for any errors contained within and are not liable for any damages resulting from the use of this material. This application is intended for non-commercial, non-profit use only. Contact the author for permission if you wish to use this application in for-profit activities.