I am trying to check if a triangle is a regular triangle in Java. This is part of what the tester class does:
Triangle a = new Triangle(new Point(2, 2), new Point(6, 2), new Point(2, 6) );
System.out.println(a.isRight());
Part of my triangular class takes values ββand sets them to x1, y2, etc .:
public Triangle(Point loc1, Point loc2, Point loc3) {
x1 = loc1.getX(); y1 = loc1.getY();
. . .
The first two code segments were provided to me. I have to make the last code segment that I did this:
public boolean isRight() {
if((Math.pow(side1,2)+Math.pow(side2,2)) == Math.pow(side3,2))
return true;
if((Math.pow(side2,2)+Math.pow(side1,2)) == Math.pow(side3,2))
return true;
if((Math.pow(side3,2)+Math.pow(side2,2)) == Math.pow(side1,2))
return true;
else
return false;
}
However, it still returns false. What am I doing wrong? Thanks a bunch!
Update: Thanks for the help. I seem to have made a pretty wrong mistake. I never thought that the doubles were not really accurate (sorry, I'm just trying to say what I did in simple words). I introduced this:
if(Math.abs(side1*side1 + side2*side2 - side3*side3) < 0.2)
return true;
if(Math.abs(side1*side1 + side3*side3 - side2*side2) < 0.2)
return true;
if(Math.abs(side3*side3 + side2*side2 - side1*side1) < 0.2)
return true;
else
return false;
Thanks again for the help!