acm.graphics
Class GPolygon

java.lang.Object
  |
  +--acm.graphics.GObject
        |
        +--acm.graphics.GPolygon

public class GPolygon extends GObject

The GPolygon class is a graphical object whose appearance consists of a polygon.

[examples forthcoming]


Constructor Summary
GPolygon()
Constructs a new empty polygon at the origin.
GPolygon(double x, double y)
Constructs a new empty polygon at (x, y).
 
Method Summary
void addEdge(double dx, double dy)
Adds an edge to the polygon whose components are given by the displacements dx and dy.
void addEdgeInPolarCoordinates(double r, double theta)
Adds an edge to the polygon specified in polar coordinates.
static double angle(double x, double y)
Returns the angle in degrees from the origin to the point (xy).
Object clone()
Overrides clone in Object to make sure that the point arrays are copied rather than shared.
boolean contains(double x, double y)
Checks to see whether a point is inside the object.
static double cosD(double angle)
Returns the trigonometric sine of its argument where angle is expressed in degrees.
static double distance(double x, double y)
Computes the distance between the origin and the point (xy).
static double distance(double x0, double y0, double x1, double y1)
Computes the distance between the points (x0y0) and (x1y1).
void endPolygon()
Ends the polygon and makes it available for display.
Rectangle getBounds()
Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure.
double getHeight()
Returns the height of this polygon.
Polygon getPolygon()
Returns an AWT Polygon whose point are as close as possible to the ones in this GPolygon.
Dimension getSize()
Returns the size of this polygon.
double getWidth()
Returns the width of this polygon.
void paint(Graphics g)
Implements the paint operation for this graphical object.
void rotate(double theta)
Rotates the polygon around its origin by the angle theta, measured in degrees.
void scale(double sx, double sy)
Scales the polygon by the scale factors sx and sy.
static double sinD(double angle)
Returns the trigonometric sine of its argument where angle is expressed in degrees.
void startPolygon()
Starts a polygon at its origin.
void startPolygon(double x, double y)
Sets the start location of the polygon relative to its origin.
static double tanD(double angle)
Returns the trigonometric sine of its argument where angle is expressed in degrees.
static double toDegrees(double radians)
Converts an angle from radians to degrees.
static double toRadians(double degrees)
Converts an angle from degrees to radians.
 

Inherited Method Summary
void addMouseListener(MouseListener listener)
Adds a mouse listener to this graphical object. [Inherited from GObject]
void addMouseMotionListener(MouseMotionListener listener)
Adds a mouse motion listener to this graphical object. [Inherited from GObject]
Color getColor()
Returns the color used to display this object. [Inherited from GObject]
Color getFillColor()
Returns the color used to display the filled region of this object. [Inherited from GObject]
Point getLocation()
Returns the nearest Point corresponding to the location of this object. [Inherited from GObject]
double getX()
Returns the x-coordinate of the object. [Inherited from GObject]
double getY()
Returns the y-coordinate of the object. [Inherited from GObject]
boolean isFilled()
Returns whether this object is filled. [Inherited from GObject]
boolean isVisible()
Checks to see whether this object is visible. [Inherited from GObject]
void moveToBack()
Moves this object to the back of the display in stacking order. [Inherited from GObject]
void moveToFront()
Moves this object to the front of the display in stacking order. [Inherited from GObject]
void removeMouseListener(MouseListener listener)
Removes a mouse listener from this graphical object. [Inherited from GObject]
void removeMouseMotionListener(MouseMotionListener listener)
Removes a mouse motion listener from this graphical object. [Inherited from GObject]
void setColor(Color c)
Sets the color used to display this object. [Inherited from GObject]
void setFillColor(Color c)
Sets the color used to display the filled region of this object. [Inherited from GObject]
void setFilled(boolean fill)
Sets whether this object is filled. [Inherited from GObject]
void setLocation(double x, double y)
Sets the location of this object to the point (x, y). [Inherited from GObject]
void setVisible(boolean visible)
Sets whether this object is visible. [Inherited from GObject]
void translate(double dx, double dy)
Moves the object on the screen using the displacements dx and dy. [Inherited from GObject]

Constructor Detail

public GPolygon()

Constructs a new empty polygon at the origin.
 
Usage: GPolygon gpoly = new GPolygon();
 

public GPolygon(double x, double y)

Constructs a new empty polygon at (x, y).
 
