File Exchange

image thumbnail

Cubic base 3D Koch snowflake

version 5.0 (55.7 KB) by Mathworlds
Function to compute, display, and save the cubic base Koch snowflake, at any iteration / depth level. 3D printable ready option.


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 cubic_base_Koch_snowflake' or 'help cubic_base_Koch_snowflake' 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.

Cite As

Mathworlds (2021). Cubic base 3D Koch snowflake (, GitHub. Retrieved .

Comments and Ratings (7)


nb_it = 0 supposes to give the cube, but does'nt. Bug to solve.


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('hot'), shading interp;


Successfully tested for 3D printing. View and purchase here :


Write and save the vertex V and the face sets T (in a .ply or .stl file for instance) before sending it to your favorite 3D printing manufacturer. Such file format writer is not included here, but may easily be found on this file exchange.


Display function based on fill3 is still very greedy in cpu time as well as the number of faces very quickly grows. From nb_iterations >= 3 it becomes very slow to get a display. My advice is to save V and T, to write a file and then to use another 'way' to display it (with a more efficient 3D display engine).


New version is coming for 3D printing. Waiting for it, to prevent from creating non manifold edges, just comment lines relative to remove duplicated vertices and triangles (l114-116).


Function to compute and display a cubic based 3D Koch snowflake. 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.

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

- At iteration #3 :
- At iteration #4 :

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

/_!_\ Since the number of squares is multiplied by 18 from an iteration of the fractal to the following, and unless your computer has very powerful computation abilities, memory, and a very strong graphic card, you should not set nb_iterations parameter value greater than ~ 4 if you want to display the result (main part of the CPU time of this algorithm : nb squares loops on fill3 function)... or else, use your favourite mesh laboratory to do it ;-) /_!_\

Tip : from nb_iterations = 4, 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 should 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!