import java.awt.*;
import java.applet.*;
import java.util.*;
class PP
 {
  static final double DR=Math.PI/180;
  static M parent;
  static Te te=M.te0;
  String name;
  public XYZ[] a;
  public int[] xi;
  public int[] yi;
  public XYZ centroid;
  public XYZ normal;
  public boolean onstage=false;
  public PP(String n,XYZ[] aa)
   {
    name=n;
    int l=aa.length;
    if(XYZ.nearlyequals(aa[0],aa[l-1])) l--;
    a=new XYZ[l];
    xi=new int[l];
    yi=new int[l];
    for(int i=0;i<l;i++) a[i]=aa[i];
    comm();
   }
  void comm() 
   {
    te=parent.te;
    calc();
   }
  void calc() 
   {
    centroid=XYZ.centroid(a);
    normal=XYZ.normal(a);
   }
  public double zave()
   {
    double r=0;
    for(int i=0;i<a.length;i++) r+=a[i].z;
    return r/a.length;
   }
  public void transl(Translation tl)
   {
    for(int i=0;i<a.length;i++) tl.transl(a[i]);
   }
  public void rotate(Rotation ro)
   {
    for(int i=0;i<a.length;i++) ro.rot(a[i]);
   }
  public void rotate(double d,double b,double c,double r) { XYZ.rotate(a,d,b,c,r*DR); }
  public void ed(String name)
   {
    tta1(name+" ed stuff here");
    tta1("name.centroid "+centroid);
   }
  void tta1(String s) { parent.tta1(s); }
  void tta(String s) { parent.tta(s); }
  static String Svo(PP pp)
   {
    String s="("+pp.name;
    for(int i=0;i<pp.a.length;i++) s+=","+Te.Svo(pp.a[i]);
    s+=")";
    return s;
   }
  boolean addPrespective(double nV,double nP)
   {
    double b=0,c=0;
    for(int i=0;i<a.length;i++) 
     {
      c=nV/(nV+nP-a[i].z);
      b=nV/(nV+nP-a[i].z);
      if(c<=0 || b<=0) return false;
      xi[i]=(int)(c*a[i].x);
      yi[i]=(int)(b*a[i].y);
     }
    return true;
    //return new XYZ(k.x*Math.abs(nV/(nV+nP-k.z)),k.y*Math.abs(nV/(nV+nP-k.z)),k.z);
   }
 }
