import java.awt.* ;
import java.awt.geom.* ;

public class PolyStar {

    Point2D.Double CenterP ;
    double RadiusL ;
    double RadiusS ;
    int nPoints ;
 
    public PolyStar(Point P, int Rs, int Rl, int n)
    // Inputs: P is a Point object storing the x and y coordinates of 
    // the center of the star, Rs is the radius of the inner circle used 
	 // to form the star, Rl is the radius of the outer circle used 
	 // to form the star, and n is the number of points on the outer circle
	 // of the star; e.g., a 5-pointed star or a 6-pointed star
    {
		CenterP = new Point2D.Double(P.x, P.y) ;
		if (Rl < 2)
	   	Rl = 2 ;
		RadiusL = Rl ;
		if (Rs >= Rl)
	   	Rs = Rl-2 ;
		RadiusS = Rs ;		
		if (n < 4)
	 	   n = 4 ;
		nPoints = n ;
   }

    public PolyStar(int x, int y, int Rs, int Rl, int n)
    // Inputs: x and y are the coordinates of the center of the star,
	 // Rs is the radius of the inner circle used to form the star, 
	 // Rl is the radius of the outer circle used to form the star, 
	 // and n is the number of points on the outer circle of the star; 
	 // e.g., a 5-pointed star or a 6-pointed star
    {
		CenterP = new Point2D.Double(x, y) ;
		if (Rl < 2)
	 	   Rl = 2 ;
		RadiusL = Rl ;
		if (Rs >= Rl)
	   	Rs = Rl-2 ;
		RadiusS = Rs ;		
		if (n <= 5)
	 	   n = 5 ;
		nPoints = n ;
    }

    private Point2D.Double RootOfUnity(int k, int n)
    // Returns k'th n'th root of unity 
    {
		double Angle = k * 2.0 * Math.PI / n ;
		return new Point2D.Double(Math.cos(Angle), Math.sin(Angle)) ;
    }

    public Point getOuterPoint(int k)
    // Input: The point number
    // Return value: A reference to a Point object containing the 
    // x and y coordinate of the point on the outer circle.
    {
		int modK = k%nPoints ;	// Probably not necessary ...
		Point2D.Double RoU = RootOfUnity(modK, nPoints) ;
		// Two reasons for the weirdness
		//   (1), The roots of unity start with x = 1, y = 0;
		//        So we want to start with x = 0, y = 1.
		//   (2), y decreases as we go up the scrren;
		//        So we want to really start with x = 0, y = -1
		double rX = - RoU.y ;
		double rY = - RoU.x ;
		return new Point((int)(CenterP.x + RadiusL*rX), (int)(CenterP.y + RadiusL*rY)) ;
    }

    public Point getInnerPoint(int k)
    // Input: The point number
    // Return value: A reference to a Point object containing the 
    // x and y coordinate of the point on the inner circle.
    {
		int modK = k%nPoints ;	// Probably not necessary ...
		Point2D.Double RoU = RootOfUnity(2*modK+1, 2*nPoints) ;
		double rX = - RoU.y ;
		double rY = - RoU.x ;
		return new Point((int)(CenterP.x + RadiusS*rX), (int)(CenterP.y + RadiusS*rY)) ;
    }

}
