Package java.awt |
![]() Previous |
![]() Java API |
![]() Index |
![]() Next |
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
public int npointsThe total number of points.
public int xpoints[]The array of x coordinates.
public int ypoints[]The array of y coordinates.
public Polygon()Creates an empty polygon.
public Polygon(int xpoints[], int ypoints[], int npoints)Constructs and initializes a polygon from the specified parameters.
Parameter Description xpoints an array of x coordinates ypoints an array of y coordinates npoints the total number of points in the polygon
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.
Parameter Description x the x coordinate of the point y the y coordinate of the point
public Rectangle getBoundingBox()Return Value:
Returns the smallest rectangle than contains this polygon
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.
Parameter Description x the xcoordinate of the point to be tested y the y coordinate of the point to be tested