package part2;

import java.awt.Color;
import java.awt.Point;

public class Triangle extends Shape {
private Point a, b, c;
/** * Create a triangle with the specified vertices and color. * @param a The first vertex. * @param b The second vertex. * @param c The third vertex. * @param color The color of the triangle. */ public Triangle(Point a, Point b, Point c, Color color) { super(color); this.a = a; this.b = b; this.c = c; }
/** * Compute and return the area of this triangle. */ @Override public double getArea() { return 0.5 * Math.abs( this.a.x * (this.b.y - this.c.y) + this.b.x * (this.c.y - this.a.y) + this.c.x * (this.a.y - this.b.y) ); } /** * Compute and return the perimeter of this triangle. */ @Override public double getPerimeter() { return a.distance(b) + b.distance(c) + c.distance(a); } /** * Move the triangle by the specified amount. * @param p The amount to move the triangle. */ @Override public void translate(Point p) { this.a.translate(p.x, p.y); this.b.translate(p.x, p.y); this.c.translate(p.x, p.y); }
public Point getVertexA() { return this.a; } public Point getVertexB() { return this.b; } public Point getVertexC() { return this.c; }
}