0% found this document useful (0 votes)
7 views2 pages

HTree Recursion Problem

The document describes the construction of an H-tree, a fractal pattern resembling the letter 'H', using recursion. At each level, a new H is drawn with reduced dimensions, and the process continues until the desired level is reached. Visualization can be achieved using the matplotlib package to connect the points of the H shapes.

Uploaded by

rudra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views2 pages

HTree Recursion Problem

The document describes the construction of an H-tree, a fractal pattern resembling the letter 'H', using recursion. At each level, a new H is drawn with reduced dimensions, and the process continues until the desired level is reached. Visualization can be achieved using the matplotlib package to connect the points of the H shapes.

Uploaded by

rudra
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

H-Tree

A fractal is an infinitely repeated pattern that is self-similar across


different scales. Let us now construct a fractal called an H-tree with the
help of a computer. As the name suggests, it is called H-tree because it
has a basic motif of an H-like shape

To begin, and at level 1, we draw an H with points A, B, C, D, E, F, O where


O is the center point. The length of CD equals to that of AE and BF. Next,
at level 2, we draw a new H pattern with A, B, E, F as the center points,
respectively. And the side length of this new H pattern is reduced by half.
And the pattern continues.

Due to this repeated nature, we can leverage recursion to draw H-trees on


a computer. The recursion stops when the desired level is achieved. Inside
the recursion function, we can keep track of the coordinates of points A, B,
C, D, E, F, and O, which are calculated using a length parameter, and
update the coordinates values upon a change of the level. For
visualization, we can use the matplotlib package to draw a line to connect
two points. The amount by which the length is reduced is controlled by the
factor parameter. Here, the default value of factor is 4, i.e., reduce the
length by half at each iteration.
OUTPUT-

You might also like