public class GGRectangle
extends java.lang.Object
(ulx, uly) (urx, ury)
vertex[0] vertex[1]
o--------------------->o ==========>> direction ---------->x
^ edges[0] | |
| | |
| e e | |
| d d | v
| g g | y
| e e | height
| s s |
| [3} [1] |
| |
| edges[2] v
o<---------------------o
vertex[3] width vertex[2]
(llx, lly) (lrx, lry)
The direction of the rectangle is defined as the angle (0..2*pi) of the
vector direction of edges[0] clockwise with reference to the x-coordinate direction.
When defining the rectangle instance by the 4 vertexes, it is assumed that the shape is
a rectangle.Constructor and Description |
---|
GGRectangle(double x0,
double y0,
double x1,
double y1,
double x2,
double y2,
double x3,
double y3)
Creates a new GGRectangle from given 8 x-y-coordinates.
|
GGRectangle(GGRectangle rect)
Creates a new GGRectangle from given GGRectangle.
|
GGRectangle(GGVector[] vertexes)
Creates a new GGRectangle from given vertexes.
|
GGRectangle(GGVector center,
double direction,
double width,
double height)
Creates a new GGRectangle from given center, direction, width and height.
|
GGRectangle(java.awt.geom.Point2D.Double pt0,
java.awt.geom.Point2D.Double pt1,
java.awt.geom.Point2D.Double pt2,
java.awt.geom.Point2D.Double pt3)
Creates a new GGRectangle from given 4 vertex points.
|
GGRectangle(java.awt.Rectangle rect)
Creates a new GGRectangle from given java.awt.Rectangle.
|
Modifier and Type | Method and Description |
---|---|
GGRectangle |
clone()
Returns a new rectangle with same vertices and egdes as the original.
|
GGVector |
getCenter()
Returns a vector that points to the center of the rectangle.
|
double |
getCircumradius()
Returns the circumradius of the rectangle.
|
double |
getDirection()
Direction of edges[0], zero to west, clockwise 0..2*pi
|
GGVector[] |
getEdges()
Returns a GGVector array with 4 GGVectors whoses values are copies of
the original edges.
|
double |
getHeight()
Returns the height of the rectangle.
|
GGVector[] |
getVertexes()
Returns a GGVector array with 4 GGVectors whoses values are copies of
the original vertexes.
|
double |
getWidth()
Returns the width of the rectangle.
|
boolean |
isEqual(GGRectangle rect)
Returns true, if the current rectangle is identical to the given rectangle.
|
boolean |
isIntersecting(GGCircle circle)
Returns true if the current rectangle intersects with the given circle.
|
boolean |
isIntersecting(GGLine line)
Returns true if the current rectangle intersects with the given line segment.
|
boolean |
isIntersecting(GGRectangle rect)
Returns true if the current rectangle intersects with the given rectangle.
|
boolean |
isIntersecting(GGVector vector,
boolean isRotatable)
Returns true if the given points is part of the rectangle area.
|
void |
rotate(double angle)
Rotates with rotation center at (0, 0).
|
void |
rotate(GGVector rotationCenter,
double angle)
Rotates with given rotation center.
|
java.lang.String |
toString()
Returns a string that enumerates vertexes, edges, center, width, height and direction.
|
void |
translate(GGVector v)
Translates by the given vector.
|
public GGRectangle(GGRectangle rect)
rect
- the rectangle from where the values of vertexes and edges are copiedpublic GGRectangle(GGVector[] vertexes)
vertexes
- the 4 vertexes from where the values of new vertexes are copiedpublic GGRectangle(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3)
x0
- coordinate of lower left x (llx)y0
- coordinate of lower left y (lly)x1
- coordinate of lower right x (lrx)y1
- coordinate of lower right y (lry)x2
- coordinate of upper right x (urx)y2
- coordinate of upper right y (ury)x3
- coordinate of upper left x (ulx)y3
- coordinate of upper left y (uly)public GGRectangle(java.awt.geom.Point2D.Double pt0, java.awt.geom.Point2D.Double pt1, java.awt.geom.Point2D.Double pt2, java.awt.geom.Point2D.Double pt3)
pt0
- coordinates of lower left vertexpt1
- coordinates of lower right vertexpt2
- coordinates of upper right vertexpt3
- coordinates of upper right vertexpublic GGRectangle(GGVector center, double direction, double width, double height)
center
- vector to the center of the rectangledirection
- direction of edges[0] (in arc, 0..2*pi, positive clockwise)width
- the length of edges[0] and edges[2]height
- the length of edges[1] and edges[3]public GGRectangle(java.awt.Rectangle rect)
rect
- the rectangle from where the values of vertexes are takenpublic void rotate(double angle)
angle
- public void rotate(GGVector rotationCenter, double angle)
rotationCenter
- the center of the rotationangle
- the angle (in radian, clockwise)public void translate(GGVector v)
v
- the translatin vectorpublic GGVector[] getVertexes()
public GGVector[] getEdges()
public GGVector getCenter()
public double getWidth()
public double getHeight()
public double getDirection()
public double getCircumradius()
public GGRectangle clone()
clone
in class java.lang.Object
public java.lang.String toString()
toString
in class java.lang.Object
public boolean isIntersecting(GGRectangle rect)
rect
- the rectangle to be checked for intersection with the current rectanglepublic boolean isIntersecting(GGLine line)
line
- the line segment to be checked for intersection with the current rectanglepublic boolean isIntersecting(GGCircle circle)
circle
- the circle to be checked for intersection with the current rectanglepublic boolean isIntersecting(GGVector vector, boolean isRotatable)
vector
- the vector to be checked for intersectionisRotatable
- if false, the axis-parallel rectangle is assumed; if true,
the rectangle may be rotatedpublic boolean isEqual(GGRectangle rect)
rect
- the rectangle to compare