import java.io.*; class bezierellipse { /* * 16.11.2002 Urs Oswald osurs@bluewin.ch * erzeugt Datei "ellipse.tex" * ueberschreibt allanfalls vorhandene Datei dieses Namens * Ellipse wird aus 8 quadratischen Bezierkurven zusammengesetzt * Gebrauch: java bezierellipse [u [v [a [b [phi]]]]] */ static double[] uvabp = new double[5]; static double[] xx = new double[16]; static double[] yy = new double[16]; static double sc45 = .5f * Math.sqrt(2); static{ // Einheitskreis uvabp[0] = 0.0; // u = 0 uvabp[1] = 0.0; // v = 0 uvabp[2] = 1.0; // a = 1 uvabp[3] = 1.0; // b = 1 uvabp[4] = 0.0; // phi = 0 } public static void main(String[] args) { /* * args[0], args[1]: Mittelpunkt (u, v) * args[2], args[3]: Halbachsen a, b * args[4]: Rotationswinkel phi in Grad * */ double[] xy; for(int i=0;i<5;i++) // Aufgrund des Arguments aendern: if(args.length > i) // Mittelpunkt (u,v) uvabp[i] = Double.parseDouble(args[i]); // Halbachsen a, b und Rotation p String str = "% Ellipse:"; str += " u = " + uvabp[0]; str += " v = " + uvabp[1]; str += " a = " + uvabp[2]; str += " b = " + uvabp[3]; str += " phi = " + uvabp[4] + " Grad"; uvabp[4] = Math.PI*uvabp[4]/180; // Rotationswinkel in Radian xx[0] = 1; yy[0] = 0; // P0 xx[1] = 1; yy[1] = Math.sqrt(2) - 1; // P1 for(int i=1;i<8;i++) { // Berechnung der Punkte P2,...,P15 double phi = i * Math.PI / 4; // des Einheitskreises xy = rotate(xx[0], yy[0], phi); xx[2*i] = xy[0]; yy[2*i] = xy[1]; xy = rotate(xx[1], yy[1], phi); xx[2*i+1] = xy[0]; yy[2*i+1] = xy[1]; } for(int i=0;i<16;i++) { // Streckung, Rotation, Verschiebung xx[i] = xx[i] * uvabp[2]; // x-Streckung yy[i] = yy[i] * uvabp[3]; // y-Streckung xy = rotate(xx[i], yy[i], uvabp[4]); // Rotation xx[i] = xy[0] + uvabp[0]; // Translation (u, 0) yy[i] = xy[1] + uvabp[1]; // Translation (0, v) } for(int i=0;i<15;i+=2) str+="\n\\qbezier" +punkt(i)+punkt(i+1)+punkt((i+2)%16); // Anfuegen der 8 Zeilen File outfile = new File("ellipse.tex"); try { outfile.createNewFile(); // in "ellipse.tex" schreiben FileWriter out = new FileWriter(outfile.getPath(), false); out.write(str); out.close(); } catch(IOException e) { } } static double[] rotate(double x, double y, double phi) { /* * phi im Bogenmass */ double[] xy = new double[2]; xy[0] = x * Math.cos(phi) - y * Math.sin(phi); xy[1] = x * Math.sin(phi) + y * Math.cos(phi); return xy; } static String runde(double t) { String s = ""; int T = (int)(Math.round(10000 * t)); double d = T/10000.0; s = String.valueOf(d); return s; } static String punkt(int i) { String s; s="(" + runde(xx[i]) + ", " + runde(yy[i]) + ")"; return s; } }