183 lines
7.2 KiB
Java
183 lines
7.2 KiB
Java
package app;
|
|
|
|
public class _2_Methods {
|
|
|
|
// Objektattribute
|
|
double[][] startpunkt = _0_Matrices.START(_0_Constants.PHI_S,_0_Constants.THETA_S);
|
|
double[][] endpunkt = _0_Matrices.END(_0_Constants.PHI_E,_0_Constants.THETA_E);
|
|
|
|
// Gibt X oder Y Koordinate aus einem normierten Vektor zurück, abhängig vom String Parameter
|
|
protected int getCoords(double[][] _vector, String _axe) {
|
|
double[][] coordinate = matrixMultiplikation(_0_Matrices.M_JavaNormalized, _vector);
|
|
if( _axe.contentEquals("x"))
|
|
return (int)coordinate[0][0];
|
|
else if( _axe.contentEquals("y"))
|
|
return (int)coordinate[1][0];
|
|
else
|
|
return -1000;
|
|
}
|
|
|
|
// Führt eine Matrixmultiplikation zweier 2D-Arrays aus
|
|
protected double[][] matrixMultiplikation(double[][] matrix_eins, double[][] matrix_zwei) {
|
|
double[][] ergebnismatrix = new double[matrix_eins.length][matrix_zwei[0].length];
|
|
if(matrix_eins[0].length == matrix_zwei.length)
|
|
for(int z=0; z<matrix_eins.length; z++) {
|
|
for(int s=0; s<matrix_zwei[0].length ;s++) {
|
|
for(int k=0; k<matrix_eins[0].length ;k++) {
|
|
ergebnismatrix[z][s] += matrix_eins[z][k]*matrix_zwei[k][s];
|
|
}
|
|
}
|
|
} else
|
|
System.out.println("Die Zeilen- & Spaltenlänge sind ungleich!");
|
|
return ergebnismatrix;
|
|
}
|
|
|
|
// Normiert einen Vektor
|
|
protected double[][] normVector(double[][] _vector) {
|
|
double[][] vectorNormiert = new double[4][1];
|
|
vectorNormiert[0][0] = _vector[0][0];
|
|
vectorNormiert[1][0] = _vector[1][0];
|
|
vectorNormiert[2][0] = _vector[2][0];
|
|
vectorNormiert[3][0] = 1;
|
|
return vectorNormiert;
|
|
}
|
|
|
|
// Gibt eine Drehmatrix für die Bewegung des "Flugzeugs" wieder
|
|
protected double[][] drehBewegung(double _time) {
|
|
// Trennlinie P_Dach
|
|
double[][] p_dach = new double[3][1];
|
|
for(int i = 0; i < 3; i++)
|
|
p_dach[i][0] = startpunkt[i][0];
|
|
for(int i = 0; i < 3; i++)
|
|
p_dach[i][0] /= betrag(startpunkt);
|
|
// Trennlinie N_Dach
|
|
double[][] n_dach = kreuzprodukt(startpunkt, endpunkt);
|
|
for(int i = 0; i < 3; i++)
|
|
n_dach[i][0] /= betrag(n_dach);
|
|
// Trennlinie U_Dach
|
|
double[][] v_dach = kreuzprodukt(n_dach, p_dach);
|
|
for(int i = 0; i < 3; i++)
|
|
v_dach[i][0] /= betrag(v_dach);
|
|
// Trennlinie Check NaN
|
|
if( Double.isNaN((p_dach[0][0])) || Double.isNaN((p_dach[1][0])) || Double.isNaN((p_dach[2][0])) || Double.isNaN((n_dach[0][0])) || Double.isNaN((n_dach[1][0])) || Double.isNaN((n_dach[2][0])) ) {
|
|
startpunkt = _0_Matrices.START(_0_Constants.PHI_S+0.01,_0_Constants.THETA_S);
|
|
return drehBewegung(_time);
|
|
}
|
|
// Trennlinie Ergebnismatrix
|
|
return new double[][] {
|
|
{ ( _0_Constants.RADIUS * Math.cos(_time * _0_Constants.VELOCITY) * p_dach[0][0] ) + ( _0_Constants.RADIUS * Math.sin(_time * _0_Constants.VELOCITY) * v_dach[0][0] ) },
|
|
{ ( _0_Constants.RADIUS * Math.cos(_time * _0_Constants.VELOCITY) * p_dach[1][0] ) + ( _0_Constants.RADIUS * Math.sin(_time * _0_Constants.VELOCITY) * v_dach[1][0] ) },
|
|
{ ( _0_Constants.RADIUS * Math.cos(_time * _0_Constants.VELOCITY) * p_dach[2][0] ) + ( _0_Constants.RADIUS * Math.sin(_time * _0_Constants.VELOCITY) * v_dach[2][0] ) },
|
|
};
|
|
}
|
|
|
|
// Berechnet die Koordinaten für eine Umrissellipse
|
|
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));
|
|
double [][] zwischenergebnis_2 = matrixMultiplikation(zwischenergebnis_1, _0_Matrices.DrehungY(_theta));
|
|
double [][] zwischenergebnis_3 = matrixMultiplikation(zwischenergebnis_2, Länge);
|
|
return zwischenergebnis_3;
|
|
}
|
|
|
|
// Gibt den Winkel Theta für einen Ortsvektor wieder
|
|
protected double getTheta(double[][] _u) {
|
|
double[][] u_strich = new double[3][1];
|
|
for(int i=0; i<3 ; i++)
|
|
u_strich[i][0] = _u[i][0];
|
|
u_strich [2][0] = 0;
|
|
double winkel = Math.acos(
|
|
(Math.pow(_u[0][0],2) + Math.pow(_u[1][0],2) + _u[2][0]*u_strich[2][0]) /
|
|
( Math.abs( Math.sqrt(Math.pow(_u[0][0],2)+Math.pow(_u[1][0],2)+Math.pow(_u[2][0],2)) * Math.sqrt(Math.pow(u_strich[0][0],2)+Math.pow(u_strich[1][0],2)+Math.pow(u_strich[2][0],2)) )) );
|
|
if(_u[2][0] < 0)
|
|
winkel *= (-1);
|
|
return Math.toDegrees(winkel);
|
|
}
|
|
|
|
// Gibt den Winkel Phi für einen Ortsvektor wieder
|
|
protected double getPhi(double[][] _u) {
|
|
double[][] x_dach = new double[][] { {1},{0},{0} };
|
|
double[][] u_strich = new double[3][1];
|
|
for(int i=0; i<3 ; i++)
|
|
u_strich[i][0] = _u[i][0];
|
|
u_strich [2][0] = 0;
|
|
double winkel = Math.acos(
|
|
(u_strich[0][0]*x_dach[0][0] + u_strich[1][0]*x_dach[1][0] + u_strich[2][0]*x_dach[1][0]) /
|
|
( Math.abs( Math.sqrt(Math.pow(x_dach[0][0],2)+Math.pow(x_dach[1][0],2)+Math.pow(x_dach[2][0],2)) * Math.sqrt(Math.pow(u_strich[0][0],2)+Math.pow(u_strich[1][0],2)+Math.pow(u_strich[2][0],2)) )) );
|
|
if(_u[1][0] < 0) {
|
|
winkel = Math.toRadians(360) + ( winkel * (-1) );
|
|
}
|
|
return Math.toDegrees(winkel);
|
|
}
|
|
|
|
// Berechnet die Entfernung vom Start bis zum Endpunkt
|
|
protected double WinkelstartToEnd() {
|
|
double variable = ( skalarprodukt (startpunkt,endpunkt) ) / ( betrag(startpunkt) * betrag(endpunkt)) ;
|
|
if(variable < -1)
|
|
variable -= (variable + 1);
|
|
if(variable > 1)
|
|
variable += (variable - 1);
|
|
return (Math.acos( variable ) ) ;
|
|
}
|
|
|
|
// Berechnet die Entfernung vom Start bis zum Endpunkt als Radius
|
|
protected double RadiusStartToEnd() {
|
|
double variable = ( skalarprodukt (startpunkt,endpunkt) ) / ( betrag(startpunkt) * betrag(endpunkt)) ;
|
|
if(variable < -1)
|
|
variable -= (variable + 1);
|
|
if(variable > 1)
|
|
variable += (variable - 1);
|
|
return Math.acos( variable ) * _0_Constants.RADIUS;
|
|
}
|
|
|
|
protected double zeitGrenze() {
|
|
return Math.toDegrees( (WinkelstartToEnd() / (_0_Constants.VELOCITY) ) );
|
|
}
|
|
|
|
// Bestimmt, ob sich das Objekt im negativen Bereich der x-Achse befindet
|
|
protected boolean istHinten(double[][] _vector) {
|
|
if( getPhi(_vector) < 90)
|
|
return false;
|
|
else if( getPhi(_vector) < 270)
|
|
return true;
|
|
else
|
|
return false;
|
|
}
|
|
|
|
// Bestimmt den Winkel Phi der Umrissellipse
|
|
protected double umrissPhi() {
|
|
return Math.atan( _0_Constants.S1 * Math.sin(_0_Constants.ALPHA) );
|
|
}
|
|
|
|
// Bestimmt den Winkel Theta der Umrissellipse
|
|
protected double umrissTheta(double _phi) {
|
|
return Math.atan( -_0_Constants.S1 * Math.cos(_0_Constants.ALPHA) * Math.cos(_phi) );
|
|
}
|
|
|
|
// Skalarprodukt
|
|
public double skalarprodukt(double[][] _vektor1, double[][] _vektor2){
|
|
double skalar = 0;
|
|
for (int i = 0; i < _vektor1.length; i++) {
|
|
skalar += _vektor1[i][0] * _vektor2[i][0];
|
|
}
|
|
return skalar;
|
|
}
|
|
|
|
// Betrag eines Vektors
|
|
public double betrag(double[][] _vektor1){
|
|
double betrag = Math.sqrt(Math.pow(_vektor1[0][0], 2) + Math.pow(_vektor1[1][0], 2) + Math.pow(_vektor1[2][0], 2));
|
|
return betrag;
|
|
}
|
|
|
|
// Kreuzprodukt
|
|
public double[][] kreuzprodukt(double[][] _vektor1, double[][] _vektor2){
|
|
double[][] kreuz = new double[][] {
|
|
{(_vektor1[1][0] * _vektor2[2][0]) - (_vektor1[2][0] * _vektor2[1][0])},
|
|
{(_vektor1[2][0] * _vektor2[0][0]) - (_vektor1[0][0] * _vektor2[2][0])},
|
|
{(_vektor1[0][0] * _vektor2[1][0]) - (_vektor1[1][0] * _vektor2[0][0])}
|
|
};
|
|
return kreuz;
|
|
}
|
|
|
|
}
|