File Exchange

image thumbnail

Sierpinski ball

version 4.0 (76.4 KB) by Mathworlds
Function to compute, display, and save the Sierpinski ball (fractal sponge) based on the regular octahedron


Updated 18 Nov 2020

From GitHub

View Version History

View license on GitHub

Please first check the examples tab (.mlx doc) here on the right for a complete description.

Once downloaded, typewrite 'doc Sierpinski_ball' or 'help Sierpinski_ball' in Matlab console for support.

To benefit from the file documentation attached, be sure to download the file, not to just copy and paste it.

N.B. : level 0 corresponds to the volumic mesh of the unit ball (radius = 1).

Cite As

Mathworlds (2021). Sierpinski ball (, GitHub. Retrieved .

Comments and Ratings (3)


Color rendering used for this cover image is radius based, i.e. by computing each vertex distance to the origin : C = sqrt(sum(V.^2,2)); trisurf(T,V(:,1),V(:,2),V(:,3),C); colormap('jet');


Default maximum number of iterations and sampling steps (nb_max_it) set to 7. Increase it line 84.


A function to compute a Sierpinski ball. Giving the resulting sets of vertices and triangles, it is almost 3D printing ready. Just have to write them in a .ply file for instance. The fractal object thereby created is a fractal sponge.

The algorithm principle is based on the projection of the Sierpinski triangular faces of a regular octahedron on the surface of the unitary sphere.

It is available for 3D printing in my Sculpteo online shop at iteration #3 :

NB : function sample_triangle isincluded, but may also be found independently here :

You may also have a look at some additional views here :

Tip : from nb_iterations = 3, and if using write_ply.m you struggle with displaying the set out of Matlab [...] try to replace in the file header "uchar ushort" by "uint8 uint32" this may help ;-)

MATLAB Release Compatibility
Created with R2019b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!