Package java.awt Previous
Previous
Java API
Java API
Index
Index
Next
Next

Class Polygon

Fields , Constructors , Methods

public  class  java.awt.Polygon
    extends  java.lang.Object  
{
        // Fields
    public int npoints;	
    public int xpoints[];	
    public int ypoints[];	

        // Constructors
    public Polygon();	
    public Polygon(int  xpoints[], int  ypoints[],	
               int  npoints);

        // Methods
    public void addPoint(int  x, int  y);	
    public Rectangle getBoundingBox();	
    public boolean inside(int  x, int  y);	
}

A polygon consists of a list of (x,y), where each successive pair of coordinates defines a side of the polygon


Fields


npoints

public int npoints 

The total number of points.


xpoints

public int xpoints[] 

The array of x coordinates.


ypoints

public int ypoints[] 

The array of y coordinates.


Constructors


Polygon

public Polygon() 

Creates an empty polygon.


Polygon

public Polygon(int  xpoints[], int  ypoints[], int  npoints) 

Constructs and initializes a polygon from the specified parameters.

ParameterDescription
xpoints an array of x coordinates
ypoints an array of y coordinates
npoints the total number of points in the polygon


Methods


addPoint

public void addPoint(int  x, int  y) 

Appends a point to this polygon.

If an operation that calculates the bounding box of this polygon (getBoundingBox or inside ) has already been performed, this method updates the bounding box.

ParameterDescription
x the x coordinate of the point
y the y coordinate of the point


getBoundingBox

public Rectangle getBoundingBox() 

Return Value:

Returns the smallest rectangle than contains this polygon


inside

public boolean inside(int  x, int  y) 

Determines if the specified point is inside this polygon. This method uses an even-odd insideness rule (also known as an "alternating rule") to determine whether the point (x,y) is inside this polygon.

It is based on code by Hanpeter van Vliet (hvvliet@inter.nl.net).

Return Value:

Returns true if the point (x,y) is inside this polygon; false otherwise.

ParameterDescription
x the xcoordinate of the point to be tested
y the y coordinate of the point to be tested



Top© 1996 Sun Microsystems, Inc. All rights reserved.