the golden ladder
TRANSCRIPT
The Golden Ladder
By
Weixin Wu
Submitted to the Board of Mathematics/Computer Science
School of Natural and Social Sciences
In partial fulfillment of the requirements
For the degree of Bachelor of Arts
Purchase College
State University of New York
May 2015
Sponsor: Irina Shablinsky
Second Reader: Knarik Tunyan
Table of ContentsAbstract.......................................................................................................................................................3
1. Introduction to the Golden Ladder..................................................................................4
2. Recursive Properties of the Golden Ladder.................................................................8
2.1 Theorem 1.................................................................................................................................8
2.2 Theorem 2...............................................................................................................................10
2.3 Theorem 3...............................................................................................................................12
3. More about the Golden Ladder.........................................................................................14
3.1 Spiral in the Golden Ladder.........................................................................................14
3.2 Find the End Point of the Golden Ladder.............................................................15
3.3 The Golden Ladder in Three Dimension................................................................16
4. A “Processing” Simulation of the Golden Ladder...................................................17
4.1 How the Program Works?..............................................................................................17
4.2 Program Output..................................................................................................................19
4.3 How to Use this Program...............................................................................................21
4.4 Why Writing this Program?..........................................................................................21
5. Results.............................................................................................................................................21
6. References.....................................................................................................................................22
7. Appendix.........................................................................................................................................23
2
Abstract
In this work, a new Euclidean structure the Golden Ladder is introduced. The Golden
Ladder was first created in visual software by applying the Golden Ratio to the diameters of
tangent circles. For this work three recursive properties of the circumference and area have
been proven, and a 2D simulation of the Golden Ladder was written in processing. The Golden
Ladder has been expanded to the third dimension, and it is possible to expand the definition to
the nth dimension. The volume will be the property of interest in the third dimension. Additional
interesting properties have been found for the Golden Ladder and are currently under
investigation.
3
1. Introduction to the Golden Ladder
I am going to introduce some facts, properties and applications of the Golden Ratio
before I get into the Golden Ladder. The Golden Ratio is one of the most famous irrational
numbers. Also known as the divine proportion, golden mean, or golden section. The term
“golden section” was first used in the textbook Die Reine Elementar-Mathematik in 1835 by
Martin Ohm. [9] Two quantities a and b are in the Golden Ratio if their ratio is same as the ratio
between the sum and the larger quantity. As shown in the equation below and figure 1 for a >
b.
a+ba
=ab=φ
The lower case Greek letter phi (φ) is used to represent the Golden Ratio. Phi (φ) is one
of the roots of the quadratic equation x2 – x – 1. The exact value of the Golden Ratio is (√5 + 1) /
2 or ca 1.6180339887… expressed as an infinite decimal number. The upper case Greek letter
phi (φ) is used to represent the reciprocal of the Golden Ratio; the exact value is (√5 -1) / 2 or ca
0.6180339887… expressed as an infinite decimal fraction.
4
Figure 1 The Golden Ratio
There is an interesting relation between the Golden Ratio and the Fibonacci sequence.
[1][4] Fibonacci sequence is an integer sequence that start with 1 and 1, and each subsequent
number is the sum of the previous two. It’s known that the limit of the ratio of two consecutive
Fibonacci numbers is φ as shown in the equation below. φ can also be expressed as exact
trigonometric formulas including2 cos( π5 ), 12 sec (2 π5
) and 12csc ( π
10).
limn→∞
Fn+ 1
Fn=φ
φ is the “worst” real number for rational approximation because its continued fraction
representation as shown in the equation below.
φ=[ 1,1,1,1,… ]
φ=1+ 1
1+ 1
1+ 11+…
φ can also be represented in terms of a nested radical as shown below.
φ=√1+√1+√1+…
The Golden Ratio is given by the series
φ=138
+∑n=0
∞ (−1 )n+1(2n+1) !(n+2) !n !42n+3
5
The Golden Ratio is widely used from Renaissance artists of the 1500’s to modern
graphic designers as exemplified by the painting of Mona Lisa by Da Vinci to the logo design of
both Apple iPhone and Toyota. Now I know why the apple logo looks so nice and became
famous quickly. The Golden Ratio has a great influence on our everyday life without noticing. As
a conclusion, use the Golden Ratio to design your logo if you want to start a new business.
The Golden Rectangle shown in Fig 2 above was constructed by laying out Golden Ratio
rectangles, and then drawing the quarter-circle arcs in the square part of each rectangle.
Similarly a Golden Triangle may be drawn and appropriately divided and a spiral may also be
drawn as shown in Fig 3. The Golden Ladder is similar to the Golden Rectangle and the Golden
Triangle. I am going to introduce this new Euclidean geometric structure by applying the Golden
Ratio to the diameter of each adjacent circles. The structure is shown below in Fig 4, and I
called it the Golden Ladder.
6
Figure 2 Golden Rectangle Figure 3 Golden Triangle
I am going to walk you through the process of construction of a Golden Ladder. Draw two
circles, C1 with the diameter d1= φ and C2 with the diameter d2= φφ tangent to each other. Add another
circle C3 with the diameter d3= φφ2 tangent to both C1 and C2. Note that d1 > d2 > d3. The circles C1, C2, and
C3 are mutually tangent. Connect the centers of the three circles to create a triangle. This triangle is the
first step of the Golden Ladder. The fourth circle C4 with the diameter d4= φφ3 must be placed tangent to
both C2 and C3. Again connect the centers of the circles C2, C3, and C4 to get the second triangle. Keep
going. Eventually you will get a sequence of circles C1 , C2,...,Cn,... with the diameters d1, d2, ... , dn, ...,
where dn= φφn-1, and each of the three circles Cn, Cn+1, Cn+2 are mutually tangent. You will also get a
sequence of triangles T1, T2,..., Tn,... . This sequence is called the Golden Ladder.
7
Figure 4 The Golden Ladder
2. Recursive Properties of the Golden Ladder
I want to introduce some recursive properties of the Golden Ladder. The first recursive
property is that all triangles in the Golden Ladder are similar triangle, the ratio between
corresponding sides of any triangle in the Golden Ladder and its next triangle is the Golden
Ratio (φ).
2.1 Theorem 1
1) All triangles in the Golden Ladder are similar.
2) The ratio of corresponding sides of triangles Tn and Tn+1 is the Golden Ratio φ.
Proof. Let the two triangles in figure 5 and 6 be Tn and Tn+1, which are taken from the
Golden Ladder. Triangle Tn was surrounded by three circles with diameters φn, φn+1 and φn+2,
triangle Tn+1 was surrounded by three circles with diameters φn+1, φn+2 and φn+3.
8
Figure 6 n+1th Triangle (Tn+1) in Golden LadderFigure 5 nth Triangle (Tn) in Golden Ladder
Sn
Sn+1
Sn+2 Sn+2
Sn+3
Sn+4
Tn Tn+1
The three sides of Tn are Sn, Sn+1 and Sn+2, and the three sides of Tn+1 are Sn+2, Sn+3 and Sn+4. Both
triangles share the same side Sn+2 as we see in Fig 4 & 5. In order to prove this recursive
property, we need to prove the following:
Table 1 Length of each side
S nS n+2
= S n+1S n+3
= S n+2S n+4
= φ
Side Length
Sn (φn + φn+1 )/2
Sn+1 (φn + φn+2 )/2
Sn+2 (φn+1 + φn+2 )/2
Sn+3 (φn+1 + φn+3 )/2
Sn+4 (φn+2 + φn+3 )/2
The table above shows the length of each side, calculated using the diameter of the
circle. Now we can calculate Sn / Sn+2, Sn+1 / Sn+3 and Sn+2 / Sn+4.
S nS n+2
= (ϕn+ϕn+1)/2(ϕn+1+ϕn+2)/2
=(1+ϕ)/2(ϕ+ϕ2)/2
= 1+ϕϕ+ϕ2=
1+ϕϕ∗(1+ϕ)
=1ϕ=φ
S n+1S n+3
= (ϕn+ϕn+2)/2(ϕn+1+ϕn+3)/2
=(1+ϕ2) /2(ϕ+ϕ3)/2
=1+ϕ2
ϕ+ϕ3 =1+ϕ2
ϕ∗(1+ϕ2)=1ϕ=φ
S n+2S n+4
= (ϕn+1+ϕn+2)/2
(ϕn+2+ϕn+3)/2=
(1+ϕ) /2(ϕ+ϕ2) /2
= 1+ϕϕ+ϕ2 =
1+ϕϕ∗(1+ϕ )
= 1ϕ=φ
S nS n+2
= φ (1)
9
Thus, we proved the first recursive property.
The second recursive property is related to the area of the triangles. The ratio between
the area of any triangle in the Golden Ladder and its next triangle is the Golden Ratio square
(φ2).
2.2 Theorem 2
1) The ratio between the area of Tn and Tn+1 is φ2.
Proof. I will use figure 5 and figure 6 again for this proof. The area of Tn is An and the
area of Tn+1 is An+1. Let’s find the area of Tn and Tn+1 using Heron’s Formula, Pn represents the
perimeter.
P n = (Sn + S n+1+S n+2 ¿ /2
A n=√P n∗(P n−Sn )∗(P n−S n+1 )∗( P n−S n+2 )
P n+1 = (Sn+2 + S n+3+S n+4 ¿ /2
A n+1=√P n+1∗(P n+1−S n+2 )∗(P n+1−S n+3 )∗(P n+1−S n+4 )
Next, we will divide An by An+1 to find the ratio:
A nA n+1
= √P n∗( P n−S n )∗(P n−S n+1 )∗(P n−S n+2 )
√P n+1∗(P n+1−S n+2 )∗(P n+1−Sn+3 )∗(P n+1−S n+4 )
10
A nA n+1
=√P nP n+1
∗(P n−S n )
(P n+1−S n+2 )∗(P n−S n+1 )
(P n+1−S n+3 )∗(P n−S n+2 )
(P n+1−S n+4 )
Next, we will be using equation (1) above for substitution to find the value of each term
above, including PnPn+1 , (Pn−Sn )
(Pn+1−Sn+2 ), (Pn−Sn+1 )
(Pn+1−Sn+3 ), and
(Pn−Sn+2 )(Pn+1−Sn+4 )
.
P nP n+1
=(S n + S n+1+S n+2 ¿ /2 ¿(S n+2 + S n+3+S n+4 ¿
/2¿=φ∗Sn+2 +φ∗S n+3+φ∗S n+4 S n+2 + S n+3+S n+4
=φ∗(S n+2 + S n+3+S n+4)S n+2 + S n+3+S n+4
=φ
(P n−S n )(P n+1−S n+2 )
=(S n + S n+1+S n+2 −S n ¿/2 ¿(S n+2 + S n+3+S n+4 −Sn+2 ¿
/2¿= S n+1+S n+2S n+3+S n+4
=φ∗Sn+3+φ∗S n+4 S n+3+Sn+4
=φ∗(S n+3+S n+4)S n+3+S n+4
=φ
(Pn−Sn+1 )( Pn+1−Sn+3 )
∧(Pn−Sn+2 )
(Pn+1−Sn+4 )are evaluated usinga similar procedure ¿ (Pn−Sn )
( Pn+1−Sn+2 ) above
which also equal to φ.
Now, we can substitution back to calculate the ratio between An and An+1,
A nA n+1
=√φ∗φ∗φ∗φ
A nA n+1
=φ2 (2)
11
The third recursive property is also involves areas, but in this case the global area, the
sum of all triangle areas not the local area, will be used. The ratio between the area of any
triangle in the Golden Ladder and the total area of all triangles after this triangle is equal to the
Golden Ratio.
2.3 Theorem 3
1) The ratio between area of Tn and total area of Tn+1, Tn+2,…, Tm is the Golden Ratio φ as
m goes to infinite.
Proof. Our goal is to find the ratio below, where An is the area starting triangle and Am is
the area ending triangle as m goes to infinite for m > n:
AnAn+1+An+2+…+Am−1+Am
Let’s starting by calculating the total area from Tn to Tm as m increases without limit.
A n+A n+1+A n+2+…+A m-1+A m
Next, let’s substitute all area using equation 2:
A n+A n /φ2+A n /φ4+…+A n /φ2 (m−1)+A n /φ2m
Let r = 1 / ϕ2, then the expression becomes:
A n+A n∗r+A n∗r2+…+A n∗rm−1+A n∗rm
This is a geometric series and r < 1, so the total area becomes:
12
An∗11−r
Next let’s subtract An from the above expression, because we don’t want to include the
area of the first triangle:An∗11−r
−An
Then, we divide An by the expression above, the result is equivalent to the ratio we
wanted:An
An∗11−r
−An
=An
An+1+An+2+…+Am−1+Am
Let’s simplify the expression:
AnAn∗11−r
−An
=An
An∗11−r
−An∗1−r
1−r
=AnAn∗r1−r
=1−rr
Finally, we substitute the definition of r into the result:
1−rr
=1− 1φ2
1φ2
=φ2−1=φ
An
∑i=n+1
m
Ai
=φ(3)
3. More about the Golden Ladder
3.1 Spiral in the Golden Ladder
13
There is another version of the Golden Ladder. From the Golden Ladder in figure 4, flip
all triangles into its pervious triangle starting at the second triangle. The result Golden Ladder is
shown in figure 7. In this version, it’s possible to draw a spiral that connect the center of all
tangent circles which is similar to the Golden Rectangle.
14
Figure 7 embedded Golden Ladder
3.2 Find the End Point of the Golden Ladder
In figure 8, three line can be drawn in the Golden Ladder to find the end point. The first
line would be drawing a straight line that passes through the intersections of every two
adjacent circles. The second line is also a straight line, which is tangent to all circles that on the
top portion of the Golden Ladder. And the third line is similar to the second line, but in this
case, it will be tangent to all circles on the bottom portion of the Golden Ladder. The
intersection of these three lines would be the end point, which is where the circles are
approaching to in the Golden Ladder.
15
Figure 8 End point of the Golden Ladder
3.3 The Golden Ladder in Three Dimension
The Golden Ladder may be presented in three dimension by applying the Golden Ratio
to the diameters of tangent spheres. I am calling it the Golden Tower (figure 9). This idea of
dimensional increase suggests that it is possible to extend the concept to the nth dimension
after completing some research on the three dimensional case. Instead of finding the ratio
between the areas of triangles, the ratio between the volumes of the tetrahedron would be our
interest. A tetrahedron can be constructed by connecting the centers of any four consecutive
spheres.
16
Figure 9 The Golden Tower
4. A “Processing” Simulation of the Golden Ladder
4.1 How the Program Works?
Processing is a java based virtual design programming language, which is a free software
that provides a great environment to simulate simple 2D and 3D objects. Drawing tangent
circles is very easy in real life, but to calculate the center of the next tangent circle with precise
diameter would not be as easy as you think. The program was written based on the math
showing below.
17
Figure 10 processing sketch
In the processing sketch, start with the two tangent circles. In order to find the center of
the next circle, we will need to setup two distances. Let the center of the first circle be X1, Y1,
and the distance from the first circle to the third circle be D1. For the second circle, the center
be X2, Y2, distance be D2. The unknown would be the center of the third center X3, Y3. We will
setup and solve equations below before writing the program.
√(X3−X 1)2+(Y 3−Y 1)2=D1 (4)
√ (X 3−X 2 )2+ (Y 3−Y 2 )2=D 2 (5)
18
Two unknowns and two equations, very simply, right? You can try to solve it or think
about it before I show you my approach. My procedure would surprise you and involves solving
a quadratic equation. This makes sense because quadratic equations can have two solutions
and there are two possible circles that can be tangent to the two pervious circles.
1. Square both sides of equation 4 and 5, and find the difference between them.
(X 3−X 2 )2+ (Y 3−Y 2 )2−(X 3−X1 )2−(Y 3−Y 1)2=D 22−D12
2. By a little simplification, we obtain the equation below,
2 (X 1−X 2 ) X 3+2 (Y 1−Y 2 )Y 3=D 22−D 12−X 22−Y 22−X 12−Y 12
3. Denote by temp = D22−D12−X22−Y 22−X 12−Y 12
2,simplify, and the expression
becomes:
(X 1−X2 )X 3+(Y 1−Y 2 )Y 3=temp
Solving for X3 gives us,
X 3=temp−(Y 1−Y 2 )Y 3(X 1−X 2 )
Now substitute X3 into equation 4,
√( temp−(Y 1−Y 2 )Y 3(X1−X 2 )
−X 1)2
+ (Y 3−Y 1 )2=D1
4. Square the equation above and transform it to a standard quadratic equation a(Y3)2 +
b(Y3) + c = 0. Solve the quadratic equation and substitute each of the two values of Y3 into
19
equations (4) or (5). That would give us two corresponding X3 values. Below is snippet of code
showing the calculation of the quadratic coefficient a, b and c.
float a = pow( (y1 - y2), 2) / pow( ( x1 - x2), 2) + 1;
float b = -2 * (y1 - y2) * temp / pow ( ( x1 - x2), 2) - 2 * y1 + 2 * x1 * (y1 - y2) / (x1 - x2);
float c = pow( temp, 2) / pow ( (x1 - x2), 2) + pow(x1, 2) + pow(y1, 2) - pow(distance1, 2) - 2 * x1
* temp / (x1 - x2);
The above process would repeat for each tangent circle. The program runs very well,
that mean the math approach is one correct way to solve the problem, I am sure there is a way
to solve this problem much easier.
4.2 Program Output
There are two modes you can select after you start the program. Mode 1 is for the
Golden Ladder and Mode 2 is for embedded Golden Ladder.
20
Figure 11 Mode 1 of the Golden Ladder simulation
4.3 How to Use this Program
You can drag the Golden Ladder with your mouse, and rotate it by pressing the
rotation icon. Press space to add circle to the Golden Ladder, and press ‘b’ on your
keyboard to remove circle from the Golden Ladder. Avoid to delete circle while there
are two circles left. Press 1 or 2 to switch mode. Press the ‘up arrow’ key to zoom in and
the ‘down arrow’ key to zoom out.
4.4 Why Writing this Program?
From this program, we can find out the exact location or the center of each
circle. These new data of the Golden Ladder would give us more understanding of the
structure and its properties. Also these information would be helpful for solving future
problem.
5. Results
In this work, a new Euclidean structure the Golden Ladder is introduced. Three recursive
properties have been proven, which relative to the area and circumference of triangles within
the Golden Ladder. And this structure has been expanded to the three dimension. More
properties have been found and will be proven in the near future.
21
6. References[1] Alberto, Fiorenza. Giovanni, Vincenzi. From Fibonacci Sequence to the Golden Ratio. Journal
of Mathematics Hindawi Publishing Corporation(2013).
[2] Pamela, M. Pallett. Stephen, Link. Kang, Lee. New “golden” ratios for facial beauty. Vision
Research 50 (2010) 149-154.
[3]. “Debunking The Myth Of Apple’s ‘Golden Ratio’ ”. fastcodesign.com. Mark, Wilson. June 4,
2013.
[4] “Golden Ratio”. mathworld.wolfram.com. Eric, Weisstein. May 4, 2015.
[5] "Golden Ratio in
Geometry." http://www.cut-the-knot.org/do_you_know/GoldenRatio.shtml. Bogomolny, A. n.d.
[6] Boyer, C. B. History of Mathematics. New York: Wiley, p. 56, 1968.
[7] Brown, D. The Da Vinci Code. New York: Doubleday, 2003.
[8] Coxeter, H. S. M. “The Golden Section, Phyllotais, and Whythoff’s Game.” Scripta
Mathematica 19, 135-143, 1953.
[9] Martin Ohm. Die Reine Elementar-Mathematik. 1835.
22
7. AppendixThe program consists of two classes Circle and Triangle other than the main code.
Circle class
class Circle
{
float x, y, d, r, g, b;
Circle(float x, float y, float d, color r, color g, color b)
{
this.x = x;
this.y = y;
this.d = d;
this.r = r;
this.g = g;
this.b = b;
}
void display()
{
fill(r, g, b);
noStroke();
ellipse(x, y, d, d);
}
}
Triangle class
23
class Triangle
{
float x1, y1, x2, y2, x3, y3;
Triangle(float x1, float y1, float x2, float y2, float x3, float y3)
{
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.x3 = x3;
this.y3 = y3;
}
void display()
{
stroke(0);
line(x1, y1, x2, y2);
line(x2, y2, x3, y3);
line(x1, y1, x3, y3);
}
}
Main code
ArrayList<Circle> Circles = new ArrayList<Circle>();
24
ArrayList<Triangle> Triangles = new ArrayList<Triangle>();
ArrayList<Circle> Circles2 = new ArrayList<Circle>();
ArrayList<Triangle> Triangles2 = new ArrayList<Triangle>();
float phi = 1.618034;
float phi2 = phi - 1;
float tempPhi = phi * phi2;
float tempPhi2 = tempPhi;
float ratio;
int biggerCircle = 0, smallerCircle = 1;
int biggerCircle2 = 0, smallerCircle2 = 1;
boolean press = false;
float px, py, tranX, tranY, rotateAngle = 0;
PImage rotate1, rotate2;
float rotate2X, rotate2Y, rotate1X, rotate1Y;
float zoom = 1;
int mode = 1;
float mode1X, mode1Y, mode2X, mode2Y;
float count1 = 0, count2 = 0;
void setup()
{
size(displayWidth - 50, displayHeight - 100);
smooth();
25
textSize(30);
textAlign(CENTER, CENTER);
rotate1 = loadImage("rotate1.png");
rotate2 = loadImage("rotate2.png");
rotate2X = width/20;
rotate2Y = height*9/10;
rotate1X = width/7;
rotate1Y = height*9/10;
mode1X = width*8.8/10;
mode1Y = height/10;
mode2X = width*9.5/10;
mode2Y = height/10;
ratio = 150;
Circles.add(new Circle(phi * ratio, phi * ratio, phi * ratio * 2, (int)random(255), (int)random(255), (int)random(255)));
Circles.add(new Circle(phi * ratio + ratio, (tempPhi + phi * 2) * ratio - ratio/5, tempPhi * ratio * 2, (int)random(255), (int)random(255), (int)random(255)));
Circles2.add(new Circle(phi * ratio, phi * ratio, phi * ratio * 2, (int)random(255), (int)random(255), (int)random(255)));
Circles2.add(new Circle(phi * ratio + ratio, (tempPhi + phi * 2) * ratio - ratio/5, tempPhi * ratio * 2, (int)random(255), (int)random(255), (int)random(255)));
}
26
void draw()
{
background(255);
image(rotate2, rotate2X, rotate2Y);
image(rotate1, rotate1X, rotate1Y);
imageMode(CENTER);
stroke(0);
strokeWeight(2);
fill(0);
text("Mode:", width*4/5, height/10);
if(mode == 1)
{
fill(65, 247, 78);
}
else
{
fill(255);
}
ellipse(width*8.8/10, height/10, width/20, width/20);
fill(0);
text("1", width*8.8/10, height/10);
if(mode == 2)
{
27
fill(65, 247, 78);
}
else
{
fill(255);
}
ellipse(width*9.5/10, height/10, width/20, width/20);
fill(0);
text("2", width*9.5/10, height/10);
scale(zoom);
if(press)
{
tranX = mouseX - px;
tranY = mouseY - py;
}
translate(tranX, tranY);
if(mousePressed)
{
if(dist(mouseX, mouseY, rotate2X, rotate2Y) < 50)
{
rotateAngle -= 0.01;
}
28
if(dist(mouseX, mouseY, rotate1X, rotate1Y) < 50)
{
rotateAngle += 0.01;
}
}
rotate(rotateAngle);
translate(-phi * ratio, -phi * ratio);
if(mode == 1)
{
for(int i = 0; i < Circles.size(); i++)
{
Circles.get(i).display();
}
for(int i = 0; i < Triangles.size(); i++)
{
Triangles.get(i).display();
}
}
else
{
for(int i = 0; i < Circles2.size(); i++)
{
Circles2.get(i).display();
29
}
for(int i = 0; i < Triangles2.size(); i++)
{
Triangles2.get(i).display();
}
}
}
void keyPressed()
{
if(key == ' ')
{
if(mode == 1)
{
count1++;
float d1 = Circles.get(biggerCircle).d;
float d2 = Circles.get(smallerCircle).d;
float d3 = d2 * phi2;
float distance1 = (d1 + d3)/2;
float distance2 = (d2 + d3)/2;
float x1 = Circles.get(biggerCircle).x;
float x2 = Circles.get(smallerCircle).x;
float y1 = Circles.get(biggerCircle).y;
float y2 = Circles.get(smallerCircle).y;
float temp = pow(distance2, 2) - pow(distance1, 2);
30
temp = temp + pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2);
temp = temp / 2;
float a = pow( (y1 - y2), 2) / pow( ( x1 - x2), 2) + 1;
float b = -2 * (y1 - y2) * temp / pow( ( x1 - x2), 2) - 2 * y1 + 2 * x1 * (y1 - y2) / (x1 - x2);
float c = pow( temp, 2) / pow ( (x1 - x2), 2) + pow(x1, 2) + pow(y1, 2) - pow(distance1, 2) - 2 * x1 * temp / (x1 - x2);
float yRoot1 = ( -b + sqrt( pow(b, 2) - 4 * a * c) ) / (2 * a);
float yRoot2 = ( -b - sqrt( pow(b, 2) - 4 * a * c) ) / (2 * a);
float xRoot1, xRoot2;
if(count1%2 == 1){
xRoot1 = -sqrt( pow(distance2, 2) - pow( (yRoot1 - y2), 2)) + x2;
xRoot2 = sqrt( pow(distance2, 2) - pow( (yRoot2 - y2), 2)) + x2;
}
else
{
xRoot1 = sqrt( pow(distance2, 2) - pow( (yRoot1 - y2), 2)) + x2;
xRoot2 = -sqrt( pow(distance2, 2) - pow( (yRoot2 - y2), 2)) + x2;
}
float realRootY, realRootX;
31
if( (yRoot1 + xRoot1) > (yRoot2 + xRoot2))
{
realRootY = yRoot1;
realRootX = xRoot1;
}
else
{
realRootY = yRoot2;
realRootX = xRoot2;
}
tempPhi = tempPhi * phi2;
Circles.add(new Circle(realRootX, realRootY, tempPhi * ratio * 2, (int)random(255), (int)random(255), (int)random(255)));
Triangles.add(new Triangle(x1, y1, x2, y2, realRootX, realRootY));
println("root1: " + xRoot1 + ", " + yRoot1);
println("root2: " + xRoot2 + ", " + yRoot2);
biggerCircle += 1;
32
smallerCircle += 1;
}
}
if(key == ' ')
{
if(mode == 2)
{
count2++;
float d1 = Circles2.get(biggerCircle2).d;
float d2 = Circles2.get(smallerCircle2).d;
float d3 = d2 * phi2;
float distance1 = (d1 + d3)/2;
float distance2 = (d2 + d3)/2;
float x1 = Circles2.get(biggerCircle2).x;
float x2 = Circles2.get(smallerCircle2).x;
float y1 = Circles2.get(biggerCircle2).y;
float y2 = Circles2.get(smallerCircle2).y;
float temp = pow(distance2, 2) - pow(distance1, 2);
temp = temp + pow(x1, 2) - pow(x2, 2) + pow(y1, 2) - pow(y2, 2);
temp = temp / 2;
float a = pow( (y1 - y2), 2) / pow( ( x1 - x2), 2) + 1;
float b = -2 * (y1 - y2) * temp / pow( ( x1 - x2), 2) - 2 * y1 + 2 * x1 * (y1 - y2) / (x1 - x2);
33
float c = pow( temp, 2) / pow ( (x1 - x2), 2) + pow(x1, 2) + pow(y1, 2) - pow(distance1, 2) - 2 * x1 * temp / (x1 - x2);
float yRoot1 = ( -b + sqrt( pow(b, 2) - 4 * a * c) ) / (2 * a);
float yRoot2 = ( -b - sqrt( pow(b, 2) - 4 * a * c) ) / (2 * a);
float xRoot1, xRoot2;
if(count2%3 == 1){
xRoot1 = -sqrt( pow(distance2, 2) - pow( (yRoot1 - y2), 2)) + x2;
xRoot2 = sqrt( pow(distance2, 2) - pow( (yRoot2 - y2), 2)) + x2;
}
else
{
xRoot1 = sqrt( pow(distance2, 2) - pow( (yRoot1 - y2), 2)) + x2;
xRoot2 = -sqrt( pow(distance2, 2) - pow( (yRoot2 - y2), 2)) + x2;
}
tempPhi2 = tempPhi2 * phi2;
if(count2%3 == 0)
{
Circles2.add(new Circle(xRoot1, yRoot1, tempPhi2 * ratio * 2, (int)random(255), (int)random(255), (int)random(255)));
Triangles2.add(new Triangle(x1, y1, x2, y2, xRoot1, yRoot1));
34
}
else
{
Circles2.add(new Circle(xRoot2, yRoot2, tempPhi2 * ratio * 2, (int)random(255), (int)random(255), (int)random(255)));
Triangles2.add(new Triangle(x1, y1, x2, y2, xRoot2, yRoot2));
}
println("root1: " + xRoot1 + ", " + yRoot1);
println("root2: " + xRoot2 + ", " + yRoot2);
biggerCircle2 += 1;
smallerCircle2 += 1;
}
}
if(key == 'b')
{
if(mode == 1)
{
count1--;
biggerCircle -= 1;
smallerCircle -= 1;
35
tempPhi = tempPhi / phi2;
Circles.remove(Circles.get(Circles.size() - 1));
Triangles.remove(Triangles.get(Triangles.size() - 1));
}
else
{
count2--;
biggerCircle2 -= 1;
smallerCircle2 -= 1;
tempPhi2 = tempPhi2 / phi2;
Circles2.remove(Circles2.get(Circles2.size() - 1));
Triangles2.remove(Triangles2.get(Triangles2.size() - 1));
}
}
if(key == CODED)
{
if(keyCode == UP)
{
zoom += 0.2;
}
else if(keyCode == DOWN)
{
zoom -=0.2;
}
36
}
}
void mousePressed()
{
press = true;
px = mouseX - tranX;
py = mouseY - tranY;
println(mouseX + " " + mouseY);
if(dist(mouseX, mouseY, mode1X, mode1Y) < width/20)
{
mode = 1;
}
else if(dist(mouseX, mouseY, mode2X, mode2Y) < width/20)
{
mode = 2;
}
}
void mouseReleased()
{
press = false;
}
37