/* Copyright 2001 Michael R. Wick */ package Shapes; import java.awt.*; public class Triangle extends Polygon { protected final static int SIDES = 3; protected int length ; public Triangle(Point center, int l, Color aColor) { super(center,SIDES,aColor); length = l; double c = length / (2.0 * Math.cos(degreesToRadians(30)) ); double a = Math.tan(degreesToRadians(30)) * 0.5 * length; theVertices[0] = new Point(center.x, (int)(center.y - c)); theVertices[1] = new Point((int)(center.x - .5 * length), (int)(center.y + a)); theVertices[2] = new Point((int)(center.x + 0.5 * length), (int)(center.y + a)); } public Triangle( Triangle orig ){ super(orig); length = orig.length; theVertices = new Point[SIDES]; for(int i = 0; i < theVertices.length; i++){ theVertices[i] = new Point( orig.theVertices[i] ); } } public Shape copy(){ return (new Triangle(this) ); } }