|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||
java.lang.Object | +--Lattice2D
Class to assist in the display of a 2D lattice.
| Inner Class Summary | |
static interface |
Lattice2D.Basis
Class representing a basis. |
class |
Lattice2D.CircularBasis
An implementation of Basis which displays as a circle. |
class |
Lattice2D.PolygonBasis
Polygon-based implementation of a basis |
| Field Summary | |
protected Lattice2D.Basis |
basis
The selected basis |
protected java.awt.Color |
basisCol
The colour to use when drawing the bases |
protected int |
basisSize
Constant scaling factor for the size of the bases. |
static int |
MARK_RADIUS
Size of the draggable blobs on the ends of the vectors |
static double |
THRESHOLD
Square of the radius of the circle of points around the end of a vector such that a click within that circle is considered close enough to be interpreted as a click on said vector. |
protected java.awt.Color[] |
vectorCols
A two-element array containing colours (that's right, with a 'u') for the vectors |
Vector2D[] |
vectors
A two-element array containing the lattice vectors |
protected double |
xscl
The ratio between x coordinates in the model and those in screen space. |
protected double |
yscl
The ratio between x coordinates in the model and those in screen space. |
| Constructor Summary | |
Lattice2D()
Creates a new lattice with orthogonal lattice vectors. |
|
Lattice2D(double x1,
double y1,
double x2,
double y2)
Creates a new lattice |
|
Lattice2D(Vector2D[] vectors)
Creates a new lattice |
|
Lattice2D(Vector2D v1,
Vector2D v2)
Creates a new lattice |
|
| Method Summary | |
Vector2D |
chooseVector(int x,
int y,
int w,
int h)
Returns the vector that is closest (of the two lattice vectors) to the specified screen coordinates. |
protected double |
distanceFrom(Vector2D point,
int vector)
Returns the distance between the specifed point and one of the two lattice vectors. |
Vector2D |
fromScreen(int x,
int y,
int w,
int h)
Converts a pair of coordinates from screen space to a lattice space vector. |
double |
fromScreenX(int x,
int w)
Converts an x coordinate from screen space to lattice space |
double |
fromScreenY(int y,
int h)
Converts a y coordinate from screen space to lattice space |
void |
paint(java.awt.Graphics g,
int w,
int h)
Displays this lattice, inlcuding the two vectors. |
protected void |
paintLattice(java.awt.Graphics g,
int w,
int h)
Paints just the lattice (without the vectors). |
protected void |
paintVector(java.awt.Graphics g,
int w,
int h,
int vector)
Paints a vector. |
void |
setBasis(Lattice2D.Basis b)
Sets the selected basis |
int |
toScreenX(double x,
int w)
Converts an x coordinate from lattice space to screen space |
int |
toScreenY(double y,
int h)
Converts a y coordinate from lattice space to screen space |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
protected Lattice2D.Basis basis
protected java.awt.Color[] vectorCols
protected java.awt.Color basisCol
protected double xscl
protected double yscl
public Vector2D[] vectors
protected int basisSize
public static final int MARK_RADIUS
public static final double THRESHOLD
| Constructor Detail |
public Lattice2D(Vector2D[] vectors)
vectors - A two-element array containing the lattice vectors
public Lattice2D(Vector2D v1,
Vector2D v2)
v1 - The first lattice vectorv2 - The second lattice vector
public Lattice2D(double x1,
double y1,
double x2,
double y2)
x1 - The x component of the first lattice vectory1 - The y component of the first lattice vectorx2 - The x component of the second lattice vectory2 - The y component of the second lattice vectorpublic Lattice2D()
| Method Detail |
public int toScreenX(double x,
int w)
x - The lattice coordinatew - The width of the display
public int toScreenY(double y,
int h)
y - The lattice coordinateh - The height of the display
public double fromScreenX(int x,
int w)
x - The screen coordinatew - The width of the display
public double fromScreenY(int y,
int h)
y - The screen coordinateh - The height of the display
public Vector2D fromScreen(int x,
int y,
int w,
int h)
x - The screen x coordinatey - The screen y coordinatew - The width of the displayh - The height of the display
public void paint(java.awt.Graphics g,
int w,
int h)
g - The Graphics surface on which to paintw - The width (in pixels) of the area on which to painth - The height (in pixels) of the area on which to paint
protected void paintVector(java.awt.Graphics g,
int w,
int h,
int vector)
g - The Graphics surface on which to paintw - The width (in pixels) of the area on which to painth - The height (in pixels) of the area on which to paintvector - The vector to paint
public Vector2D chooseVector(int x,
int y,
int w,
int h)
x - The screen x coordinatey - The screen y coordinatew - The width of the displayh - The height of the display
protected double distanceFrom(Vector2D point,
int vector)
point - The pointvector - The index (0 or 1) of a lattice vector
protected void paintLattice(java.awt.Graphics g,
int w,
int h)
The basic algorithm is to display a "grid" of bases, each at a position av1 + bv2, where a, b are integers in the interval [-30,30].
However, with near-dependent lattice vectors, this is often insufficient; a large number of bases will fall outside the view area, and the view area will not be entirely filled.
The solution is to make use of the fact that u, v describe the same vector space as u, v - nu, where n is any integer. The two lattice vectors will be transformed in this way, subtracting the smaller from the larger, until the modulae are minimised, at which point the vectors will be the closest-to-orthogonal vectors which still describe the same vector space.
g - The Graphics surface on which to paintw - The width (in pixels) of the area on which to painth - The height (in pixels) of the area on which to paintpublic void setBasis(Lattice2D.Basis b)
|
||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||