How to create a fractal tree?
Clash Royale CLAN TAG#URR8PPP
up vote
3
down vote
favorite
I want to create a fractal tree, using translation and rotation. Code below is working for one level, but when I try loop, it is not giving output. Code is given below:
threshold = 4;
L = 100;
While[
L > threshold,
line = Line[0, 0, 0, -L];
Graphics[
line,
Scale[#,
2/3, 0,
0] & /@ (Rotate[
Translate[line, 0, L], # Degree, 0, 0] & /@ -30,
30)]
L = L*0.67;
];
mathematical-optimization education mathematica-online
add a comment |Â
up vote
3
down vote
favorite
I want to create a fractal tree, using translation and rotation. Code below is working for one level, but when I try loop, it is not giving output. Code is given below:
threshold = 4;
L = 100;
While[
L > threshold,
line = Line[0, 0, 0, -L];
Graphics[
line,
Scale[#,
2/3, 0,
0] & /@ (Rotate[
Translate[line, 0, L], # Degree, 0, 0] & /@ -30,
30)]
L = L*0.67;
];
mathematical-optimization education mathematica-online
1
Related: 154213.
– Henrik Schumacher
Sep 2 at 12:09
add a comment |Â
up vote
3
down vote
favorite
up vote
3
down vote
favorite
I want to create a fractal tree, using translation and rotation. Code below is working for one level, but when I try loop, it is not giving output. Code is given below:
threshold = 4;
L = 100;
While[
L > threshold,
line = Line[0, 0, 0, -L];
Graphics[
line,
Scale[#,
2/3, 0,
0] & /@ (Rotate[
Translate[line, 0, L], # Degree, 0, 0] & /@ -30,
30)]
L = L*0.67;
];
mathematical-optimization education mathematica-online
I want to create a fractal tree, using translation and rotation. Code below is working for one level, but when I try loop, it is not giving output. Code is given below:
threshold = 4;
L = 100;
While[
L > threshold,
line = Line[0, 0, 0, -L];
Graphics[
line,
Scale[#,
2/3, 0,
0] & /@ (Rotate[
Translate[line, 0, L], # Degree, 0, 0] & /@ -30,
30)]
L = L*0.67;
];
mathematical-optimization education mathematica-online
asked Sep 2 at 11:20


BiSarfraz
625
625
1
Related: 154213.
– Henrik Schumacher
Sep 2 at 12:09
add a comment |Â
1
Related: 154213.
– Henrik Schumacher
Sep 2 at 12:09
1
1
Related: 154213.
– Henrik Schumacher
Sep 2 at 12:09
Related: 154213.
– Henrik Schumacher
Sep 2 at 12:09
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
5
down vote
accepted
ClearAll[next];
next[x1_, y1_, x2_, y2_] =
(
x1, y1, x2, y2 //
TranslationTransform[x2 - x1, y2 - y1] //
RotationTransform[# Pi/6, x2, y2] //
ScalingTransform[2/3 1, 1, x2, y2]
) & /@ -1, 1;
list = NestList[Join @@ next /@ # &, N@0, 0, 0, 1, 5];
Graphics[Line /@ list]
Nice, Thank you so very much @chyang.
– BiSarfraz
Sep 2 at 14:33
@BiSarfraz You are welcome.
– chyanog
Sep 3 at 6:25
add a comment |Â
up vote
6
down vote
I am not only new in Mathematica, but also new in Maths. I need a very simple approach
(This answer attempts to be a "reference answer" with relevant links.)
This has been discussed extensively in MSE and Mathematica blogs and demonstrations.
MSE:
How can I improve my code for drawing a tree?
L-System in Mathematica
Mathematica Journal:
- A New Method of
Constructing Fractals and
Other Graphics
- A New Method of
Demonstrations:
Fractal Trees
Radial FractalTree
FibonacciTree
Blogs:
Adventures into the Mathematical Forest of Fractal Trees.
Fractals at 4am
Thank you so much.
– BiSarfraz
Sep 2 at 14:25
@BiSarfraz You are welcome, good luck!
– Anton Antonov
Sep 2 at 14:28
add a comment |Â
up vote
3
down vote
The main issue with your code is that it's lacking a way to combine the different levels of the tree. Graphics
are not automatically printed, unless they are the final result of a computation.
The following code should get you started:
tree[L_, th_] /; L > th := With[
line = Line[0, 0, 0, -L],
line,
Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, L], # Degree, 0, 0] & /@ -30, 30)
]
tree[__] :=
tree[100, 10] // Graphics
The key ingredients are:
- Recursion of the
tree
function to combine the different parts. The termination condition is implemented usingCondition
(/;
) Rotate
,Scale
,Transform
can be arbitrarily nested, allowing for a clean specification of the nested levels
As you can see, the result is not correct yet (the lines are too short), but you should be able to easily fix that.
Thank you so much for making things easy.
– BiSarfraz
Sep 2 at 14:28
1
I have fixed it: line, Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, 0.67L], # Degree, 0, 0] & /@ -30, 30)} ]
– BiSarfraz
Sep 3 at 10:12
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
accepted
ClearAll[next];
next[x1_, y1_, x2_, y2_] =
(
x1, y1, x2, y2 //
TranslationTransform[x2 - x1, y2 - y1] //
RotationTransform[# Pi/6, x2, y2] //
ScalingTransform[2/3 1, 1, x2, y2]
) & /@ -1, 1;
list = NestList[Join @@ next /@ # &, N@0, 0, 0, 1, 5];
Graphics[Line /@ list]
Nice, Thank you so very much @chyang.
– BiSarfraz
Sep 2 at 14:33
@BiSarfraz You are welcome.
– chyanog
Sep 3 at 6:25
add a comment |Â
up vote
5
down vote
accepted
ClearAll[next];
next[x1_, y1_, x2_, y2_] =
(
x1, y1, x2, y2 //
TranslationTransform[x2 - x1, y2 - y1] //
RotationTransform[# Pi/6, x2, y2] //
ScalingTransform[2/3 1, 1, x2, y2]
) & /@ -1, 1;
list = NestList[Join @@ next /@ # &, N@0, 0, 0, 1, 5];
Graphics[Line /@ list]
Nice, Thank you so very much @chyang.
– BiSarfraz
Sep 2 at 14:33
@BiSarfraz You are welcome.
– chyanog
Sep 3 at 6:25
add a comment |Â
up vote
5
down vote
accepted
up vote
5
down vote
accepted
ClearAll[next];
next[x1_, y1_, x2_, y2_] =
(
x1, y1, x2, y2 //
TranslationTransform[x2 - x1, y2 - y1] //
RotationTransform[# Pi/6, x2, y2] //
ScalingTransform[2/3 1, 1, x2, y2]
) & /@ -1, 1;
list = NestList[Join @@ next /@ # &, N@0, 0, 0, 1, 5];
Graphics[Line /@ list]
ClearAll[next];
next[x1_, y1_, x2_, y2_] =
(
x1, y1, x2, y2 //
TranslationTransform[x2 - x1, y2 - y1] //
RotationTransform[# Pi/6, x2, y2] //
ScalingTransform[2/3 1, 1, x2, y2]
) & /@ -1, 1;
list = NestList[Join @@ next /@ # &, N@0, 0, 0, 1, 5];
Graphics[Line /@ list]
edited Sep 3 at 6:25
answered Sep 2 at 12:55
chyanog
6,75921544
6,75921544
Nice, Thank you so very much @chyang.
– BiSarfraz
Sep 2 at 14:33
@BiSarfraz You are welcome.
– chyanog
Sep 3 at 6:25
add a comment |Â
Nice, Thank you so very much @chyang.
– BiSarfraz
Sep 2 at 14:33
@BiSarfraz You are welcome.
– chyanog
Sep 3 at 6:25
Nice, Thank you so very much @chyang.
– BiSarfraz
Sep 2 at 14:33
Nice, Thank you so very much @chyang.
– BiSarfraz
Sep 2 at 14:33
@BiSarfraz You are welcome.
– chyanog
Sep 3 at 6:25
@BiSarfraz You are welcome.
– chyanog
Sep 3 at 6:25
add a comment |Â
up vote
6
down vote
I am not only new in Mathematica, but also new in Maths. I need a very simple approach
(This answer attempts to be a "reference answer" with relevant links.)
This has been discussed extensively in MSE and Mathematica blogs and demonstrations.
MSE:
How can I improve my code for drawing a tree?
L-System in Mathematica
Mathematica Journal:
- A New Method of
Constructing Fractals and
Other Graphics
- A New Method of
Demonstrations:
Fractal Trees
Radial FractalTree
FibonacciTree
Blogs:
Adventures into the Mathematical Forest of Fractal Trees.
Fractals at 4am
Thank you so much.
– BiSarfraz
Sep 2 at 14:25
@BiSarfraz You are welcome, good luck!
– Anton Antonov
Sep 2 at 14:28
add a comment |Â
up vote
6
down vote
I am not only new in Mathematica, but also new in Maths. I need a very simple approach
(This answer attempts to be a "reference answer" with relevant links.)
This has been discussed extensively in MSE and Mathematica blogs and demonstrations.
MSE:
How can I improve my code for drawing a tree?
L-System in Mathematica
Mathematica Journal:
- A New Method of
Constructing Fractals and
Other Graphics
- A New Method of
Demonstrations:
Fractal Trees
Radial FractalTree
FibonacciTree
Blogs:
Adventures into the Mathematical Forest of Fractal Trees.
Fractals at 4am
Thank you so much.
– BiSarfraz
Sep 2 at 14:25
@BiSarfraz You are welcome, good luck!
– Anton Antonov
Sep 2 at 14:28
add a comment |Â
up vote
6
down vote
up vote
6
down vote
I am not only new in Mathematica, but also new in Maths. I need a very simple approach
(This answer attempts to be a "reference answer" with relevant links.)
This has been discussed extensively in MSE and Mathematica blogs and demonstrations.
MSE:
How can I improve my code for drawing a tree?
L-System in Mathematica
Mathematica Journal:
- A New Method of
Constructing Fractals and
Other Graphics
- A New Method of
Demonstrations:
Fractal Trees
Radial FractalTree
FibonacciTree
Blogs:
Adventures into the Mathematical Forest of Fractal Trees.
Fractals at 4am
I am not only new in Mathematica, but also new in Maths. I need a very simple approach
(This answer attempts to be a "reference answer" with relevant links.)
This has been discussed extensively in MSE and Mathematica blogs and demonstrations.
MSE:
How can I improve my code for drawing a tree?
L-System in Mathematica
Mathematica Journal:
- A New Method of
Constructing Fractals and
Other Graphics
- A New Method of
Demonstrations:
Fractal Trees
Radial FractalTree
FibonacciTree
Blogs:
Adventures into the Mathematical Forest of Fractal Trees.
Fractals at 4am
edited Sep 2 at 15:06
Szabolcs
152k13415896
152k13415896
answered Sep 2 at 14:07
Anton Antonov
21.5k164107
21.5k164107
Thank you so much.
– BiSarfraz
Sep 2 at 14:25
@BiSarfraz You are welcome, good luck!
– Anton Antonov
Sep 2 at 14:28
add a comment |Â
Thank you so much.
– BiSarfraz
Sep 2 at 14:25
@BiSarfraz You are welcome, good luck!
– Anton Antonov
Sep 2 at 14:28
Thank you so much.
– BiSarfraz
Sep 2 at 14:25
Thank you so much.
– BiSarfraz
Sep 2 at 14:25
@BiSarfraz You are welcome, good luck!
– Anton Antonov
Sep 2 at 14:28
@BiSarfraz You are welcome, good luck!
– Anton Antonov
Sep 2 at 14:28
add a comment |Â
up vote
3
down vote
The main issue with your code is that it's lacking a way to combine the different levels of the tree. Graphics
are not automatically printed, unless they are the final result of a computation.
The following code should get you started:
tree[L_, th_] /; L > th := With[
line = Line[0, 0, 0, -L],
line,
Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, L], # Degree, 0, 0] & /@ -30, 30)
]
tree[__] :=
tree[100, 10] // Graphics
The key ingredients are:
- Recursion of the
tree
function to combine the different parts. The termination condition is implemented usingCondition
(/;
) Rotate
,Scale
,Transform
can be arbitrarily nested, allowing for a clean specification of the nested levels
As you can see, the result is not correct yet (the lines are too short), but you should be able to easily fix that.
Thank you so much for making things easy.
– BiSarfraz
Sep 2 at 14:28
1
I have fixed it: line, Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, 0.67L], # Degree, 0, 0] & /@ -30, 30)} ]
– BiSarfraz
Sep 3 at 10:12
add a comment |Â
up vote
3
down vote
The main issue with your code is that it's lacking a way to combine the different levels of the tree. Graphics
are not automatically printed, unless they are the final result of a computation.
The following code should get you started:
tree[L_, th_] /; L > th := With[
line = Line[0, 0, 0, -L],
line,
Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, L], # Degree, 0, 0] & /@ -30, 30)
]
tree[__] :=
tree[100, 10] // Graphics
The key ingredients are:
- Recursion of the
tree
function to combine the different parts. The termination condition is implemented usingCondition
(/;
) Rotate
,Scale
,Transform
can be arbitrarily nested, allowing for a clean specification of the nested levels
As you can see, the result is not correct yet (the lines are too short), but you should be able to easily fix that.
Thank you so much for making things easy.
– BiSarfraz
Sep 2 at 14:28
1
I have fixed it: line, Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, 0.67L], # Degree, 0, 0] & /@ -30, 30)} ]
– BiSarfraz
Sep 3 at 10:12
add a comment |Â
up vote
3
down vote
up vote
3
down vote
The main issue with your code is that it's lacking a way to combine the different levels of the tree. Graphics
are not automatically printed, unless they are the final result of a computation.
The following code should get you started:
tree[L_, th_] /; L > th := With[
line = Line[0, 0, 0, -L],
line,
Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, L], # Degree, 0, 0] & /@ -30, 30)
]
tree[__] :=
tree[100, 10] // Graphics
The key ingredients are:
- Recursion of the
tree
function to combine the different parts. The termination condition is implemented usingCondition
(/;
) Rotate
,Scale
,Transform
can be arbitrarily nested, allowing for a clean specification of the nested levels
As you can see, the result is not correct yet (the lines are too short), but you should be able to easily fix that.
The main issue with your code is that it's lacking a way to combine the different levels of the tree. Graphics
are not automatically printed, unless they are the final result of a computation.
The following code should get you started:
tree[L_, th_] /; L > th := With[
line = Line[0, 0, 0, -L],
line,
Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, L], # Degree, 0, 0] & /@ -30, 30)
]
tree[__] :=
tree[100, 10] // Graphics
The key ingredients are:
- Recursion of the
tree
function to combine the different parts. The termination condition is implemented usingCondition
(/;
) Rotate
,Scale
,Transform
can be arbitrarily nested, allowing for a clean specification of the nested levels
As you can see, the result is not correct yet (the lines are too short), but you should be able to easily fix that.
answered Sep 2 at 13:01


Lukas Lang
5,1531525
5,1531525
Thank you so much for making things easy.
– BiSarfraz
Sep 2 at 14:28
1
I have fixed it: line, Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, 0.67L], # Degree, 0, 0] & /@ -30, 30)} ]
– BiSarfraz
Sep 3 at 10:12
add a comment |Â
Thank you so much for making things easy.
– BiSarfraz
Sep 2 at 14:28
1
I have fixed it: line, Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, 0.67L], # Degree, 0, 0] & /@ -30, 30)} ]
– BiSarfraz
Sep 3 at 10:12
Thank you so much for making things easy.
– BiSarfraz
Sep 2 at 14:28
Thank you so much for making things easy.
– BiSarfraz
Sep 2 at 14:28
1
1
I have fixed it: line, Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, 0.67L], # Degree, 0, 0] & /@ -30, 30)} ]
– BiSarfraz
Sep 3 at 10:12
I have fixed it: line, Scale[#, 2/3, 0, 0] & /@ (Rotate[Translate[tree[0.67 L, th], 0, 0.67L], # Degree, 0, 0] & /@ -30, 30)} ]
– BiSarfraz
Sep 3 at 10:12
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f181095%2fhow-to-create-a-fractal-tree%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
Related: 154213.
– Henrik Schumacher
Sep 2 at 12:09