Updated Code Snippets

Ein neuer Ansatz für den Start- und den Endpunkt wurde implementiert
This commit is contained in:
Justin Dretvic 2020-06-15 21:39:47 +02:00
parent 238f24bcb7
commit 67ce8d154f
4 changed files with 54 additions and 27 deletions

View File

@ -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
}

View File

@ -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) ) }
};
}

View File

@ -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<Integer> WegX = new ArrayList<Integer>();
ArrayList<Integer> WegY = new ArrayList<Integer>();
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);
} else {
planeLanded = true;
}
//g2d.setColor(Color.RED);
}
}

View File

@ -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