131 lines
2.7 KiB
Java
131 lines
2.7 KiB
Java
public final class Triangle{
|
|
|
|
private static final double EPS = 1e-9;
|
|
|
|
//Instanzvariablen
|
|
final private Point p0;
|
|
final private Point p1;
|
|
final private Point p2;
|
|
|
|
|
|
//Konstruktor
|
|
Triangle(Point a, Point b, Point c) {
|
|
this.p0 = a;
|
|
this.p1 = b;
|
|
this.p2 = c;
|
|
}
|
|
|
|
|
|
|
|
//Distanz Punkt A = P1-P0, Pythagoras länge |p0p1| = sqrt(x²+y²)
|
|
public double distance(Point p0, Point p1){
|
|
|
|
double dis = Math.sqrt(Math.pow(p1.getX() - p0.getX(), 2) + Math.pow(p1.getY() - p0.getY(), 2));
|
|
|
|
return dis;
|
|
}
|
|
|
|
|
|
//Gleichseitig
|
|
public boolean isEquilateral(){
|
|
|
|
double a = distance(p0, p1);
|
|
double b = distance(p1, p2);
|
|
double c = distance(p2, p0);
|
|
|
|
//Alle kleiner EPS
|
|
if (Math.abs(a - b) < EPS && Math.abs(b - c) < EPS && Math.abs(a - c) < EPS)
|
|
|
|
{return true;}
|
|
|
|
else {return false;}
|
|
}
|
|
|
|
|
|
//Gleichschenklig
|
|
public boolean isIsosceles(){
|
|
|
|
double a = distance(p0, p1);
|
|
double b = distance(p1, p2);
|
|
double c = distance(p2, p0);
|
|
|
|
//2 kleiner EPS, 1 größer EPS
|
|
if (Math.abs(a - b) < EPS && Math.abs(b - c) < EPS && Math.abs(c - a) > EPS
|
|
|| Math.abs(a - b) < EPS && Math.abs(a - c) < EPS && Math.abs(c - b) > EPS
|
|
|| Math.abs(b - c) < EPS && Math.abs(a - c) < EPS && Math.abs(a - b) > EPS)
|
|
|
|
{return true;}
|
|
|
|
else {return false;}
|
|
}
|
|
|
|
|
|
//Spitzwinklig (alle Winkel < 90°)
|
|
public boolean isAcute(){
|
|
|
|
double a = distance(p0, p1);
|
|
double b = distance(p1, p2);
|
|
double c = distance(p2, p0);
|
|
|
|
if(a*a + b*b > c*c && a*a + c*c > b*b && b*b + b*b > a*a)
|
|
|
|
{return true;}
|
|
|
|
else {return false;}
|
|
}
|
|
|
|
|
|
//Rechtwinklig
|
|
public boolean isRight(){
|
|
|
|
double a = distance(p0, p1);
|
|
double b = distance(p1, p2);
|
|
double c = distance(p2, p0);
|
|
|
|
if (Math.abs(a*a + b*b - c*c) < EPS ||Math.abs(a*a + c*c - b*b) < EPS ||Math.abs(c*c + b*b - a*a) < EPS)
|
|
|
|
{return true;}
|
|
|
|
else {return false;}
|
|
}
|
|
|
|
|
|
//Stumpfwinklig (1 Winkel > 90°)
|
|
public boolean isObtuse(){
|
|
|
|
double a = distance(p0, p1);
|
|
double b = distance(p1, p2);
|
|
double c = distance(p2, p0);
|
|
|
|
if (a*a + b*b > c*c || a*a + c*c > b*b || b*b + c*c > a*a)
|
|
|
|
{return true;}
|
|
|
|
else {return false;}
|
|
|
|
}
|
|
|
|
|
|
//Entartet
|
|
public boolean isDegenerated(){
|
|
|
|
double a = distance(p0, p1);
|
|
double b = distance(p1, p2);
|
|
double c = distance(p2, p0);
|
|
|
|
//Kolinear
|
|
if(Math.abs(a + b - c) < EPS ||
|
|
Math.abs(a + c - b) < EPS ||
|
|
Math.abs(b + c - a) < EPS)
|
|
{return true;}
|
|
|
|
//Punkte gleich
|
|
else if (Math.abs(p0.getX() - p1.getX()) < EPS && Math.abs(p0.getY() - p1.getY()) < EPS ||
|
|
Math.abs(p1.getX() - p2.getX()) < EPS && Math.abs(p1.getY() - p2.getY()) < EPS ||
|
|
Math.abs(p0.getX() - p2.getX()) < EPS && Math.abs(p0.getY() - p2.getY()) < EPS)
|
|
{return true;}
|
|
|
|
else {return false;}
|
|
}
|
|
|
|
} |