import java.io.*; class arc { static double[] xx; static double[] yy; static double r; public static void main(String[] args) { /* * Urs Oswald osurs@bluewin.ch, 18.11.2002 * Eingabe: x1 y1 x2 y2 x3 y3 r * schreibt arc.tex: LaTeX-Datei fuer Bogen * mit Radius r im Winkel P1-P2-P3 (Scheitel: P2) * ueberschreibt allfaellig schon vorhandene Datei desselben Namens */ if(args.length < 7) { System.out.println("Schreibt arc.tex für Bogen mit Radius r im Winkel P1-P2-P3"); System.out.println("Gebrauch: java arc x1 y1 x2 y2 x3 y3 r"); return; } String outstring = ""; double a, rot; double[] xy; xx = new double[4]; // P3: mittlerer (Kontroll-)Punkt yy = new double[4]; xx[1] = Double.parseDouble(args[0]); // P1 --> 1 yy[1] = Double.parseDouble(args[1]); xx[0] = Double.parseDouble(args[2]); // P2 --> 0 yy[0] = Double.parseDouble(args[3]); xx[2] = Double.parseDouble(args[4]); // P3 --> 2 yy[2] = Double.parseDouble(args[5]); r = Double.parseDouble(args[6]); // r outstring += "% arc\n"; outstring += "% P1 = ("+xx[1]+"/"+yy[1]+")"; outstring += " P2 = ("+xx[0]+"/"+yy[0]+")"; outstring += " P3 = ("+xx[2]+"/"+yy[2]+")"; outstring += " r = " + r ; xx[1] = xx[1] - xx[0]; yy[1] = yy[1] - yy[0]; // Verschiebung des Scheitels xx[2] = xx[2] - xx[0]; yy[2] = yy[2] - yy[0]; // in den Ursprung a = Math.sqrt(xx[1]*xx[1] + yy[1]*yy[1]); // Einheitsvektor (xx[1], yy[1]) xx[1] = xx[1] / a; yy[1] = yy[1] / a; a = Math.sqrt(xx[2]*xx[2] + yy[2]*yy[2]); // Einheitsvektor (xx[2], yy[2]) xx[2] = xx[2] / a; yy[2] = yy[2] / a; rot = 0.5*( angle(xx[1], yy[1]) // rot: Neigungswinkel der +angle(xx[2], yy[2])); // Winkelhalbierenden xy = rotate(xx[1], yy[1], -rot); // Rotation: Ziel ist xx[1] = xy[0]; yy[1] = xy[1]; // Symmetrie zur x-Achse xy = rotate(xx[2], yy[2], -rot); xx[2] = xy[0]; yy[2] = xy[1]; xx[3] = 1 / xx[1]; yy[3] = 0; // qbezier-Punktfolge: P1 P3 P2 for(int i=1;i<4;i++) { xy = rotate(xx[i], yy[i], rot); // Zurueckrotieren xx[i] = r * xy[0] + xx[0]; // Strecken und Zurueckschieben yy[i] = r * xy[1] + yy[0]; } outstring += "\n\\qbezier" + punkt(1)+punkt(3)+punkt(2); // Anfuegen der 3 Punkte File outfile = new File("arc.tex"); // in Datei schreiben try{ FileWriter out = new FileWriter(outfile.getPath(), false); // ueberschreibt allfaellig schon out.write(outstring); // bestehende Datei "arc.tex" out.close(); } catch(IOException e) { } } static double angle(double x, double y) { /* * Resultat: Radian, 0 <= phi < 2PI */ double phi = 0.0; double a = Math.sqrt(x*x + y*y); x = x/a; y = y/a; phi = Math.acos(x); if(y<0) phi = 2*Math.PI-phi; return phi; } 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; } }