public static double length (Point a, Point b) { return sqrt(pow(b.getX() - a.getX(), 2) + pow(b.getY() - a.getY(), 2)); } public static double length2 (Point a, Point c) { return sqrt(pow(c.getX() - a.getX(), 2) + pow(c.getY() - a.getY(), 2)); } public static double length3 (Point b, Point c) { return sqrt(pow(c.getX() - b.getX(), 2) + pow(c.getY() - b.getY(), 2)); }
class Triangle { Point a; Point b; Point c; public Triangle(Point a, Point b, Point c) { //TODO double lab, lac, lbc; lab = length(a, b); lac = length2(a, c); lbc = length3(b, c); if ((lab + lac) > lbc || (lab + lbc) > lac || (lbc + lac) > lab) { throw new IllegalArgumentException(); } this.a = a; this.b = b; this.c = c; } public static double length (Point a, Point b) { return sqrt(pow(b.getX() - a.getX(), 2) + pow(b.getY() - a.getY(), 2)); } public static double length2 (Point a, Point c) { return sqrt(pow(c.getX() - a.getX(), 2) + pow(c.getY() - a.getY(), 2)); } public static double length3 (Point b, Point c) { return sqrt(pow(c.getX() - b.getX(), 2) + pow(c.getY() - b.getY(), 2)); } public double area() { //TODO return Math.abs((a.getX() - c.getX()) * (b.getY() - a.getY()) - (a.getX() - b.getX()) * (c.getY() - a.getY())) /2; } public Point centroid(){ //TODO double x = (a.getX() + b.getX() + c.getX()) / 3; double y = (a.getY() + b.getY() + c.getY()) / 3; return new Point(x, y); } }