public class Geom
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
static int |
OUT_BOTTOM
The bitmask that indicates that a point lies below the rectangle.
|
static int |
OUT_LEFT
The bitmask that indicates that a point lies to the left of the rectangle.
|
static int |
OUT_RIGHT
The bitmask that indicates that a point lies to the right of the rectangle.
|
static int |
OUT_TOP
The bitmask that indicates that a point lies above the rectangle.
|
Modifier and Type | Method and Description |
---|---|
static double |
angle(double x1,
double y1,
double x2,
double y2)
Gets the angle of the specified line.
|
static java.awt.geom.Point2D.Double |
angleToPoint(java.awt.geom.Rectangle2D.Double r,
double angle)
Gets the point on a rectangle that corresponds to the given angle.
|
static java.awt.Point |
angleToPoint(java.awt.Rectangle r,
double angle)
Gets the point on a rectangle that corresponds to the given angle.
|
static java.awt.geom.Point2D.Double |
cap(java.awt.geom.Point2D.Double p1,
java.awt.geom.Point2D.Double p2,
double radius)
Caps the line defined by p1 and p2 by the number of units
specified by radius.
|
static java.awt.Point |
center(java.awt.Rectangle r) |
static java.awt.geom.Point2D.Double |
center(java.awt.geom.Rectangle2D.Double r) |
static java.awt.geom.Point2D.Double |
chop(java.awt.Shape shape,
java.awt.geom.Point2D.Double p)
Returns a point on the edge of the shape which crosses the line
from the center of the shape to the specified point.
|
static boolean |
contains(java.awt.geom.Rectangle2D.Double r1,
java.awt.geom.Rectangle2D.Double r2)
Returns true, if rectangle 1 contains rectangle 2.
|
static boolean |
contains(java.awt.geom.Rectangle2D r1,
java.awt.geom.Rectangle2D r2)
Returns true, if rectangle 1 contains rectangle 2.
|
static int |
direction(double x1,
double y1,
double x2,
double y2)
Returns the direction OUT_TOP, OUT_BOTTOM, OUT_LEFT, OUT_RIGHT from
one point to another one.
|
static int |
direction(int x1,
int y1,
int x2,
int y2)
Returns the direction OUT_TOP, OUT_BOTTOM, OUT_LEFT, OUT_RIGHT from
one point to another one.
|
static double |
distanceFromLine(int xa,
int ya,
int xb,
int yb,
int xc,
int yc)
compute distance of point from line segment, or
Double.MAX_VALUE if perpendicular projection is outside segment; or
If pts on line are same, return distance from point
|
static java.awt.Point |
east(java.awt.Rectangle r) |
static java.awt.geom.Point2D.Double |
east(java.awt.geom.Rectangle2D.Double r) |
static void |
grow(java.awt.geom.Rectangle2D.Double r,
double h,
double v)
Resizes the
Rectangle2D.Double both horizontally and vertically. |
static java.awt.geom.Point2D.Double |
intersect(double xa,
double ya,
double xb,
double yb,
double xc,
double yc,
double xd,
double yd)
Standard line intersection algorithm
Return the point of intersection if it exists, else null
|
static java.awt.geom.Point2D.Double |
intersect(double xa,
double ya,
double xb,
double yb,
double xc,
double yc,
double xd,
double yd,
double limit) |
static java.awt.Point |
intersect(int xa,
int ya,
int xb,
int yb,
int xc,
int yc,
int xd,
int yd)
Standard line intersection algorithm
Return the point of intersection if it exists, else null.
|
static double |
length(double x1,
double y1,
double x2,
double y2)
Gets the distance between to points
|
static long |
length(int x1,
int y1,
int x2,
int y2)
Gets the distance between to points
|
static double |
length(java.awt.geom.Point2D.Double p1,
java.awt.geom.Point2D.Double p2)
Gets the distance between to points
|
static double |
length2(double x1,
double y1,
double x2,
double y2)
Gets the square distance between two points.
|
static long |
length2(int x1,
int y1,
int x2,
int y2)
Gets the square distance between two points.
|
static boolean |
lineContainsPoint(double x1,
double y1,
double x2,
double y2,
double px,
double py,
double tolerance)
Tests if a point is on a line.
|
static boolean |
lineContainsPoint(int x1,
int y1,
int x2,
int y2,
int px,
int py)
Tests if a point is on a line.
|
static boolean |
lineContainsPoint(int x1,
int y1,
int x2,
int y2,
int px,
int py,
double tolerance)
Tests if a point is on a line.
|
static java.awt.Point |
north(java.awt.Rectangle r) |
static java.awt.geom.Point2D.Double |
north(java.awt.geom.Rectangle2D.Double r) |
static int |
outcode(java.awt.geom.Rectangle2D.Double r1,
java.awt.geom.Rectangle2D.Double r2)
This method computes a binary OR of the appropriate mask values
indicating, for each side of Rectangle r1, whether or not the
Rectangle r2 is on the same side of the edge as the rest
of this Rectangle.
|
static int |
outcode(java.awt.Rectangle r1,
java.awt.Rectangle r2)
This method computes a binary OR of the appropriate mask values
indicating, for each side of Rectangle r1, whether or not the
Rectangle r2 is on the same side of the edge as the rest
of this Rectangle.
|
static java.awt.geom.Point2D.Double |
ovalAngleToPoint(java.awt.geom.Rectangle2D.Double r,
double angle)
Gets the point on an oval that corresponds to the given angle.
|
static java.awt.Point |
ovalAngleToPoint(java.awt.Rectangle r,
double angle)
Gets the point on an oval that corresponds to the given angle.
|
static double |
pointToAngle(java.awt.geom.Rectangle2D.Double r,
java.awt.geom.Point2D.Double p)
Gets the angle of a point relative to a rectangle.
|
static double |
pointToAngle(java.awt.Rectangle r,
java.awt.Point p)
Gets the angle of a point relative to a rectangle.
|
static java.awt.Point |
polarToPoint(double angle,
double fx,
double fy)
Converts a polar to a point
|
static java.awt.geom.Point2D.Double |
polarToPoint2D(double angle,
double fx,
double fy)
Converts a polar to a point
|
static double |
range(double min,
double max,
double value)
Constains a value to the given range.
|
static int |
range(int min,
int max,
int value)
Constains a value to the given range.
|
static java.awt.Point |
south(java.awt.Rectangle r) |
static java.awt.geom.Point2D.Double |
south(java.awt.geom.Rectangle2D.Double r) |
static java.awt.Point |
west(java.awt.Rectangle r) |
static java.awt.geom.Point2D.Double |
west(java.awt.geom.Rectangle2D.Double r) |
public static final int OUT_TOP
public static final int OUT_BOTTOM
public static final int OUT_LEFT
public static final int OUT_RIGHT
public static boolean lineContainsPoint(int x1, int y1, int x2, int y2, int px, int py)
public static boolean lineContainsPoint(int x1, int y1, int x2, int y2, int px, int py, double tolerance)
changed Werner Randelshofer 2003-11-26
public static boolean lineContainsPoint(double x1, double y1, double x2, double y2, double px, double py, double tolerance)
changed Werner Randelshofer 2003-11-26
public static int direction(int x1, int y1, int x2, int y2)
public static int direction(double x1, double y1, double x2, double y2)
public static int outcode(java.awt.Rectangle r1, java.awt.Rectangle r2)
public static int outcode(java.awt.geom.Rectangle2D.Double r1, java.awt.geom.Rectangle2D.Double r2)
public static java.awt.Point south(java.awt.Rectangle r)
public static java.awt.geom.Point2D.Double south(java.awt.geom.Rectangle2D.Double r)
public static java.awt.Point center(java.awt.Rectangle r)
public static java.awt.geom.Point2D.Double center(java.awt.geom.Rectangle2D.Double r)
public static java.awt.geom.Point2D.Double chop(java.awt.Shape shape, java.awt.geom.Point2D.Double p)
public static java.awt.Point west(java.awt.Rectangle r)
public static java.awt.geom.Point2D.Double west(java.awt.geom.Rectangle2D.Double r)
public static java.awt.Point east(java.awt.Rectangle r)
public static java.awt.geom.Point2D.Double east(java.awt.geom.Rectangle2D.Double r)
public static java.awt.Point north(java.awt.Rectangle r)
public static java.awt.geom.Point2D.Double north(java.awt.geom.Rectangle2D.Double r)
public static int range(int min, int max, int value)
public static double range(double min, double max, double value)
public static long length2(int x1, int y1, int x2, int y2)
public static long length(int x1, int y1, int x2, int y2)
public static double length2(double x1, double y1, double x2, double y2)
public static double length(double x1, double y1, double x2, double y2)
public static double length(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2)
public static java.awt.geom.Point2D.Double cap(java.awt.geom.Point2D.Double p1, java.awt.geom.Point2D.Double p2, double radius)
public static double pointToAngle(java.awt.Rectangle r, java.awt.Point p)
public static double pointToAngle(java.awt.geom.Rectangle2D.Double r, java.awt.geom.Point2D.Double p)
public static double angle(double x1, double y1, double x2, double y2)
public static java.awt.Point angleToPoint(java.awt.Rectangle r, double angle)
public static java.awt.geom.Point2D.Double angleToPoint(java.awt.geom.Rectangle2D.Double r, double angle)
public static java.awt.Point polarToPoint(double angle, double fx, double fy)
public static java.awt.geom.Point2D.Double polarToPoint2D(double angle, double fx, double fy)
public static java.awt.Point ovalAngleToPoint(java.awt.Rectangle r, double angle)
public static java.awt.geom.Point2D.Double ovalAngleToPoint(java.awt.geom.Rectangle2D.Double r, double angle)
public static java.awt.Point intersect(int xa, int ya, int xb, int yb, int xc, int yc, int xd, int yd)
public static java.awt.geom.Point2D.Double intersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd)
public static java.awt.geom.Point2D.Double intersect(double xa, double ya, double xb, double yb, double xc, double yc, double xd, double yd, double limit)
public static double distanceFromLine(int xa, int ya, int xb, int yb, int xc, int yc)
public static void grow(java.awt.geom.Rectangle2D.Double r, double h, double v)
Rectangle2D.Double
both horizontally and vertically.
This method modifies the Rectangle2D.Double
so that it is
h
units larger on both the left and right side,
and v
units larger at both the top and bottom.
The new Rectangle2D.Double
has (x - h
,
y - v
) as its top-left corner, a
width of
width
+
2h
,
and a height of
height
+
2v
.
If negative values are supplied for h
and
v
, the size of the Rectangle2D.Double
decreases accordingly.
The grow
method does not check whether the resulting
values of width
and height
are
non-negative.
h
- the horizontal expansionv
- the vertical expansionpublic static boolean contains(java.awt.geom.Rectangle2D.Double r1, java.awt.geom.Rectangle2D.Double r2)
This method is similar to Rectangle2D.contains, but also returns true, when rectangle1 contains rectangle2 and either or both of them are empty.
r1
- Rectangle 1.r2
- Rectangle 2.public static boolean contains(java.awt.geom.Rectangle2D r1, java.awt.geom.Rectangle2D r2)
This method is similar to Rectangle2D.contains, but also returns true, when rectangle1 contains rectangle2 and either or both of them are empty.
r1
- Rectangle 1.r2
- Rectangle 2.