Die Mandelbrot-Menge, im allgemeinen Sprachgebrauch oft auch "Apfelmännchen" genannt, ist ein Fraktal, das in der Chaostheorie eine bedeutende Rolle spielt. Es wurde 1980 von Benoît Mandelbrot erstmals computergrafisch dargestellt und untersucht. Die mathematischen Grundlagen dafür wurden bereits 1905 von dem französischen Mathematiker Pierre Fatou erarbeitet.
sicherlich nützlich bei der lösung sind folgende dokumente
- http://www.thegeek.de/src/fraktal.phps
- http://www.htwm.de/~if99/grundstudium/java_pr/Praktikum14.htm
- http://www.mathematische-basteleien.de/apfelmaennchen.htm (mit weiterer literaturliste)
Alles anzeigen
sicherlich nützlich bei der lösung sind folgende dokumente
- http://www.thegeek.de/src/fraktal.phps
- http://www.htwm.de/~if99/grundstudium/java_pr/Praktikum14.htm
- http://www.mathematische-basteleien.de/apfelmaennchen.htm (mit weiterer literaturliste)
Quellcode
- import java.io.*;
- import java.io.IOException;
- import java.util.Formatter;
- /**
- *
- * @author Torben Brodt
- * @version 1.0
- *
- * <p />Fraktale Geometrie & Komplexe Zahlen: Mandelbrot
- */
- public class A1_Mandelbrot {
- /**
- * @param args
- * 0 => dateiname
- * 1 => xmin
- * 2 => xmax
- * 3 => length
- * 4 => dimension
- * 5 => maxIt
- */
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- double xmin=0.0, xmax=0.0, length=0.0;
- int dimension=0,maxIt=0;
- String dateiname="";
- try {
- // Imaginärteil
- xmin = Double.parseDouble(args[1]); //-2
- xmax = Double.parseDouble(args[2]); //-2
- length = Double.parseDouble(args[3]); //4
- // Realteil
- dimension = Integer.parseInt(args[4]); //400
- maxIt = Integer.parseInt(args[5]); //254
- dateiname = args[0]; //mandelbrot.pgm
- } catch(Exception e) {
- error_msg("Fehler bei der Eingabe");
- }
- //Andere Fehler abfangen
- if(dimension <= 0) error_msg("Fehler: Dimension <= 0");
- if(length <= 0) error_msg("Fehler: Laenge <= 0");
- if(maxIt <= 0) error_msg("Fehler: Grauwert <= 0");
- int draw[][] = new int[dimension][dimension];
- //double d_dimension = (double)dimension; //perfomanter als in der schleife zu casten?
- // x & y => Imaginärteil in Mandelfeldern (z.B. -2 bis 2)
- // i & j => Realteil in Pixeln (z.B. 0 bis 400)
- double x=xmin;
- for (int i=0 ; i<dimension ; i++) {
- double y=xmax;
- for (int j=0 ; j<dimension ; j++) {
- draw[j][i] = greytone(x, y, maxIt);
- y += length / dimension;
- }
- x += length / dimension; //Schrittweite = Quotient von Länge(Imaginär) und Bildgröße(Real)
- }
- try {
- pgm(draw, dateiname, dimension, maxIt);
- } catch(Exception e) {
- System.out.println("Fehler");
- }
- System.out.print("Das Mandelbrot wurde erstellt");
- }
- /**
- * Draws a PGM Picture
- * @param draw -> Array
- * @param filename -> Dateiname
- * @param maxIt -> Maximaler Grauwert (für den Header)
- * @throws IOException
- */
- static void pgm(int[][] draw, String filename, int dimension, int maxIt) throws IOException
- {
- Formatter output = new Formatter(new File(filename));
- // Header schreiben
- output.format("P2\n#"+filename+"\n"+draw[0].length+" "+draw.length+"\n"+maxIt+"\n");
- // Array schreiben
- for(int i=dimension-1; i>=0; i--) { //umgekehrt steht "es" auf den Fuessen
- for(int point : draw[i])
- output.format(point+" ");
- output.format("\n");
- }
- output.close();
- }
- /**
- * Returns the Greytone
- * @param xmin = imaginärteil - x-Koordinate
- * @param xmax = imaginärteil - y-Koordinate
- * @param maxIt
- * @return
- */
- static int greytone(double xmin, double xmax, int maxIt) {
- double old_x, old_y, new_x=0, new_y=0;
- int greytone = maxIt; //von 0 oder von 1?
- do {
- old_x = new_x;
- old_y = new_y;
- // x_1 = x_0^2 - y_0^2 + x_1 ~> (1)
- new_x = (old_x * old_x) - (old_y * old_y) + xmin;
- // y_1 = 2 * x_0 * y_0 + y_1 ~> (1)
- new_y = 2 * (old_x * old_y) + xmax;
- greytone--;
- // Betrag = sqrt(a_1^2 + b_1^2)
- // Bedingung = Betrag^2 < 4
- if ((new_x*new_x) + (new_y*new_y) >= 4)
- return greytone;
- } while (greytone > 0);
- return greytone;
- }
- //Quellen: (1) http://www.mathematische-basteleien.de/apfelmaennchen.htm
- static void error_msg(String text)
- {
- System.out.println(text);
- System.exit(-1);
- }
- }