QuadratQuiz
Solution
- Draw a square with width N
- Cut of a rectangular stripe at the right
- Move that stripe to the center of the resulting rest rectangle
- Draw a circle around the corners of the inner rectangle
- Turn the inner rectangle along the circle, so that the upper right corner is located where the upper left corner has been.
- If the width of the cut was correct, all corners will be positioned on the resulting outer rectangle.
- Well. That was a well-done cut off. How would a cut to small look like?
- ... and to big ...
- Now let's introduce some names:
Note: the Image is now vertical flipped, but because of symetry that's without special meaning.
- N:= The width and height of the square. N shows up again as falling angular length of the stripe.
- c:= width of cut. (look first to the c on the right. c like cut. I moved it to the center, there is the c again.
Another c is foud by rotating the inner rectangle, the top-line of triangle D2.
- a:= (N-2c)/2 = N/2 - c
Since c was moved to the middle of the resulting square: {(0,0), (2a+c, 0), (2a+c, N), (0,N)}, the remainder after cutting the stripe,
there must be equal space to the left and to the right of the stripe.
- b:= is the height of the resulting triangle in the lower eastside.
- y:= is the height of the resulting triangle in the upper eastside.
- D2:= is this yellow rectangle.
- D1:= is the red rectangle above
- Now let's start the real math:
- N=1
- We are only interested in relations, so let's define the length of the whole square as 1.
That's allowed, since we only deal with lengths.
Imagine we measure with centimeters vs. inches or dots.
The numbers will change, but the relations are constant.
- c=?
- Let's not forget, what we're fighting for. c is the searched item.
- a=1/2 - c
- That's allmost the definition of a.
- N = b + y
- Both hights of the triangles are N (=1) in Sum.
- N²=(a + c)² + y²
- Phythagoras for the red triangle.
We replace N:=1
1² = (a + c)² + y²
1 = (a + c)² + y²
Well: a + c = N/2 let's use that knowledge:
1 = (1/2)² + y²
1 = (1/4) + y²
3/4 = y²
y = √(3/4)
- c²=a² + b²
- Phythagoras for the yellow triangle.
From above we insert a:=1/2 - c
c²=(1/2 - c)² + b²
We isolate b²
c² - (1/2 - c)² = b²
Well (x-y)² = x² - 2xy + y², we replace:
c² - ((1/2)² - 2*1/2c + c²) = b²
c² - ((1/2)² - c + c²) = b²
Since x - (y + z) = x - y - z:
c² - (1/2)² + c - c ² = b²
c² vanisches - that's comfortable!
- (1/2)² + c = b²
- (1/4) + c = b²
c = b² + (1/4)
- Combine the last two results and the observation b + y = 1 from above:
-
b = 1 - y
y = √(3/4)
c = b² + 1/4
c = (1 - y)² + 1/4
c = 1² - 2y + y² + 1/4
c = 1 - 2y + y² + 1/4
c = 1 + 1/4 - 2y + y²
c = 1 + 1/4 - 2(√(3/4) + 3/4
c = 1 + 1/4 + 3/4 - 2(√(3/4)
c = 2 - 2√(3/4)
c = 2 - 2√(3)/√(4)
c = 2 - 2√(3)/2
c = 2 - √(3)
- c = 2 - √(3)
-
Solution
- c ≈ 0.26795 if you prefer to have it decimal.
- To generate a quick drawing with nearly fitting Integer-Values use N=15 and c=4
- The Program to create the drawings which are the base for the drawings here uses N=480 and c=128 (which should be about 128.62).
Here is the program-listing which helped me, solving the diversion.
import java.util.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
interface Drawable
{
public void draw (Graphics g);
}
class Quadrat implements Drawable
{
private int x, y, w, h;
private int cut = 0;
private java.util.List elements;
public Quadrat (int x, int y, int w, int h)
{
this.x = x;
this.y = y;
this.w = w;
this.h = h;
elements = new ArrayList ();
elements.add (this);
}
public void clear ()
{
elements.clear ();
elements.add (this);
}
public void draw (Graphics g)
{
g.setColor (Color.BLACK);
g.drawRect (x, y, w, h);
g.setColor (Color.WHITE);
g.fillRect (x+1, y+1, w-2, h-2);
}
public void paint (Graphics g)
{
for (Drawable elem : elements)
{
elem.draw (g);
}
}
public void cut (int c)
{
cut = c;
elements.add (new Drawable ()
{
final int ix = x;
final int iy = y;
final int xi = w - cut;
final int ha = h;
public void draw (Graphics g)
{
g.setColor (Color.RED);
g.drawRect (ix, iy, xi, ha);
}
});
}
class P
{
public int x, y;
public P () { x = 0; y = 0;}
public P (int c, int r) { x = c; y = r;}
int distance (P p2)
{
int dx = p2.x - x;
int dy = p2.y - y;
return (int) Math.sqrt (dx * dx + dy * dy);
}
}
public void center ()
{
final P center = new P ();
center.y = y + (h/2);
center.x = x + ((w-cut)/2);
final P diagLio = new P (x, y);
final P diagReu = new P (x + (w-cut), y + h);
/*
*/
final P mitte = new P (center.x - (cut/2), y);
elements.add (new Drawable ()
{
public void draw (Graphics g)
{
/*
diag:
*/
g.setColor (Color.BLACK);
g.drawLine (diagLio.x, diagLio.y, diagReu.x, diagReu.y);
g.drawLine (diagLio.x, diagReu.y, diagReu.x, diagLio.y);
g.setColor (new Color (255, 0, 0, 128));
g.fillRect (mitte.x, mitte.y, cut, h);
}
});
}
public void circle ()
{
final P mitte = new P (x + ((w-cut)/2), y + (h/2));
// final P mitte = new P (center.x - (cut/2), y + h/2);
final P lio = new P (mitte.x - (cut/2), y);
final int radius = mitte.distance (lio);
elements.add (new Drawable ()
{
public void draw (Graphics g)
{
g.setColor (new Color (0, 255, 0, 128));
g.fillOval (mitte.x-radius, mitte.y-radius, 2*radius, 2*radius);
}
});
}
public void kreise ()
{
final P mitte = new P (x + ((w-cut)/2), y + (h/2));
final P lio = new P (mitte.x - (cut/2), y);
final int radius = mitte.distance (lio);
int dx = (x + w - cut) - mitte.x;
int dy = (int) Math.sqrt (radius * radius + dx * dx);
elements.add (new Drawable ()
{
public void draw (Graphics g)
{
g.setColor (Color.BLACK);
g.drawOval (mitte.x - (cut/2), y-(cut), 2*cut, 2*cut);
g.drawOval (mitte.x - (cut/2) - (cut), y + h - cut, 2*cut, 2*cut);
}
});
}
public void poly ()
{
final P mitte = new P (x + ((w-cut)/2), y + (h/2));
final P lio = new P (mitte.x - (cut/2), y);
final int radius = mitte.distance (lio);
int dx = (x + w - cut) - mitte.x;
int dy = (int) Math.sqrt (radius * radius + dx * dx);
Polygon p = new Polygon ();
p.addPoint (mitte.x + (cut/2), y);
p.addPoint (mitte.x + dx, (mitte.y + dy) - h);
p.addPoint (lio.x, y + h);
// p.addPoint (x, y + h - (dy - mitte.y) - y);
p.addPoint (x, h - (dy - mitte.y));
final Polygon poly = p;
elements.add (new Drawable ()
{
public void draw (Graphics g)
{
g.setColor (Color.BLACK);
g.drawPolygon (poly);
}
});
}
public void values ()
{
final P mitte = new P (x + ((w-cut)/2), y + (h/2));
// final P mitte = new P (center.x - (cut/2), y + h/2);
final P lio = new P (mitte.x - (cut/2), y);
final int radius = mitte.distance (lio);
int dx = (x + w - cut) - mitte.x;
int dy = (int) Math.sqrt (radius * radius + dx * dx);
System.out.println ("x = " + x);
System.out.println ("y = " + y);
System.out.println ("w = " + w);
System.out.println ("h = " + h);
System.out.println ("cut= " + cut);
System.out.println ("mitte.x = " + mitte.x);
System.out.println ("mitte.y = " + mitte.y);
System.out.println ("radius = " + radius);
System.out.println ("radius = " + radius);
System.out.println ("dx = " + dx);
System.out.println ("dy = " + dy);
}
}
class CanvasPanel extends JPanel
{
private Quadrat q; // = new Quadrat (50, 50, 240*2, 240 * 2);
public CanvasPanel (Quadrat q)
{
this.q = q;
}
public void paint (Graphics g)
{
super.paint (g);
q.paint (g);
}
}
/**
QuadraturDesKreises
@author Stefan Wagner
@date Fr Apr 21 21:55:55 CEST 2006
*/
public class QuadraturDesKreises extends JFrame implements ActionListener
{
private static final String progname = "QuadraturDesKreises 0.1";
private JTextField x;
private CanvasPanel mitte;
private JButton jb;
private Quadrat q = new Quadrat (150, 50, 240*2, 240 * 2);
/** */
public QuadraturDesKreises (String sx)
{
super (progname);
JPanel mainpanel = new JPanel ();
mainpanel.setLayout (new BorderLayout ());
this.getContentPane ().add (mainpanel);
JPanel nord = new JPanel ();
nord.setLayout (new BoxLayout (nord, BoxLayout.LINE_AXIS));
nord.add (new JLabel (" cut: "));
x = new JTextField (sx);
nord.add (x);
mitte = new CanvasPanel (q);
JPanel sued = fillPanelWithButtons (new String [] {"cut", "center", "circle", "arcs", "poly", "values", "clear", "paint", "exit"});
mainpanel.add (nord, BorderLayout.NORTH);
// mainpanel.add (jtfb, BorderLayout.EAST);
mainpanel.add (mitte, BorderLayout.CENTER);
mainpanel.add (sued, BorderLayout.SOUTH);
setSize (240*3, 240*3);
setLocation (100, 100);
setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
setVisible (true);
q.cut (Integer.parseInt (sx));
q.center ();
q.circle ();
q.kreise ();
q.poly ();
}
private JPanel fillPanelWithButtons (String [] names)
{
JPanel sued = new JPanel ();
sued.setLayout (new BoxLayout (sued, BoxLayout.LINE_AXIS));
for (String name : names)
{
JButton b = new JButton (name);
b.addActionListener (this);
sued.add (b);
}
return sued;
}
private void center ()
{
Toolkit tk = Toolkit.getDefaultToolkit ();
Dimension screen = tk.getScreenSize ();
Dimension d = getSize ();
setLocation ((screen.width - d.width) / 2, (screen.height - d.height) / 2);
}
public void actionPerformed (ActionEvent e)
{
String cmd = e.getActionCommand ();
if (cmd.equals ("cut"))
{
int cut = Integer.parseInt (x.getText ());
System.out.println ("cut: " + cut);
q.cut (cut);
mitte.updateUI ();
}
else if (cmd.equals ("center"))
{
q.center ();
mitte.updateUI ();
}
else if (cmd.equals ("circle"))
{
q.circle ();
mitte.updateUI ();
}
else if (cmd.equals ("arcs"))
{
q.kreise ();
mitte.updateUI ();
}
else if (cmd.equals ("poly"))
{
q.poly ();
mitte.updateUI ();
}
else if (cmd.equals ("values"))
{
q.values ();
}
else if (cmd.equals ("paint"))
{
int cut = Integer.parseInt (x.getText ());
System.out.println ("cut: " + cut);
q.cut (cut);
q.center ();
q.circle ();
q.kreise ();
q.poly ();
mitte.updateUI ();
System.out.println ("paint");
}
else if (cmd.equals ("clear"))
{
q.clear ();
mitte.updateUI ();
System.out.println ("clear");
}
else if (cmd.equals ("exit"))
{
System.out.println ("exit");
System.exit (0);
}
else
{
System.out.println ("unhandled");
}
}
/** */
public static void main (String args[])
{
String param = "128";
if (args.length == 1)
{
param = args[0];
}
new QuadraturDesKreises (param);
}
/** */
public static void usage ()
{
System.out.println ("Usage:\tjava QuadraturDesKreises [cutwidth]");
}
}