Java Reference
In-Depth Information
[ Note: The x and y to the left of each letter refer to the x -coordinate and y -coordinate of
that point, respectively. For instance, xA refers to the x -coordinate of point A , while yC re-
fers to the y -coordinate of point C . In our diagrams we denote the point by its letter, fol-
lowed by two numbers representing the x - and y -coordinates.]
A (6, 5)
B (30, 5)
Origin (0, 0)
Fig. 18.13 | “Lo feather fractal” at level 0.
To create this fractal, we also must find a point D that lies left of segment AC and cre-
ates an isosceles right triangle ADC . To calculate point D 's location, use the following for-
mulas:
xD = xA + (xC - xA) / 2 - (yC - yA) / 2 ;
yD = yA + (yC - yA) / 2 + (xC - xA) / 2 ;
We now move from level 0 to level 1 as follows: First, add points C and D (as in
Fig. 18.14). Then, remove the original line and add segments DA , DC and DB . The
remaining lines will curve at an angle, causing our fractal to look like a feather. For the
next level of the fractal, this algorithm is repeated on each of the three lines in level 1. For
each line, the formulas above are applied, where the former point D is now considered to
be point A , while the other end of each line is considered to be point B . Figure 18.15 con-
tains the line from level 0 (now a dashed line) and the three added lines from level 1.
We've changed point D to be point A , and the original points A , C and B to B1 , B2 and B3 ,
respectively. The preceding formulas have been used to find the new points C and D on
each line. These points are also numbered 1-3 to keep track of which point is associated
with each line. The points C1 and D1 , for instance, represent points C and D associated
with the line formed from points A to B1 . To achieve level 2, the three lines in Fig. 18.15
are removed and replaced with new lines from the C and D points just added. Figure 18.16
shows the new lines (the lines from level 2 are shown as dashed lines for your conve-
nience). Figure 18.17 shows level 2 without the dashed lines from level 1. Once this pro-
cess has been repeated several times, the fractal created will begin to look like one-half of
a feather, as shown in the output of Fig. 18.19. We'll present the code for this application
shortly.
 
 
Search WWH ::




Custom Search