
// Traingel.java


/******************************************************************************
/ Triangel.java modellerar en triangel.
/
/*****************************************************************************/

class Triangel
{
	// Triangelns hörn ----------------
	private Punkt    horn1 = null;
	private Punkt    horn2 = null;
	private Punkt    horn3 = null;
	
	// Konstruktorer ------------------
	public Triangel ()
	{
		horn1 = new Punkt (-1, 0);
		horn2 = new Punkt (1, 0);
		horn3 = new Punkt (0, 1);
	}
	
	public Triangel (Punkt horn1, Punkt horn2, Punkt horn3)
	{
		this.horn1 = new Punkt (horn1);
		this.horn2 = new Punkt (horn2);
		this.horn3 = new Punkt (horn3);
	}
	
	public Triangel (Triangel t)
	{
		this.horn1 = new Punkt (t.horn1);
		this.horn2 = new Punkt (t.horn2);
		this.horn3 = new Punkt (t.horn3);
	}
	
	// Metoder ------------------------
	public Punkt getHorn1 ()
	{
		return new Punkt (horn1);
	}
	
	public Punkt getHorn2 ()
	{
		return new Punkt (horn2);
	}
	
	public Punkt getHorn3 ()
	{
		return new Punkt (horn3);
	}
	
	public void setHorn1 (Punkt horn)
	{
		this.horn1 = horn;
	}
	
	public void setHorn2 (Punkt horn)
	{
		this.horn2 = horn;
	}
	
	public void setHorn3 (Punkt horn)
	{
		this.horn3 = horn;
	}
	
	public double sida1()
	{
		return horn2.avstand (horn3);
	}
	
	public double sida2()
	{
		return horn3.avstand (horn1);
	}
	
	public double sida3()
	{
		return horn1.avstand (horn2);
	}
	
	public double omkrets ()
	{
		return sida1 () + sida2 () + sida3 ();
	}
	
	public double area ()
	{
		return 0.5 * Math.abs (horn1.getX () * horn2.getY ()
					+ horn2.getX () * horn3.getY ()
					+ horn3.getX () * horn1.getY ()
					- horn2.getX () * horn1.getY ()
					- horn3.getX () * horn2.getY ()
					- horn1.getX () * horn3.getY ());
	}
	
	public String toString ()
	{
		return "[" + 
				horn1.toString () + "," +
				horn2.toString () + "," +
				horn3.toString () + "]";
	}
	
	
}