Usage: GPolygon gpoly = new GPolygon(x, y);
Parameters: 
x  The x-coordinate of the origin of the polygon
y  The y-coordinate of the origin of the polygon
 
Method Detail

public void addEdge(double dx, double dy)

Adds an edge to the polygon whose components are given by the displacements dx and dy.
 
Usage: gpoly.addEdge(dx, dy);
Parameters: 
dx  The x displacement through which the edge moves
dy  The y displacement through which the edge moves
 

public void addEdgeInPolarCoordinates(double r, double theta)

Adds an edge to the polygon specified in polar coordinates. The length of the edge is given by r, and the edge extends in direction theta, measured in degrees counterclockwise from the +x axis.
 
Usage: gpoly.addEdgeInPolarCoordinates(r, theta);
Parameters: 
r  The length of the edge
theta  The angle at which the edge extends measured in degrees
 

public static double angle(double x, double y)

Returns the angle in degrees from the origin to the point (xy). This method is easier to use than atan2 because it specifies the displacements in the usual x/y order and because it takes care of the fact that the Java coordinate system is flipped. The point (0, 0) is arbitrarily defined to be at angle 0.

public Object clone()

Overrides clone in Object to make sure that the point arrays are copied rather than shared.

public boolean contains(double x, double y)

Checks to see whether a point is inside the object.
 
Usage: if (gpoly.contains(x, y)) . . .
Parameters: 
x  The x-coordinate of the point being tested
y  The y-coordinate of the point being tested
Returns: true if the point (xy) is inside the object, and false otherwise
 

public static double cosD(double angle)

Returns the trigonometric sine of its argument where angle is expressed in degrees.

public static double distance(double x, double y)

Computes the distance between the origin and the point (xy).

public static double distance(double x0, double y0, double x1, double y1)

Computes the distance between the points (x0y0) and (x1y1).

public void endPolygon()

Ends the polygon and makes it available for display.
 
Usage: gpoly.endPolygon();
 

public Rectangle getBounds()

Returns the bounding box of this object, which is defined to be the smallest rectangle that covers everything drawn by the figure.
 
Usage: Rectangle bounds = gpoly.getBounds();
Returns: The bounding box for this object
 

public double getHeight()

Returns the height of this polygon.
 
Usage: double height = gpoly.getHeight();
Returns: The height of this object on the screen
 

public Polygon getPolygon()

Returns an AWT Polygon whose point are as close as possible to the ones in this GPolygon.
 
Usage: Polygon p = gpoly.getPolygon();
Returns: An AWT polygon corresponding to this object
 

public Dimension getSize()

Returns the size of this polygon.
 
Usage: Dimension size = gpoly.getSize();
Returns: The size of this object
 

public double getWidth()

Returns the width of this polygon.
 
Usage: double width = gpoly.getWidth();
Returns: The width of this object
 

public void paint(Graphics g)

Implements the paint operation for this graphical object. This method is not called directly by clients.

public void rotate(double theta)

Rotates the polygon around its origin by the angle theta, measured in degrees.
 
Usage: gpoly.rotate(theta);
Parameter: 
theta  The angle of rotation in degrees counterclockwise
 

public void scale(double sx, double sy)

Scales the polygon by the scale factors sx and sy.
 
Usage: gpoly.scale(sx, sy);
Parameters: 
sx  The factor used to scale all coordinates in the x direction
sy  The factor used to scale all coordinates in the y direction
 

public static double sinD(double angle)

Returns the trigonometric sine of its argument where angle is expressed in degrees.

public final void startPolygon()

Starts a polygon at its origin.
 
Usage: gpoly.startPolygon();
 

public void startPolygon(double x, double y)

Sets the start location of the polygon relative to its origin.
 
Usage: gpoly.startPolygon(x, y);
Parameters: 
x  The x-coordinate of the start of the figure relative to the polygon origin
y  The y-coordinate of the start of the figure relative to the polygon origin
 

public static double tanD(double angle)

Returns the trigonometric sine of its argument where angle is expressed in degrees.

public static double toDegrees(double radians)

Converts an angle from radians to degrees. This method is defined in the Math class, but was added only in JDK1.2, which is not supported in all browsers.

public static double toRadians(double degrees)

Converts an angle from degrees to radians. This method is defined in the Math class, but was added only in JDK1.2, which is not supported in all browsers.