/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package PoligonoRegular;

import java.awt.Color;
import java.awt.Graphics;
import java.util.ArrayList;

/**
 *
 * @author felix
 */
public class Triangulo implements Poligono{
    public int N;
    public double theta;
    private double R;
    
    ArrayList <Linea> Lineas;
    
    Triangulo() {
        Lineas = DefinePoligono(3);  
    }
    
    public ArrayList DefinePoligono(int Nb){
        int i;
        double x, y;
        ArrayList <Punto> Puntos;
        ArrayList <Linea> aux;
        
        N = Nb;
        theta = 2.0*Math.PI/(double)N;
        R = 100;
        Puntos = new ArrayList <Punto>();
        aux = new ArrayList <Linea>();
        
        for(i=0; i<N; i++){
            x = R*(1.0 + Math.cos(theta*i));
            y = R*(1.0 + Math.sin(theta*i));
            Puntos.add(new Punto(x, y));
        }
        
        for(i=0; i<N; i++){
            if(i < N-1)
                aux.add(new Linea(Puntos.get(i), Puntos.get(i+1)));
            else
                aux.add(new Linea(Puntos.get(i), Puntos.get(0)));
        }  
        return aux;
    }

    @Override
    public void Dibuja(Graphics g) {
        g.setColor(Color.BLACK);
        g.drawOval(0, 0, 200, 200);
        g.setColor(Color.red);
        for(Linea l : Lineas)
            l.Dibuja(g);
    }

    @Override
    public double Area() {
        double area;
        double a, b;
        
        a = R*Math.sin(theta/2.0);
        b = R*Math.cos(theta/2.0);
        area = a*b*N;
        return area;
    }

    @Override
    public double Perimetro() {
        double p =0;
        
        for(Linea l: Lineas)
            p += l.Longitud();
        
        return p;
    }
    
    @Override
    public String toString() {
        int i;
        String aux = "";
        
        
        for(Linea l : Lineas) 
            aux += l.toString() + "\n";
        
        aux += "Perimetro " + Perimetro() + "\n";
        aux += "Area " + Area() + "\n";
            
        return aux;
    }
}
