From 67ce8d154f63aafa1271d0d40644d8ef72aade1a Mon Sep 17 00:00:00 2001 From: Justin Dretvic Date: Mon, 15 Jun 2020 21:39:47 +0200 Subject: [PATCH] Updated Code Snippets MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ein neuer Ansatz für den Start- und den Endpunkt wurde implementiert --- src/app/_0_Constants.java | 2 +- src/app/_0_Matrices.java | 10 ++-- .../_1_GeoAnimation_DrawingOperations.java | 51 +++++++++++++------ src/app/_2_Methods.java | 18 +++++-- 4 files changed, 54 insertions(+), 27 deletions(-) diff --git a/src/app/_0_Constants.java b/src/app/_0_Constants.java index d993678..7205988 100644 --- a/src/app/_0_Constants.java +++ b/src/app/_0_Constants.java @@ -37,6 +37,6 @@ public class _0_Constants { public static double[][] NULLVECTOR_MINUS_Z = new double[][] { {0}, {0}, {-RADIUS}, {1} }; // Simulation - public static double VELOCITY = 10; + public static double VELOCITY = 10; // Die Geschwindigkeit sollte Pi betragen } diff --git a/src/app/_0_Matrices.java b/src/app/_0_Matrices.java index 804d6f7..3e4509e 100644 --- a/src/app/_0_Matrices.java +++ b/src/app/_0_Matrices.java @@ -35,13 +35,13 @@ public class _0_Matrices { } public static double[][] START = new double[][] { - {_0_Constants.RADIUS * Math.cos( Math.toRadians(45) ) * Math.cos( Math.toRadians(230) )}, - {_0_Constants.RADIUS * Math.cos( Math.toRadians(45) ) * Math.sin( Math.toRadians(230) )}, + {_0_Constants.RADIUS * Math.cos( Math.toRadians(45) ) * Math.cos( Math.toRadians(180) )}, + {_0_Constants.RADIUS * Math.cos( Math.toRadians(45) ) * Math.sin( Math.toRadians(180) )}, {_0_Constants.RADIUS * Math.sin( Math.toRadians(45) ) } }; public static double[][] END = new double[][] { - {_0_Constants.RADIUS * Math.cos( Math.toRadians(-35) ) * Math.cos( Math.toRadians(30) )}, - {_0_Constants.RADIUS * Math.cos( Math.toRadians(-35) ) * Math.sin( Math.toRadians(30) )}, - {_0_Constants.RADIUS * Math.sin( Math.toRadians(-35) ) } + {_0_Constants.RADIUS * Math.cos( Math.toRadians(-45) ) * Math.cos( Math.toRadians(30) )}, + {_0_Constants.RADIUS * Math.cos( Math.toRadians(-45) ) * Math.sin( Math.toRadians(30) )}, + {_0_Constants.RADIUS * Math.sin( Math.toRadians(-45) ) } }; } diff --git a/src/app/_1_GeoAnimation_DrawingOperations.java b/src/app/_1_GeoAnimation_DrawingOperations.java index 7b3456a..d989df8 100644 --- a/src/app/_1_GeoAnimation_DrawingOperations.java +++ b/src/app/_1_GeoAnimation_DrawingOperations.java @@ -17,6 +17,7 @@ import com.sun.org.apache.xalan.internal.templates.Constants; import utils.ApplicationTime; import java.util.Collections; +import java.util.Scanner; @SuppressWarnings({ "serial", "unused" }) public class _1_GeoAnimation_DrawingOperations extends JPanel{ @@ -38,9 +39,12 @@ public class _1_GeoAnimation_DrawingOperations extends JPanel{ // double[][] drehMatrix = Meth.drehBewegung(); ArrayList WegX = new ArrayList(); ArrayList WegY = new ArrayList(); + double newTime; double distance = Meth.startToEnd(); double differencePhi = Meth.getPhi(_0_Matrices.END) - Meth.getPhi(_0_Matrices.START); double differenceTheta = Meth.getTheta(_0_Matrices.END) - Meth.getTheta(_0_Matrices.START); + boolean planeLanded = false; + boolean firstPoint = true; // DRAWING OPERATIONS IN HERE @Override protected void paintComponent(Graphics g) { @@ -70,6 +74,8 @@ public class _1_GeoAnimation_DrawingOperations extends JPanel{ g2d.drawString(String.valueOf(breitengrad)+"°", Meth.getCoords(text, "x")-15, Meth.getCoords(text, "y")); } + Meth.startToEnd(); + // Drawing Coordinate-System g2d.setColor(Color.RED); g2d.drawLine(Meth.getCoords(_0_Constants.ZENTRUM, "x"), Meth.getCoords(_0_Constants.ZENTRUM, "y"), Meth.getCoords(_0_Constants.NULLVECTOR_X, "x"), Meth.getCoords(_0_Constants.NULLVECTOR_X, "y") ); @@ -111,10 +117,8 @@ public class _1_GeoAnimation_DrawingOperations extends JPanel{ // Zeichnen der Umrissellipse g.setColor(Color.MAGENTA); for(double parameter = 0; parameter < 360 ; parameter+=0.25) { -// double winkelTheta = Math.toRadians(180); -// double winkelPhi = Math.toRadians(-220); - double winkelTheta = Math.toRadians(90); - double winkelPhi = Math.toRadians(0); + double winkelTheta = Math.toRadians(180); + double winkelPhi = Math.toRadians(-220); double[][] kreis = Meth.umrissellipse(winkelPhi,winkelTheta,Math.toRadians(parameter)); g2d.drawLine((int)(kreis[0][0]*_0_Constants.RADIUS+_0_Constants.START_X), (int)(kreis[1][0]*_0_Constants.RADIUS+_0_Constants.START_Y), (int)(kreis[0][0]*_0_Constants.RADIUS+_0_Constants.START_X), (int)(kreis[1][0]*_0_Constants.RADIUS+_0_Constants.START_Y)); } @@ -129,28 +133,43 @@ public class _1_GeoAnimation_DrawingOperations extends JPanel{ // Wegpunkt & Streckenverlauf Zeichnen g2d.setColor(Color.CYAN); - double[][] bewegung = Meth.drehBewegung(Math.toRadians(time)); + System.out.println("time: " + time); +// Scanner scanner = new Scanner(System.in); +// String s = scanner.next(); +// if(firstPoint) { +// double[][] bewegung = Meth.drehBewegung(Math.toRadians(0)); +// firstPoint = false; +// } else if (firstPoint = false) + if(time < 1) + newTime = time; + double[][] bewegung = Meth.drehBewegung(Math.toRadians(time - newTime)); + System.out.println("actual time: " + (time - newTime) ); - WegX.add(Meth.getCoords(Meth.normVector(bewegung), "x")); - WegY.add(Meth.getCoords(Meth.normVector(bewegung), "y")); - for(int i = 0; i < WegX.size(); i++) - g2d.drawLine(WegX.get(i), WegY.get(i), WegX.get(i), WegY.get(i)); +// WegX.add(Meth.getCoords(Meth.normVector(bewegung), "x")); +// WegY.add(Meth.getCoords(Meth.normVector(bewegung), "y")); g2d.setColor(Color.CYAN); double differencePhi = Meth.getPhi(_0_Matrices.END) - Meth.getPhi(bewegung); if (differencePhi < 0) differencePhi *= (-1); - System.out.println("Phi: " + differencePhi); +// System.out.println("Phi: " + differencePhi); double differenceTheta = Meth.getTheta(_0_Matrices.END) - Meth.getTheta(bewegung); if (differenceTheta < 0) differenceTheta *= (-1); - System.out.println("Theta: " + differenceTheta); - if(differencePhi >= 0.5 && differenceTheta >= 0.5) - g2d.setColor(Color.RED); - else +// System.out.println("Theta: " + differenceTheta); + for(int i = 0; i < WegX.size(); i++) + g2d.drawLine(WegX.get(i), WegY.get(i), WegX.get(i), WegY.get(i)); +// System.out.println(planeLanded); +// if(differencePhi >= 0.5 && differenceTheta >= 0.5 && planeLanded == false) { + if(time < Meth.zeitGrenze() - newTime ) { + WegX.add(Meth.getCoords(Meth.normVector(bewegung), "x")); + WegY.add(Meth.getCoords(Meth.normVector(bewegung), "y")); g2d.setColor(Color.CYAN); - g2d.fillOval(Meth.getCoords(Meth.normVector(bewegung), "x")-(_0_Constants.RADIUS_KUGEL), Meth.getCoords(Meth.normVector(bewegung), "y")-(_0_Constants.RADIUS_KUGEL), _0_Constants.DIAMETER_KUGEL, _0_Constants.DIAMETER_KUGEL); - + g2d.fillOval(Meth.getCoords(Meth.normVector(bewegung), "x")-(_0_Constants.RADIUS_KUGEL), Meth.getCoords(Meth.normVector(bewegung), "y")-(_0_Constants.RADIUS_KUGEL), _0_Constants.DIAMETER_KUGEL, _0_Constants.DIAMETER_KUGEL); + } else { + planeLanded = true; + } + //g2d.setColor(Color.RED); } } \ No newline at end of file diff --git a/src/app/_2_Methods.java b/src/app/_2_Methods.java index 0e807a7..02f8394 100644 --- a/src/app/_2_Methods.java +++ b/src/app/_2_Methods.java @@ -1,5 +1,7 @@ package app; +//import java.util.Arrays; + public class _2_Methods { // Gibt X oder Y Koordinate aus einem normierten Vektor zurück, abhängig vom String Parameter @@ -67,8 +69,11 @@ public class _2_Methods { protected double[][] umrissellipse(double _phi, double _theta, double _parameter){ double [][] Länge = new double [][] {{0},{Math.cos(_parameter)},{Math.sin(_parameter)}}; double [][] zwischenergebnis_1 = matrixMultiplikation(_0_Matrices.M_JavaNormalized_Umriss, _0_Matrices.DrehungZ(_phi)); +// System.out.println("1: " + Arrays.deepToString(zwischenergebnis_1)); double [][] zwischenergebnis_2 = matrixMultiplikation(zwischenergebnis_1, _0_Matrices.DrehungY(_theta)); +// System.out.println("2: " + Arrays.deepToString(zwischenergebnis_2)); double [][] zwischenergebnis_3 = matrixMultiplikation(zwischenergebnis_2, Länge); +// System.out.println("3: " + Arrays.deepToString(zwischenergebnis_3)); return zwischenergebnis_3; } @@ -106,11 +111,14 @@ public class _2_Methods { // Berechnet die Entfernung vom Start bis zum Endpunkt protected double startToEnd() { - double winkel; - winkel = _0_Matrices.START[0][0] * _0_Matrices.END[0][0] + _0_Matrices.START[1][0] * _0_Matrices.END[1][0] + _0_Matrices.START[1][0] * _0_Matrices.END[1][0] ; - winkel /= Math.sqrt( Math.pow(_0_Matrices.START[0][0], 2) + Math.pow(_0_Matrices.START[1][0], 2) + Math.pow(_0_Matrices.START[2][0], 2)) * Math.sqrt( Math.pow(_0_Matrices.END[0][0], 2) + Math.pow(_0_Matrices.END[1][0], 2) + Math.pow(_0_Matrices.END[2][0], 2) ); - winkel = Math.acos(winkel); - return winkel; + return (Math.acos( ( skalarprodukt (_0_Matrices.START,_0_Matrices.END) ) / ( betrag(_0_Matrices.START) * betrag(_0_Matrices.END) ) ) ) * _0_Constants.RADIUS; +// System.out.println("winkel: " + Math.toDegrees(winkel) ); + } + + protected double zeitGrenze() { + System.out.println("zeitGrenze: " + (startToEnd() / (Math.PI * _0_Constants.VELOCITY))); + return (startToEnd() / (Math.PI * _0_Constants.VELOCITY)); +// return (startToEnd() / (_0_Constants.VELOCITY)); } // Bestimmt, ob sich das Objekt im negativen Bereich der x-Achse befindet