com.partnersoft.geometry.xy
Class XyGrid

java.lang.Object
  extended by com.partnersoft.geometry.xy.XyGrid
All Implemented Interfaces:
Immutable
Direct Known Subclasses:
XyGridSystem

public class XyGrid
extends java.lang.Object
implements Immutable

A quantization grid or tiling in (x, y) space.

Applying a grid to a geometric space is just like drawing the space on graph paper. The grid is oriented with the cartesian axes such that lines are horizontal and vertical. It may be offset from the (0, 0) origin by its own originX and originY parameters.

A cell width and height is specified; this is the width and height of all cells in the grid. A given cell can be described as a rectangle with minimum and maximum x and y parameters; the cell is understood to contain all values from (minX, minY) inclusive to (maxX, maxY) exclusive. Cells have their own coordinates within the grid, with consists of the number of cells to the left or west and the number of cells beneath or to the south of the cell. This is represented by an XyGridCell object.

As an example, let's present an integer quantization grid with cell width and height of 1.0, and originX and originY of 0.0.

Consider the following four points: (0.5, 0.5), (1.0, 1.0), (3.2, 9.6), and (-8.0, 5.0).

Mathematically, to find the cell for a given coordinate, you subtract the origin, divide by the width or height, and take the integer portion of the result. The offset within the cell is then equal to the remainder times the width or height.

 double dividedX = (x - originX) / width;
 double dividedY = (y - originY) / height;
 int cellX = (int) Math.floor(dividedX);
 int cellY = (int) Math.floor(dividedY);
 double cellOffsetX = (dividedX - cellX) * width;
 double cellOffsetY = (dividedY - cellY) * height;
 

Copyright 2007 Partner Software, Inc.

Version:
$Id: XyGrid.java 2117 2009-09-23 13:56:35Z paul $
Author:
Paul Reavis

Constructor Summary
XyGrid(double cellSize)
          Creates a grid with origin (0, 0) and square cells with the given size.
XyGrid(double cellWidth, double cellHeight)
          Creates a grid with origin (0, 0) and cells with the given width and height.
XyGrid(double originX, double originY, double cellSize)
          Creates a grid with origin (originX, originY) and square cells with the given size.
XyGrid(double originX, double originY, double cellWidth, double cellHeight)
           
XyGrid(XyPoint origin, XySize cellSize)
           
XyGrid(XySize cellSize)
           
 
Method Summary
 XyGridCell cellContainingPoint(double x, double y)
           
 XyGridCell cellContainingPoint(XyPoint point)
           
 XySize getCellSize()
           
 XyPoint getOrigin()
           
 java.util.List<XyGridCell> listCellsIntersecting(XyBounds bounds)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XyGrid

public XyGrid(double cellSize)
Creates a grid with origin (0, 0) and square cells with the given size.


XyGrid

public XyGrid(double cellWidth,
              double cellHeight)
Creates a grid with origin (0, 0) and cells with the given width and height.


XyGrid

public XyGrid(double originX,
              double originY,
              double cellSize)
Creates a grid with origin (originX, originY) and square cells with the given size.

Parameters:
originX - origin of grid (x)
originY - origin of grid (y)
cellSize - width and height of cells

XyGrid

public XyGrid(double originX,
              double originY,
              double cellWidth,
              double cellHeight)

XyGrid

public XyGrid(XySize cellSize)

XyGrid

public XyGrid(XyPoint origin,
              XySize cellSize)
Method Detail

cellContainingPoint

public XyGridCell cellContainingPoint(XyPoint point)

cellContainingPoint

public XyGridCell cellContainingPoint(double x,
                                      double y)

listCellsIntersecting

public java.util.List<XyGridCell> listCellsIntersecting(XyBounds bounds)

getOrigin

public XyPoint getOrigin()

getCellSize

public XySize getCellSize()