edu.neu.ccs.gui
Class RegularShape

java.lang.Object
  extended byedu.neu.ccs.gui.RegularShape

public class RegularShape
extends Object

Class RegularShape provides factory methods to create regular polygons and regular star shapes.

This class also provides the mathematical methods that return the vertex arrays in case the caller wishes to deal directly with this data.

This class cannot be instantiated.

Since:
2.6.0
Version:
2.6.0

Constructor Summary
private RegularShape()
          Prevent instantiation.
 
Method Summary
static PolygonShape polygon(double x, double y, double r, int vertices)
          Creates a regular polygon with center (x,y) and radius r with the initial vertex positioned vertically above the center and with the given number of vertices.
static double[][] regularShapeData(double x, double y, double r, int vertices, int jump)
          Returns the array of coordinate data for a regular polygon or regular star shape with center (x,y), radius r, and the given number of outer vertices and the given jump between outer vertices.
static float[][] regularShapeDataFloat(double x, double y, double r, int vertices, int jump)
          Returns the same coordinate information as the method regularShapeData except as an array of float.
static PolygonShape star(double x, double y, double r, int vertices, int jump)
          Creates a regular star shape with center (x,y) and radius r with the initial vertex positioned vertically above the center and with the given number of outer vertices and the given jump.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RegularShape

private RegularShape()
Prevent instantiation.

Method Detail

polygon

public static PolygonShape polygon(double x,
                                   double y,
                                   double r,
                                   int vertices)

Creates a regular polygon with center (x,y) and radius r with the initial vertex positioned vertically above the center and with the given number of vertices.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
r - the radius
vertices - the number of polygon vertices

star

public static PolygonShape star(double x,
                                double y,
                                double r,
                                int vertices,
                                int jump)

Creates a regular star shape with center (x,y) and radius r with the initial vertex positioned vertically above the center and with the given number of outer vertices and the given jump.

Conceptually, the jump determines the distance between outer vertices that are "connected" by a line in the star. In particular, if jump is 1, then the shape reduces to a regular polygon .

In the actual shape construction, we do not in fact directly connect the outer vertices of a star. Instead, we compute a sequence of inner vertices positioned midway between the outer vertices and then build the star by connecting vertices in an alternating pattern: outer, inner, outer, inner, etc. This methodology makes the star a shape with no self-intersections.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
r - the radius
vertices - the number of outer star vertices
jump - the jump between outer star vertices

regularShapeData

public static double[][] regularShapeData(double x,
                                          double y,
                                          double r,
                                          int vertices,
                                          int jump)

Returns the array of coordinate data for a regular polygon or regular star shape with center (x,y), radius r, and the given number of outer vertices and the given jump between outer vertices.

Let V stand for the vertices parameter. Then:

If jump==1, the array returned has shape double[V][2].

If jump!=1, the array returned has shape double[2*V][2] to account for both the outer and the inner vertices of the star.

The vertices parameter should be at least 3 and the jump parameter should be at least 1 and less than vertices. Invalid parameters will be adjusted to the most reasonable valid values.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
r - the radius
vertices - the number of outer star vertices
jump - the jump between outer star vertices

regularShapeDataFloat

public static float[][] regularShapeDataFloat(double x,
                                              double y,
                                              double r,
                                              int vertices,
                                              int jump)

Returns the same coordinate information as the method regularShapeData except as an array of float.

Parameters:
x - the x-coordinate of the center
y - the y-coordinate of the center
r - the radius
vertices - the number of outer star vertices
jump - the jump between outer star vertices