public class Triangle extends Figure {
    private final Point p1;
    private final Point p2;
    private final Point p3;
    public Triangle(Point p1, Point p2, Point p3) {
        super("Triangle");
        this.p1 = p1;
        this.p2 = p2;
        this.p3 = p3;
    }
    public Point getP1() {
        return this.p1;
    }
    public Point getP2() {
        return this.p2;
    }
    public Point getP3() {
        return this.p3;
    }
    @Override
    public double calculateArea() {
        // http://www.mathopenref.com/coordtrianglearea.html
        return Math.abs((
                p1.getX() * (p2.getY() - p3.getY()) + 
                p2.getX() * (p3.getY() - p1.getY()) + 
                p3.getX() * (p1.getY() - p2.getY())
                ) / 2);
    }
    @Override
    public double calculatePerimeter() {
        return p1.distanceTo(p2) + p2.distanceTo(p3) + p3.distanceTo(p1);
    }
    public void printSideLengths() {
        System.out.println("Distance from p1 to p2: " + p1.distanceTo(p2));
        System.out.println("Distance from p2 to p3: " + p2.distanceTo(p3));
        System.out.println("Distance from p3 to p1: " + p3.distanceTo(p1));
    }
    @Override
    public String toString() {
        return super.toString() + ": (" + this.p1 + "," + this.p2 + "," + this.p3 + ")";
    }
}
