public class Punkt implements Vergleiche, Comparable
{
public int nr;
double rechtsWert, hochWert, höhe;
public Punkt ( )
{
this.nr = - 1;
this.rechtsWert = - 9.9999e10;
this.hochWert = - 9.9999e10;
this.höhe = - 9.9999e10;
}
public Punkt ( int nr, double rechtsWert, double hochWert )
{
this ( );
this.nr = nr;
this.rechtsWert = rechtsWert;
this.hochWert = hochWert;
}
public Punkt ( int nr, double rechtsWert, double hochWert, double höhe )
{
this ( nr, rechtsWert, hochWert );
this.höhe = höhe;
}
public Punkt ( Punkt p )
{
this ( p.getNr ( ), p.getRechtsWert ( ), p.getHochWert ( ), p.getHöhe ( ) );
}
public void ausgeben ( )
{
System.out.printf ( " %10d %13.3f %13.3f %13.3f \n",
nr, rechtsWert, hochWert, höhe );
}
public void ausgeben ( String text )
{
System.out.printf ( "%s", text );
ausgeben ( );
}
public void ausgebenRH ( )
{
System.out.printf ( " %10d %13.3f %13.3f \n",
nr, rechtsWert, hochWert );
}
public int compareTo ( Object o )
{
Punkt p = (Punkt) o;
if ( this.getNr ( ) < p.getNr ( ) )
{
return -1;
}
else if ( this.getNr ( ) > p.getNr ( ) )
{
return 1;
}
return 0;
}
public double deltaH ( Punkt p )
{
double dh = this.getHöhe ( ) - p.getHöhe ( );
return dh;
}
public static double deltaH ( Punkt p1, Punkt p2 )
{
double diffH = p1.getHöhe ( ) - p2.getHöhe ( );
return diffH;
}
public double getHochWert ( )
{
return this.hochWert;
}
public double getHöhe ( )
{
return this.höhe;
}
public int getNr ( )
{
return this.nr;
}
public double getRechtsWert ( )
{
return this.rechtsWert;
}
public boolean isInside
( double rLu, double hLu, double rRo, double hRo )
{
if ( rechtsWert >= rLu && rechtsWert <= rRo &&
hochWert >= hLu && hochWert <= hRo ) return true;
return false;
}
public static Punkt minHoehenPunkt ( Punkt [ ] punkte )
{
if ( punkte == null ) return null;
Punkt p = null;
double minHoehe = 1.e10;
for ( int i = 0; i < punkte.length; i++ )
{
double hoehe = punkte [ i ].getHöhe ( );
if ( hoehe > -9.e10 && hoehe < minHoehe )
{
minHoehe = punkte [ i ].getHöhe ( );
p = new Punkt ( punkte [ i ] );
}
}
return p;
}
public static Punkt [ ] minHoehenPunkte ( Punkt [ ] punkte )
{
if ( punkte == null ) return null;
double minHoehe = 1.e10;
int zaehler = 0;
for ( int i = 0; i < punkte.length; i++ )
{
double hoehe = punkte [ i ].getHöhe ( );
if ( hoehe > -9.e10 && hoehe <= minHoehe )
{
minHoehe = punkte [ i ].getHöhe ( );
zaehler++;
}
}
System.out.println ( "Anzahl: " + zaehler );
if ( zaehler == 0 ) return null;
Punkt [ ] minHoeP = new Punkt [ zaehler ];
int ix = 0;
for ( int i = 0; i < punkte.length; i++ )
{
double hoehe = punkte [ i ].getHöhe ( );
if ( hoehe > -9.e10 && hoehe <= minHoehe )
{
minHoehe = punkte [ i ].getHöhe ( );
minHoeP [ ix ] = new Punkt ( punkte [ i ] );
ix++;
}
}
return minHoeP;
}
public static double minRechtsWert ( Punkt [ ] punkte )
{
if ( punkte == null ) return -9999999999.0;
double min = punkte [ 0 ].getRechtsWert ( );
for ( int i = 0; i < punkte.length; i++ )
{
if ( punkte [ i ].getRechtsWert ( ) < min )
min = punkte [ i ].getRechtsWert ( );
}
return min;
}
public double riwi ( Punkt p )
{
return GMath.riwi( this, p );
}
public double strecke ( Punkt p )
{
return GMath.strecke( this, p );
}
public void setNr ( int nr )
{
this.nr = nr;
}
public void setHöhe ( double höhe )
{
this.höhe = höhe;
}
public String toStringRH ( )
{
return getNr ( ) + " " + getRechtsWert ( ) + " " + getHochWert ( );
}
public int vergleicheMit ( Object o )
{
Punkt p = (Punkt) o;
if ( this.getNr ( ) < p.getNr ( ) )
{
return -1;
}
else if ( this.getNr ( ) > p.getNr ( ) )
{
return 1;
}
return 0;
}
}
public final class GMath
{
public static final double RHO = 200. / Math.PI;
private GMath ( )
{
}
public static double max ( double z1, double z2 )
{
if ( z1 > z2 ) return z1;
return z2;
}
public static double min ( double z1, double z2 )
{
if ( z1 < z2 ) return z1;
return z2;
}
public static double riwi ( double r1, double h1, double r2, double h2 )
{
double dr = r2 - r1;
double dh = h2 - h1;
double c = Math.atan2 ( dr, dh );
double riWi = c * RHO;
if ( riWi < 0. ) riWi = riWi + 400.;
return riWi;
}
public static double riwi ( Punkt p1, Punkt p2 )
{
return riwi ( p1.getRechtsWert( ), p1.getHochWert( ),
p2.getRechtsWert( ), p2.getHochWert( ) );
}
public static double strecke ( double r1, double h1, double r2, double h2 )
{
double dr = r1 - r2;
double dh = h1 - h2;
double c = Math.pow ( dr, 2. ) + Math.pow ( dh, 2. );
return Math.sqrt( c );
}
public static double strecke ( Punkt p1, Punkt p2 )
{
return strecke ( p1.getRechtsWert( ), p1.getHochWert( ),
p2.getRechtsWert( ), p2.getHochWert( ) );
}
public static double toGon ( double winkRad )
{
return winkRad * RHO;
}
public static double toRadiant ( double winkGon )
{
return winkGon / RHO;
}
}
public interface Vergleiche
{
public int vergleicheMit ( Object o );
}