Packages  This Package  Prev  Next  Index  

§1.35 Class Polygon

public  class  java.awt.Polygon
    extends  java.lang.Object  (I-§1.12)
{
        // Fields
    public int npoints;	§1.35.1
    public int xpoints[];	§1.35.2
    public int ypoints[];	§1.35.3

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

        // Methods
    public void addPoint(int  x, int  y);	§1.35.6
    public Rectangle getBoundingBox();	§1.35.7
    public boolean inside(int  x, int  y);	§1.35.8
}
A polygon consists of a list of , 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.
Parameters:
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 (II-§1.35.7) or inside (II-§1.35.8)) has already been performed, this method updates the bounding box.

Parameters:
x - the x coordinate of the point
y - the y coordinate of the point

getBoundingBox

public Rectangle getBoundingBox()
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 pont is inside this polygon.
It is based on code by Hanpeter van Vliet (hvvliet@inter.nl.net).
Parameters:
x - the xcoordinate of the point to be tested
y - the y coordinate of the point to be tested
Returns:
true if the point is inside this polygon; false otherwise.

Packages  This Package  Prev  Next  Index
Java API Document (HTML generated by dkramer on April 22, 1996)
Copyright © 1996 Sun Microsystems, Inc. All rights reserved
Please send any comments or corrections to doug.kramer@sun.com