import static java.
lang.
Math.
sqrt;
public class ThreePoints {
float x0;
float y0;
float x1;
float y1;
float x2;
float y2;
public ThreePoints(){
this.x0 = 0;
this.y0 = 0;
this.x1 = 0;
this.y1 = 0;
this.x2 = 0;
this.y2 = 0;
}
public ThreePoints(float x0, float y0, float x1, float y1, float x2, float y2){
this.x0 = x0;
this.y0 = y0;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
}
public double getLength(int side){
if(side == 0 && isTriangle()){
return Math.
sqrt((x2
-x1
) * (x2
-x1
) + (y2
-y1
) * (y2
-y1
)); } else if (side == 1 && isTriangle()){
return Math.
sqrt((x2
-x0
) * (x2
-x0
) + (y2
-y0
) * (y1
-y0
)); } else if (side == 2 && isTriangle()){
return Math.
sqrt((x1
-x0
) * (x1
-x0
) + (y1
-y0
) * (y1
-y0
)); }else{ return 0;
}
}
public double getAngle(int vertex){
if(vertex == 0 && isTriangle()) {
double angle
= Math.
acos((-Math.
pow(this.
getLength(0),
2) +Math.
pow(this.
getLength(1),
2) +Math.
pow(this.
getLength(2),
2)) /(2*this.getLength(1)*this.getLength(2)));
return angle;
} else if(vertex == 1 && isTriangle()) {
double angle
= Math.
acos((Math.
pow(this.
getLength(0),
2)- Math.
pow(this.
getLength(1),
2) +Math.
pow(this.
getLength(2),
2))/ (2*this.getLength(0)*this.getLength(2)));
return angle;
} else if(vertex == 2 && isTriangle()){
double angle
= Math.
acos((Math.
pow(this.
getLength(0),
2) +Math.
pow(this.
getLength(1),
2)- Math.
pow(this.
getLength(2),
2)) /(2*this.
getLength(0)*this.
getLength(1))); return angle;
} else {
return 0;
}
}
public boolean isTriangle(){
if (!(x0 * (y1-y2) + x1 * (y2-y0) + x2 * (y0-y1) == 0)){
return true;
}
return false;
}
public boolean isEquilateral(){
if (getLength(0) != getLength(1))
return false;
if (getLength(0) != getLength(2))
return false;
if (getLength(1) != getLength(2))
return false;
return true;
}
public boolean isIsosceles(){
if (getLength(0) == getLength(1))
return true;
if (getLength(0) == getLength(2))
return true;
if (getLength(1) == getLength(2))
return true;
return false;
}
public boolean isScalene(){
if (getLength(0) == getLength(1))
return true;
if (getLength(0) == getLength(2))
return true;
if (getLength(1) == getLength(2))
return true;
return false;
}
public boolean isAcute(){
if (getAngle(0) < 90 && getAngle(1) < 90 && getAngle(2) < 90){
return true;
}
return false;
}
public boolean isObtuse(){
if (getAngle(0) > 90 && getAngle(1) > 90 && getAngle(2) > 90){
return true;
}
return false;
}
public double getPerimeter(){
double perimeter;
perimeter = (getLength(0) + getLength(1) + getLength(2));
return perimeter;
}
public boolean isRight(){
if (getAngle(0) == 90 && getAngle(1) == 90 && getAngle(2) == 90){
return true;
}
return false;
}
public double getArea(){
double s = ((getLength(0) + getLength(1) + getLength(2))/2);
double area = sqrt(s * (s-getLength(0))*(s-getLength(1))*(s-getLength(2)));
return area;
}
private boolean approxEqual (double x, double y) {
return Math.
abs(x
- y
) <= 1E
-12
; }
}